From 548cd83327ce13d7aba0ef80a19e05af4b4a9da2 Mon Sep 17 00:00:00 2001 From: Aditya Samantaray Date: Tue, 26 Apr 2022 15:34:31 +0530 Subject: [PATCH 1/4] chore: moved playwright-dotnet to playwright-csharp folder --- .../PlaywrightDotnetTests.csproj | 0 {playwright-dotnet => playwright-csharp}/PlaywrightIPhoneTest.cs | 0 {playwright-dotnet => playwright-csharp}/PlaywrightLocalTest.cs | 0 .../PlaywrightParallelTest.cs | 0 {playwright-dotnet => playwright-csharp}/PlaywrightPixelTest.cs | 0 .../PlaywrightSessionDetailsTest.cs | 0 {playwright-dotnet => playwright-csharp}/PlaywrightTest.cs | 0 {playwright-dotnet => playwright-csharp}/Program.cs | 0 {playwright-dotnet => playwright-csharp}/README.md | 0 9 files changed, 0 insertions(+), 0 deletions(-) rename {playwright-dotnet => playwright-csharp}/PlaywrightDotnetTests.csproj (100%) rename {playwright-dotnet => playwright-csharp}/PlaywrightIPhoneTest.cs (100%) rename {playwright-dotnet => playwright-csharp}/PlaywrightLocalTest.cs (100%) rename {playwright-dotnet => playwright-csharp}/PlaywrightParallelTest.cs (100%) rename {playwright-dotnet => playwright-csharp}/PlaywrightPixelTest.cs (100%) rename {playwright-dotnet => playwright-csharp}/PlaywrightSessionDetailsTest.cs (100%) rename {playwright-dotnet => playwright-csharp}/PlaywrightTest.cs (100%) rename {playwright-dotnet => playwright-csharp}/Program.cs (100%) rename {playwright-dotnet => playwright-csharp}/README.md (100%) diff --git a/playwright-dotnet/PlaywrightDotnetTests.csproj b/playwright-csharp/PlaywrightDotnetTests.csproj similarity index 100% rename from playwright-dotnet/PlaywrightDotnetTests.csproj rename to playwright-csharp/PlaywrightDotnetTests.csproj diff --git a/playwright-dotnet/PlaywrightIPhoneTest.cs b/playwright-csharp/PlaywrightIPhoneTest.cs similarity index 100% rename from playwright-dotnet/PlaywrightIPhoneTest.cs rename to playwright-csharp/PlaywrightIPhoneTest.cs diff --git a/playwright-dotnet/PlaywrightLocalTest.cs b/playwright-csharp/PlaywrightLocalTest.cs similarity index 100% rename from playwright-dotnet/PlaywrightLocalTest.cs rename to playwright-csharp/PlaywrightLocalTest.cs diff --git a/playwright-dotnet/PlaywrightParallelTest.cs b/playwright-csharp/PlaywrightParallelTest.cs similarity index 100% rename from playwright-dotnet/PlaywrightParallelTest.cs rename to playwright-csharp/PlaywrightParallelTest.cs diff --git a/playwright-dotnet/PlaywrightPixelTest.cs b/playwright-csharp/PlaywrightPixelTest.cs similarity index 100% rename from playwright-dotnet/PlaywrightPixelTest.cs rename to playwright-csharp/PlaywrightPixelTest.cs diff --git a/playwright-dotnet/PlaywrightSessionDetailsTest.cs b/playwright-csharp/PlaywrightSessionDetailsTest.cs similarity index 100% rename from playwright-dotnet/PlaywrightSessionDetailsTest.cs rename to playwright-csharp/PlaywrightSessionDetailsTest.cs diff --git a/playwright-dotnet/PlaywrightTest.cs b/playwright-csharp/PlaywrightTest.cs similarity index 100% rename from playwright-dotnet/PlaywrightTest.cs rename to playwright-csharp/PlaywrightTest.cs diff --git a/playwright-dotnet/Program.cs b/playwright-csharp/Program.cs similarity index 100% rename from playwright-dotnet/Program.cs rename to playwright-csharp/Program.cs diff --git a/playwright-dotnet/README.md b/playwright-csharp/README.md similarity index 100% rename from playwright-dotnet/README.md rename to playwright-csharp/README.md From 875672e15fc3d3f0afd081f0f87fcd66645a9830 Mon Sep 17 00:00:00 2001 From: Aditya Samantaray Date: Tue, 26 Apr 2022 15:40:34 +0530 Subject: [PATCH 2/4] chore: update readme for playwright-csharp --- playwright-csharp/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/playwright-csharp/README.md b/playwright-csharp/README.md index d3afc0e..d63f4d1 100644 --- a/playwright-csharp/README.md +++ b/playwright-csharp/README.md @@ -6,7 +6,7 @@ ## Setup -* Clone the repo and run `cd Playwright-dotnet` +* Clone the repo and run `cd playwright-csharp` * Run `dotnet build` ## Running your tests From f76f107325e17be67523fa135ac1f63cffe028f7 Mon Sep 17 00:00:00 2001 From: Aditya Samantaray Date: Wed, 27 Apr 2022 14:48:39 +0530 Subject: [PATCH 3/4] fix: browserstack local scripts for python and java --- .../com/browserstack/PlaywrightLocalTest.java | 8 +--- .../PlaywrightLocalUsingBindingsTest.java | 22 ++++----- playwright-python/local-playwright-test.py | 9 ++-- .../local-using-bindings-playwright-test.py | 46 +++++++++---------- 4 files changed, 36 insertions(+), 49 deletions(-) diff --git a/playwright-java/src/test/java/com/browserstack/PlaywrightLocalTest.java b/playwright-java/src/test/java/com/browserstack/PlaywrightLocalTest.java index 1ed944d..22ff3eb 100644 --- a/playwright-java/src/test/java/com/browserstack/PlaywrightLocalTest.java +++ b/playwright-java/src/test/java/com/browserstack/PlaywrightLocalTest.java @@ -24,14 +24,10 @@ public static void main(String[] args) { Browser browser = chromium.connect(ws_endpoint); Page page = browser.newPage(); try { - page.navigate("https://www.google.co.in/"); - Locator locator = page.locator("[aria-label='Search']"); - locator.click(); - page.fill("[aria-label='Search']", "BrowserStack"); - page.locator("[aria-label='Google Search'] >> nth=0").click(); + page.navigate("http://localhost:45454"); String title = page.title(); - if (title.equals("BrowserStack - Google Search")) { + if (title.equals("BrowserStack Local")) { // following line of code is responsible for marking the status of the test on BrowserStack as 'passed'. You can use this code in your after hook after each test markTestStatus("passed", "Title matched", page); } else { diff --git a/playwright-java/src/test/java/com/browserstack/PlaywrightLocalUsingBindingsTest.java b/playwright-java/src/test/java/com/browserstack/PlaywrightLocalUsingBindingsTest.java index 4b313fc..69b78f9 100644 --- a/playwright-java/src/test/java/com/browserstack/PlaywrightLocalUsingBindingsTest.java +++ b/playwright-java/src/test/java/com/browserstack/PlaywrightLocalUsingBindingsTest.java @@ -40,21 +40,15 @@ public static void main(String[] args) { Browser browser = chromium.connect(ws_endpoint); Page page = browser.newPage(); try { - page.navigate("https://www.google.co.in/"); - Locator locator = page.locator("[aria-label='Search']"); - locator.click(); - page.fill("[aria-label='Search']", "BrowserStack"); - page.locator("[aria-label='Google Search'] >> nth=0").click(); - String title = page.title(); - - if (title.equals("BrowserStack - Google Search")) { - // following line of code is responsible for marking the status of the test on BrowserStack as 'passed'. You can use this code in your after hook after each test - markTestStatus("passed", "Title matched", page); - } else { - markTestStatus("failed", "Title did not match", page); - } + page.navigate("http://localhost:45691"); + page.waitForFunction("document" + + ".querySelector(\"body\")" + + ".innerText" + + ".includes(\"This is an internal server for BrowserStack Local\")"); + + markTestStatus("passed", "Local is up and running", page); } catch (Exception err) { - markTestStatus("failed", err.getMessage(), page); + markTestStatus("failed", "BrowserStack Local binary is not running", page); } browser.close(); diff --git a/playwright-python/local-playwright-test.py b/playwright-python/local-playwright-test.py index 5f8c66f..4093148 100644 --- a/playwright-python/local-playwright-test.py +++ b/playwright-python/local-playwright-test.py @@ -15,7 +15,7 @@ 'browserstack.accessKey': 'BROWSERSTACK_ACCESS_KEY' } -def run_local_session(): +def run_local_session(playwright): clientPlaywrightVersion = str(subprocess.getoutput('playwright --version')).strip().split(" ")[1] desired_cap['client.playwrightVersion'] = clientPlaywrightVersion @@ -23,13 +23,10 @@ def run_local_session(): browser = playwright.chromium.connect(cdpUrl) page = browser.new_page() try: - page.goto("https://www.google.co.in/") - page.fill("[aria-label='Search']", 'Browserstack') - locator = page.locator("[aria-label='Google Search'] >> nth=0") - locator.click() + page.goto("http://localhost:45454") title = page.title() - if title == "Browserstack - Google Search": + if title == "BrowserStack Local": # following line of code is responsible for marking the status of the test on BrowserStack as 'passed'. You can use this code in your after hook after each test mark_test_status("passed", "Title matched", page) else: diff --git a/playwright-python/local-using-bindings-playwright-test.py b/playwright-python/local-using-bindings-playwright-test.py index edb7119..522414c 100644 --- a/playwright-python/local-using-bindings-playwright-test.py +++ b/playwright-python/local-using-bindings-playwright-test.py @@ -27,33 +27,33 @@ def run_local_session(playwright): bs_local.start(**bs_local_args) # Check if BrowserStack local instance is running - print("BrowserStackLocal running: " + bs_local.isRunning()) + print("BrowserStackLocal running: " + str(bs_local.isRunning())) clientPlaywrightVersion = str(subprocess.getoutput('playwright --version')).strip().split(" ")[1] desired_cap['client.playwrightVersion'] = clientPlaywrightVersion - - cdpUrl = 'wss://cdp.browserstack.com/playwright?caps=' + urllib.parse.quote(json.dumps(desired_cap)) - browser = playwright.chromium.connect(cdpUrl) - page = browser.new_page() + try: - page.goto("https://www.google.co.in/") - page.fill("[aria-label='Search']", 'Browserstack') - locator = page.locator("[aria-label='Google Search'] >> nth=0") - locator.click() - title = page.title() - - if title == "Browserstack - Google Search": - # following line of code is responsible for marking the status of the test on BrowserStack as 'passed'. You can use this code in your after hook after each test - mark_test_status("passed", "Title matched", page) - else: - mark_test_status("failed", "Title did not match", page) - except Exception as err: - mark_test_status("failed", str(err), page) - - browser.close() - - # Stop the Local instance - bs_local.stop() + cdpUrl = 'wss://cdp.browserstack.com/playwright?caps=' + urllib.parse.quote(json.dumps(desired_cap)) + browser = playwright.chromium.connect(cdpUrl) + page = browser.new_page() + try: + page.goto("http://localhost:45691") + page.main_frame.wait_for_function(""" + document + .querySelector("body") + .innerText + .includes("This is an internal server for BrowserStack Local") + """) + mark_test_status("passed", "Local is up and running", page) + except Exception: + mark_test_status("failed", "BrowserStack Local binary is not running", page) + browser.close() + except Exception as ex: + print("Exception while creating page context: ", str(ex)) + finally: + # Stop the Local instance + bs_local.stop() + print("BrowserStackLocal stopped") def mark_test_status(status, reason, page): page.evaluate("_ => {}", "browserstack_executor: {\"action\": \"setSessionStatus\", \"arguments\": {\"status\":\""+ status + "\", \"reason\": \"" + reason + "\"}}"); From 6f7bc40d2b2afc3596e80debda63b272945e6188 Mon Sep 17 00:00:00 2001 From: Aditya Samantaray Date: Wed, 27 Apr 2022 14:52:34 +0530 Subject: [PATCH 4/4] chore: add comments for python java local scripts --- .../java/com/browserstack/PlaywrightLocalUsingBindingsTest.java | 1 + playwright-python/local-using-bindings-playwright-test.py | 1 + 2 files changed, 2 insertions(+) diff --git a/playwright-java/src/test/java/com/browserstack/PlaywrightLocalUsingBindingsTest.java b/playwright-java/src/test/java/com/browserstack/PlaywrightLocalUsingBindingsTest.java index 69b78f9..be90dbe 100644 --- a/playwright-java/src/test/java/com/browserstack/PlaywrightLocalUsingBindingsTest.java +++ b/playwright-java/src/test/java/com/browserstack/PlaywrightLocalUsingBindingsTest.java @@ -46,6 +46,7 @@ public static void main(String[] args) { ".innerText" + ".includes(\"This is an internal server for BrowserStack Local\")"); + // following line of code is responsible for marking the status of the test on BrowserStack as 'passed'. You can use this code in your after hook after each test markTestStatus("passed", "Local is up and running", page); } catch (Exception err) { markTestStatus("failed", "BrowserStack Local binary is not running", page); diff --git a/playwright-python/local-using-bindings-playwright-test.py b/playwright-python/local-using-bindings-playwright-test.py index 522414c..9794376 100644 --- a/playwright-python/local-using-bindings-playwright-test.py +++ b/playwright-python/local-using-bindings-playwright-test.py @@ -44,6 +44,7 @@ def run_local_session(playwright): .innerText .includes("This is an internal server for BrowserStack Local") """) + # following line of code is responsible for marking the status of the test on BrowserStack as 'passed'. You can use this code in your after hook after each test mark_test_status("passed", "Local is up and running", page) except Exception: mark_test_status("failed", "BrowserStack Local binary is not running", page)