Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,16 @@ 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\")");

// 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", err.getMessage(), page);
markTestStatus("failed", "BrowserStack Local binary is not running", page);
}
browser.close();

Expand Down
9 changes: 3 additions & 6 deletions playwright-python/local-playwright-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,18 @@
'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

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()
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:
Expand Down
45 changes: 23 additions & 22 deletions playwright-python/local-using-bindings-playwright-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,33 +27,34 @@ 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":
try:
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")
""")
# 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()
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 + "\"}}");
Expand Down