mirror of
https://github.com/User0332/rewards-farmer.git
synced 2026-09-16 01:31:36 +00:00
cover the rewards urls the daily set actually uses
Matching on bing.com/search alone was too narrow. Turn referrals into rewards is a real daily set activity that awards points and it points at a rewards url, so the filter skipped it and the run came up short without saying why. Three shapes now count, bing.com/search, bing.com/rewards and rewards.bing.com. The bing app promo from #45 sits on bingapp.microsoft.com and stays out of all three, which is what keeps that fix intact. Five tests, one per shape plus a mixed panel.
This commit is contained in:
@@ -182,21 +182,39 @@ class ElementSelectionUtils:
|
|||||||
Handing one of those back gets it clicked, which navigates away from
|
Handing one of those back gets it clicked, which navigates away from
|
||||||
rewards.bing.com, and every element captured beforehand then goes stale.
|
rewards.bing.com, and every element captured beforehand then goes stale.
|
||||||
|
|
||||||
Activities always point at a Bing search, so match on that rather than on
|
Matching on a Bing search alone was too narrow. "Turn referrals into
|
||||||
position. If nothing matches, return nothing: clicking a promo is worse
|
rewards" is a real daily set activity that awards points, and it points
|
||||||
than skipping the task, and the caller already reports the shortfall.
|
at a rewards URL rather than a search. Three shapes have been observed:
|
||||||
|
|
||||||
|
1. `bing.com/search?q=...`, the classic search activity,
|
||||||
|
2. `bing.com/rewards/...`, seen on daily sets alongside the searches,
|
||||||
|
3. `rewards.bing.com/...`, the same activity written against the
|
||||||
|
rewards host.
|
||||||
|
|
||||||
|
The Bing app promo behind #45 is on `bingapp.microsoft.com`, so it stays
|
||||||
|
out of all three, and so does anything else off those hosts. If nothing
|
||||||
|
matches, return nothing: clicking a promo is worse than skipping the
|
||||||
|
task, and the caller already reports the shortfall.
|
||||||
"""
|
"""
|
||||||
activities = []
|
activities = []
|
||||||
|
|
||||||
for link in self.get_sidebar_section().find_elements(By.TAG_NAME, "a"):
|
for link in self.get_sidebar_section().find_elements(By.TAG_NAME, "a"):
|
||||||
try:
|
try:
|
||||||
if "bing.com/search" in (link.get_dom_attribute("href") or ""):
|
if self._is_daily_set_activity(link.get_dom_attribute("href") or ""):
|
||||||
activities.append(link)
|
activities.append(link)
|
||||||
except StaleElementReferenceException:
|
except StaleElementReferenceException:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
return activities
|
return activities
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _is_daily_set_activity(href: str) -> bool:
|
||||||
|
"""Whether an href in the daily set panel is an activity rather than a promo."""
|
||||||
|
return any(
|
||||||
|
marker in href
|
||||||
|
for marker in ("bing.com/search", "bing.com/rewards", "rewards.bing.com/")
|
||||||
|
)
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
# explore on bing (absent in en-US, present in some other markets)
|
# explore on bing (absent in en-US, present in some other markets)
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
|
|||||||
@@ -190,5 +190,59 @@ class DailySetOpener(unittest.TestCase):
|
|||||||
selectors_for(driver).get_open_daily_set_button()
|
selectors_for(driver).get_open_daily_set_button()
|
||||||
|
|
||||||
|
|
||||||
|
class DailySetActivityUrls(unittest.TestCase):
|
||||||
|
"""Which hrefs in the panel count as activities and which are promos."""
|
||||||
|
|
||||||
|
def _links(self, *hrefs):
|
||||||
|
links = [FakeElement(text="activity", attributes={"href": h}) for h in hrefs]
|
||||||
|
panel = FakeElement(
|
||||||
|
attributes={"id": "react-aria-42"},
|
||||||
|
children={(By.TAG_NAME, "a"): links},
|
||||||
|
)
|
||||||
|
|
||||||
|
return FakeDriver(children={(By.TAG_NAME, "section"): [panel]})
|
||||||
|
|
||||||
|
def test_matches_a_plain_search_activity(self):
|
||||||
|
found = selectors_for(
|
||||||
|
self._links("https://www.bing.com/search?q=weather")
|
||||||
|
).get_daily_set_elements()
|
||||||
|
|
||||||
|
self.assertEqual(len(found), 1)
|
||||||
|
|
||||||
|
def test_matches_a_rewards_path_activity(self):
|
||||||
|
# "Turn referrals into rewards" awards points and is not a search.
|
||||||
|
found = selectors_for(
|
||||||
|
self._links("https://www.bing.com/rewards/panelflyout")
|
||||||
|
).get_daily_set_elements()
|
||||||
|
|
||||||
|
self.assertEqual(len(found), 1)
|
||||||
|
|
||||||
|
def test_matches_an_activity_on_the_rewards_host(self):
|
||||||
|
found = selectors_for(
|
||||||
|
self._links("https://rewards.bing.com/redeem/12345")
|
||||||
|
).get_daily_set_elements()
|
||||||
|
|
||||||
|
self.assertEqual(len(found), 1)
|
||||||
|
|
||||||
|
def test_skips_the_bing_app_promo(self):
|
||||||
|
# The link behind #45. Clicking it leaves the rewards host and every
|
||||||
|
# element captured beforehand goes stale.
|
||||||
|
found = selectors_for(
|
||||||
|
self._links("https://bingapp.microsoft.com/bing?adjust=14u4j3kz")
|
||||||
|
).get_daily_set_elements()
|
||||||
|
|
||||||
|
self.assertEqual(found, [])
|
||||||
|
|
||||||
|
def test_keeps_activities_and_drops_promos_from_the_same_panel(self):
|
||||||
|
found = selectors_for(self._links(
|
||||||
|
"https://bingapp.microsoft.com/bing?adjust=14u4j3kz",
|
||||||
|
"https://www.bing.com/search?q=news",
|
||||||
|
"https://www.bing.com/rewards/panelflyout",
|
||||||
|
"https://play.google.com/store/apps/details?id=com.microsoft.bing",
|
||||||
|
)).get_daily_set_elements()
|
||||||
|
|
||||||
|
self.assertEqual(len(found), 2)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
Reference in New Issue
Block a user