Skip to content

Commit e942fd3

Browse files
committed
LambdaTest fixture example with Selenium and Pylenium
1 parent f422bd6 commit e942fd3

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

tests/test_todo.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
import os
12
import pytest
3+
from selenium import webdriver
4+
from pylenium.config import PyleniumConfig
25
from pylenium.driver import Pylenium
36
from pylenium.element import Element, Elements
47

@@ -23,6 +26,68 @@ def add_todo(self, name: str) -> 'TodoPage':
2326
return self
2427

2528

29+
@pytest.fixture
30+
def selenium():
31+
# 1. Define the 3 pieces needed to connect to LambdaTest
32+
username = os.getenv('LT_USERNAME')
33+
access_key = os.getenv('LT_ACCESS_KEY')
34+
remote_url = "https://{}:{}@hub.lambdatest.com/wd/hub".format(username, access_key)
35+
36+
# 2. Define the Desired Capabilities for this Test Run
37+
desired_caps = {
38+
"build": 'PyunitTest sample build', # Change your build name here
39+
"name": 'Py-unittest', # Change your test name here
40+
"platform": 'Windows 10', # Change your OS version here
41+
"browserName": 'Chrome', # Change your browser here
42+
"version": '87.0', # Change your browser version here
43+
"resolution": '1024x768', # Change your resolution here
44+
"console": 'true', # Enable or disable console logs
45+
"network": 'true' # Enable or disable network logs
46+
}
47+
48+
# 3. Instantiate a new Remote WebDriver that is connected to LambdaTest
49+
driver = webdriver.Remote(
50+
command_executor=remote_url,
51+
desired_capabilities=desired_caps)
52+
53+
# 4. Yield the driver so the test can use it, then quit() when the test is complete
54+
yield driver
55+
driver.quit()
56+
57+
58+
@pytest.fixture
59+
def LT(py_config: PyleniumConfig):
60+
# 1. Define the 3 pieces needed to connect to LambdaTest
61+
username = os.getenv('LT_USERNAME')
62+
access_key = os.getenv('LT_ACCESS_KEY')
63+
remote_url = f'https://{username}:{access_key}@hub.lambdatest.com/wd/hub'
64+
# update Pylenium's config with this URL
65+
# * You can also set this in pylenium.json or via the CLI! *
66+
py_config.driver.remote_url = remote_url
67+
68+
# 2. Update the Desired Capabilities for this Test Run
69+
desired_caps = {
70+
"build": 'pytest build',
71+
"name": 'pytest tutorial',
72+
"platform": 'Windows 10',
73+
"browserName": 'Chrome',
74+
"version": '87.0',
75+
"resolution": '1024x768',
76+
"console": 'true',
77+
"network": 'true'
78+
}
79+
# update Pylenium's config with this dictionary
80+
# * You can also set this in pylenium.json or via the CLI! *
81+
py_config.driver.capabilities.update(desired_caps)
82+
83+
# 3. Instantiate a new instance of Pylenium that is connected to LambdaTest
84+
py = Pylenium(py_config)
85+
86+
# 4. Yield the driver so the test can use it, then quit() when the test is complete
87+
yield py
88+
py.quit()
89+
90+
2691
@pytest.fixture
2792
def page(py: Pylenium):
2893
return TodoPage(py).goto()

0 commit comments

Comments
 (0)