-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathconftest.py
More file actions
55 lines (44 loc) · 1.66 KB
/
conftest.py
File metadata and controls
55 lines (44 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import pytest
import os
from selenium import webdriver
from selenium.webdriver.chrome.options import Options as ChromeOptions
@pytest.fixture(scope='function')
def driver(request):
options = ChromeOptions()
# Browser configuration
options.browser_version = "latest"
options.platform_name = os.environ.get("TARGET_OS", "Windows 10")
# LambdaTest specific options (Selenium 4 uses LT:Options capability)
lt_options = {
"build": "[Python] HyperTest demo using PyTest framework",
"name": request.node.name,
"video": True,
"visual": True,
"network": True,
"console": True
}
options.set_capability("LT:Options", lt_options)
username = os.environ.get("LT_USERNAME")
access_key = os.environ.get("LT_ACCESS_KEY")
selenium_endpoint = f"https://{username}:{access_key}@hub.lambdatest.com/wd/hub"
browser = webdriver.Remote(
command_executor=selenium_endpoint,
options=options
)
yield browser
def fin():
if request.node.rep_call.failed:
browser.execute_script("lambda-status=failed")
else:
browser.execute_script("lambda-status=passed")
browser.quit()
request.addfinalizer(fin)
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_runtest_makereport(item, call):
# this sets the result as a test attribute for LambdaTest reporting.
# execute all other hooks to obtain the report object
outcome = yield
rep = outcome.get_result()
# set an report attribute for each phase of a call, which can
# be "setup", "call", "teardown"
setattr(item, "rep_" + rep.when, rep)