From d21ebe7d25ecec573382f660e6fd3ad96642c91d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rene=CC=81=20Rohner?= Date: Mon, 13 Jun 2022 20:07:40 +0200 Subject: [PATCH 1/2] improved StrictMode behavior of Evaluate JavaScript --- .../test/01_Browser_Management/timeout.robot | 12 +++---- atest/test/03_Waiting/wait_for_http.robot | 2 +- atest/test/05_JS_Tests/on_page_js.robot | 31 ++++++++++++++++++- node/playwright-wrapper/evaluation.ts | 2 +- 4 files changed, 37 insertions(+), 10 deletions(-) diff --git a/atest/test/01_Browser_Management/timeout.robot b/atest/test/01_Browser_Management/timeout.robot index 615885831..f8e93bcd1 100644 --- a/atest/test/01_Browser_Management/timeout.robot +++ b/atest/test/01_Browser_Management/timeout.robot @@ -5,16 +5,14 @@ Resource imports.resource Suite Setup New Browser Suite Teardown Close Browser -Force Tags timeout - +Force Tags timeout *** Variables *** ${err_goto} = page.goto: Timeout 1ms exceeded. -${err_click} = SEPARATOR= -... locator.click: Timeout 100ms exceeded. -... *Use "Set Browser Timeout" for increasing the timeout or double check${SPACE} -... your locator as the targeted element(s) couldn't be found. - +${err_click} = SEPARATOR= +... locator.click: Timeout 100ms exceeded. +... *Use "Set Browser Timeout" for increasing the timeout or double check${SPACE} +... your locator as the targeted element(s) couldn't be found. *** Test Cases *** Test GoTo With Short Default Timeout diff --git a/atest/test/03_Waiting/wait_for_http.robot b/atest/test/03_Waiting/wait_for_http.robot index 94be27927..2c9c8684b 100644 --- a/atest/test/03_Waiting/wait_for_http.robot +++ b/atest/test/03_Waiting/wait_for_http.robot @@ -100,7 +100,7 @@ Wait For Navigation Works With Wait_until END [Teardown] Set Browser Timeout ${old timeout} -Promise To Wait For Navigation With wait_until +Promise To Wait For Navigation With Wait_until ${old timeout} = Set Browser Timeout 4s Go To ${ROOT_URL}/redirector.html ${page_navigation} = Promise To Wait For Navigation url=${ROOT_URL}/posted.html wait_until=networkidle diff --git a/atest/test/05_JS_Tests/on_page_js.robot b/atest/test/05_JS_Tests/on_page_js.robot index 7b0a100b5..6fb9806a9 100644 --- a/atest/test/05_JS_Tests/on_page_js.robot +++ b/atest/test/05_JS_Tests/on_page_js.robot @@ -41,6 +41,35 @@ Evaluate Multiline JavaScript With Singel Element Length Should Be ${texts} 2 Should Be Equal ${texts}[-1] Hello World +Evaluate Multiline JavaScript With Strict Mode Disabled And All Elements + ${org} = Set Strict Mode False + ${length} = Evaluate JavaScript button + ... (elements) => { + ... return elements.length + ... } + ... all_elements=True + Should Be Equal ${length} ${11} + [Teardown] Set Strict Mode ${org} + +Evaluate Multiline JavaScript With Strict Mode Enabled And All Elements + ${org} = Set Strict Mode True + ${length} = Evaluate JavaScript button + ... (elements) => { + ... return elements.length + ... } + ... all_elements=True + Should Be Equal ${length} ${11} + [Teardown] Set Strict Mode ${org} + +Evaluate Multiline JavaScript With Strict Mode Disabled And Single Element + ${org} = Set Strict Mode False + ${text} = Evaluate JavaScript button + ... (e) => { + ... return e.innerText + ... } + Should Be Equal ${text} Visible + [Teardown] Set Strict Mode ${org} + Evaluate Multiline JavaScript Strict Mode Error Run Keyword And Expect Error ... *strict mode violation*input*resolved to 4 elements* @@ -110,7 +139,7 @@ Highlight Element On Page Highlight Elements .pure-button duration=1000ms Set Strict Mode True Get Element Count .robotframework-browser-highlight == 5 - Sleep 9000ms + Sleep 1500ms Get Element Count .robotframework-browser-highlight == 0 Highlight Element With Strict diff --git a/node/playwright-wrapper/evaluation.ts b/node/playwright-wrapper/evaluation.ts index 73097ffd7..397140e34 100644 --- a/node/playwright-wrapper/evaluation.ts +++ b/node/playwright-wrapper/evaluation.ts @@ -110,7 +110,7 @@ export async function evaluateJavascript( async function getJSResult() { if (selector !== '') { - const locator = await findLocator(state, selector, strictMode, undefined, true); + const locator = await findLocator(state, selector, strictMode, undefined, !allElements); if (allElements) { return await locator.evaluateAll(script, arg); } From c17612b806e01bec16cef8f3cb6d80a9e63aa081 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rene=CC=81=20Rohner?= Date: Mon, 13 Jun 2022 22:34:24 +0200 Subject: [PATCH 2/2] removed Presenter Mode from Get Element States to fix #2068 --- Browser/keywords/getters.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Browser/keywords/getters.py b/Browser/keywords/getters.py index cfc9c30c3..1fcc89b92 100644 --- a/Browser/keywords/getters.py +++ b/Browser/keywords/getters.py @@ -1374,7 +1374,6 @@ def convert_str(f): return f.name if isinstance(f, ElementState) else f assertion_expected_str = [convert_str(flag) for flag in assertion_expected] - self.presenter_mode(selector, self.strict_mode) with self.playwright.grpc_channel() as stub: response = stub.GetElementStates( Request.ElementSelector(selector=selector, strict=self.strict_mode)