-
Notifications
You must be signed in to change notification settings - Fork 8
Added custom fixture to fix session merge issue #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import threading | ||
| import urllib | ||
| import uuid | ||
| #import threading | ||
| from multiprocessing import Process, Lock | ||
| import pytest | ||
| from browserstack.local import Local | ||
| import os, json | ||
| from jsonmerge import merge | ||
| from dotenv import load_dotenv | ||
| import time | ||
|
|
||
| from playwright.sync_api import Playwright | ||
| from playwright.sync_api import Page | ||
|
|
||
| lock = Lock() | ||
| threaded_count = 0 | ||
|
|
||
| load_dotenv() | ||
|
|
||
| TASK_ID = int(os.environ['TASK_ID']) if 'TASK_ID' in os.environ else 0 | ||
|
|
||
|
|
||
| BROWSERSTACK_USERNAME = os.environ['BROWSERSTACK_USERNAME'] | ||
| BROWSERSTACK_ACCESS_KEY = os.environ['BROWSERSTACK_ACCESS_KEY'] | ||
|
|
||
|
|
||
| def update_session_name(page, session_name=''): | ||
| if not (page and session_name): | ||
| return | ||
|
|
||
| command = { | ||
| "action": "setSessionName", | ||
| "arguments": { | ||
| "name": session_name | ||
| } | ||
| } | ||
|
|
||
| browser_stack_command = f"browserstack_executor: {json.dumps(command)}" | ||
| result = page.evaluate("() => {}", browser_stack_command) | ||
| return json.loads(result) | ||
|
|
||
| if os.environ.get('REMOTE', 'true') == "true": | ||
| @pytest.fixture(scope='function') | ||
| def session_capabilities(playwright: Playwright): | ||
| global timenow | ||
| global lock | ||
| test_name = os.environ.get('PYTEST_CURRENT_TEST').split(' ')[0].split('::')[1] | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. doesn't this create duplicate tests at browserstack. Please attach sessions
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| capabilities = {} | ||
| stringifiedCaps = urllib.parse.quote(json.dumps(capabilities)) | ||
| caps = 'wss://cdp.browserstack.com/playwright?caps=' + stringifiedCaps | ||
| browser = playwright.chromium.launch() | ||
| context = browser.new_context() | ||
| page = context.new_page() | ||
| print(f'Test name is {test_name}') | ||
| update_session_name(page,test_name) | ||
|
|
||
| yield page | ||
| context.close() | ||
| browser.close() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,8 @@ | |
| from playwright.sync_api import expect | ||
|
|
||
|
|
||
| def test_bstack_sample(page) -> None: | ||
| def test_sample(session_capabilities) -> None: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same change for local test as well |
||
| page = session_capabilities | ||
| try: | ||
| # Navigate to the base url | ||
| page.goto("https://bstackdemo.com/", timeout=0) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this condition not needed