Skip to content

Commit

Permalink
Remove deprecated Playwright keywords (#3503)
Browse files Browse the repository at this point in the history
We missed a major release of `robotframework-browser` ([v15]), which
removed the deprecated `execute_javascript` keyword. This resulted in
test failures that we initially believed were timeout related because
the `AttributeError` was being cought by the bare `except` and re-raised
with an misleading error message.

This commit resolves the falures by:

1. Switching to the `evaluate_javascript` keyword
2. Raising the timeout exception using the `raise ... from exc`

[v15]: https://github.com/MarketSquare/robotframework-browser/releases/tag/v15.0.0
  • Loading branch information
jstvz authored Jan 21, 2023
1 parent f0a9703 commit 2bb633a
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions cumulusci/robotframework/SalesforcePlaywright.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ def get_current_record_id(self):
This expects the url to contain an id that matches [a-zA-Z0-9]{15,18}
"""
OID_REGEX = r"^(%2F)?([a-zA-Z0-9]{15,18})$"
url = self.browser.execute_javascript("window.location.href")
url = self.browser.evaluate_javascript(None, "window.location.href")
for part in url.split("/"):
oid_match = re.match(OID_REGEX, part)
if oid_match is not None:
return oid_match.group(2)
raise AssertionError("Could not parse record id from url: {}".format(url))
return oid_match[2]
raise AssertionError(f"Could not parse record id from url: {url}")

def go_to_record_home(self, obj_id):
"""Navigates to the Home view of a Salesforce Object
Expand All @@ -45,7 +45,7 @@ def go_to_record_home(self, obj_id):
div can be found on the page.
"""
url = self.cumulusci.org.lightning_base_url
url = "{}/lightning/r/{}/view".format(url, obj_id)
url = f"{url}/lightning/r/{obj_id}/view"
self.browser.go_to(url)
self.wait_until_loading_is_complete("div.slds-page-header_record-home")

Expand Down Expand Up @@ -134,7 +134,8 @@ class 'slds-template__container', but a different locator can
else locator
)
self.browser.get_elements(locator)
self.browser.execute_javascript(function=WAIT_FOR_AURA_SCRIPT)

self.browser.evaluate_javascript(None, WAIT_FOR_AURA_SCRIPT)
# An old knowledge article recommends waiting a second. I don't
# like it, but it seems to help. We should do a wait instead,
# but I can't figure out what to wait on.
Expand Down Expand Up @@ -173,14 +174,14 @@ def wait_until_salesforce_is_ready(
# No errors? We're golden.
break

except Exception:
except Exception as exc:
# dang. Maybe we landed somewhere unexpected?
if self._check_for_classic():
continue

if time.time() - start_time > timeout_seconds:
self.browser.take_screenshot()
raise Exception("Timed out waiting for a lightning page")
raise Exception("Timed out waiting for a lightning page") from exc

# If at first you don't succeed, ...
self.browser.go_to(login_url)
Expand Down

0 comments on commit 2bb633a

Please sign in to comment.