From 2bb633a72034dcd5842446eb69b3ec25c265e15d Mon Sep 17 00:00:00 2001 From: James Estevez Date: Fri, 20 Jan 2023 16:46:51 -0800 Subject: [PATCH] Remove deprecated Playwright keywords (#3503) 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 --- cumulusci/robotframework/SalesforcePlaywright.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/cumulusci/robotframework/SalesforcePlaywright.py b/cumulusci/robotframework/SalesforcePlaywright.py index 5232111587..9eba2edf11 100644 --- a/cumulusci/robotframework/SalesforcePlaywright.py +++ b/cumulusci/robotframework/SalesforcePlaywright.py @@ -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 @@ -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") @@ -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. @@ -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)