-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support of remote browser. Lamdatest, BrowserStack, browserbase, anch…
…orbrowser. Added helper scripts to populate CDP_URL and proper documentation
- Loading branch information
Shriyansh Agnihotri
committed
Jan 23, 2025
1 parent
487874e
commit 92621fb
Showing
7 changed files
with
263 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import os | ||
import json | ||
import urllib.parse | ||
import subprocess | ||
|
||
# Use environment variables if set, else fallback to default strings | ||
BROWSERSTACK_USERNAME = os.environ.get('BROWSERSTACK_USERNAME', 'BROWSERSTACK_USERNAME') | ||
BROWSERSTACK_ACCESS_KEY = os.environ.get('BROWSERSTACK_ACCESS_KEY', 'BROWSERSTACK_ACCESS_KEY') | ||
|
||
desired_cap = { | ||
'os': 'osx', | ||
'os_version': 'catalina', | ||
'browser': 'chrome', # allowed browsers: chrome, edge, playwright-chromium, playwright-firefox, playwright-webkit | ||
'browser_version': 'latest', # valid only for `chrome` and `edge` | ||
'browserstack.username': BROWSERSTACK_USERNAME, | ||
'browserstack.accessKey': BROWSERSTACK_ACCESS_KEY, | ||
# 'browserstack.geoLocation': 'FR', | ||
'project': 'My First Project', | ||
'build': 'playwright-python-1', | ||
'name': 'My First Test', | ||
'buildTag': 'reg', | ||
'resolution': '1280x1024', | ||
'browserstack.local': 'false', | ||
'browserstack.localIdentifier': 'local_connection_name', | ||
'browserstack.playwrightVersion': '1.latest', | ||
'client.playwrightVersion': '1.latest', # We will overwrite this with the installed version | ||
'browserstack.debug': 'true', | ||
'browserstack.console': 'info', | ||
'browserstack.networkLogs': 'true', | ||
'browserstack.interactiveDebugging': 'true' | ||
} | ||
|
||
def create_cdp_url() -> str: | ||
# Dynamically get the local Playwright version | ||
playwright_version = subprocess.getoutput('playwright --version').strip().split()[1] | ||
desired_cap['client.playwrightVersion'] = playwright_version | ||
# import ipdb; ipdb.set_trace() | ||
# Construct the final CDP URL | ||
raw_caps = json.dumps(desired_cap) | ||
encoded_caps = urllib.parse.quote(raw_caps) | ||
cdp_url = f"wss://cdp.browserstack.com/playwright?caps={encoded_caps}" | ||
return cdp_url | ||
|
||
if __name__ == "__main__": | ||
print(create_cdp_url()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import os | ||
import json | ||
import urllib.parse | ||
import subprocess | ||
|
||
# Read from environment variables or use default | ||
LT_USERNAME = os.environ.get('LAMBDATEST_USERNAME', 'LAMBDATEST_USERNAME') | ||
LT_ACCESS_KEY = os.environ.get('LAMBDATEST_ACCESS_KEY', 'LAMBDATEST_ACCESS_KEY') | ||
|
||
capabilities = { | ||
'browserName': 'Chrome', # Browsers allowed: Chrome, MicrosoftEdge, pw-chromium, pw-firefox, pw-webkit | ||
'browserVersion': 'latest', | ||
'LT:Options': { | ||
'platform': 'Windows 11', | ||
'build': 'Playwright Python Build', | ||
'name': 'Playwright Test', | ||
'user': LT_USERNAME, | ||
'accessKey': LT_ACCESS_KEY, | ||
'network': True, | ||
'video': True, | ||
'console': True, | ||
'tunnel': False, # set to True if testing locally hosted pages | ||
# 'tunnelName': '', | ||
# 'geoLocation': '', # e.g. 'US', 'FR', 'IN' | ||
'playwrightClientVersion': '1.latest' # Will be updated dynamically | ||
} | ||
} | ||
|
||
def create_lt_cdp_url() -> str: | ||
# Dynamically get the local Playwright version | ||
playwright_version = subprocess.getoutput('playwright --version').strip().split()[1] | ||
# Update the capabilities to reflect the local Playwright version | ||
capabilities['LT:Options']['playwrightClientVersion'] = playwright_version | ||
|
||
# Construct the final CDP URL for LambdaTest | ||
raw_caps = json.dumps(capabilities) | ||
encoded_caps = urllib.parse.quote(raw_caps) | ||
lt_cdp_url = f"wss://cdp.lambdatest.com/playwright?capabilities={encoded_caps}" | ||
return lt_cdp_url | ||
|
||
if __name__ == "__main__": | ||
print(create_lt_cdp_url()) |
Oops, something went wrong.