Skip to content

Commit 5b22f08

Browse files
authored
Merge pull request #14 from DUMBANIKET/master
New selenium update bug fixes
2 parents 3b9a447 + dd81996 commit 5b22f08

File tree

2 files changed

+42
-38
lines changed

2 files changed

+42
-38
lines changed

README.md

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,23 @@ Make sure you have your LambdaTest credentials with you to run test automation s
8080

8181
**Step 4:** In the python script, you need to update your test capabilities. In this code, we are passing browser, browser version, and operating system information, along with LambdaTest Selenium grid capabilities via capabilities object.
8282

83-
The capabilities object in the above code are defined as:
83+
The capabilities in the below code are defined as:
8484

8585
```python
86-
capabilities = {
87-
"build": "your build name",
88-
"name": "your test name",
89-
"platformName": "Windows 10"
90-
"browserName": "Chrome",
91-
"browserVersion": "latest",
92-
}
86+
options = ChromeOptions()
87+
options.browser_version = "114.0"
88+
options.platform_name = "macOS High Sierra"
89+
lt_options = {}
90+
lt_options["video"] = True
91+
lt_options["resolution"] = "1920x1080"
92+
lt_options["network"] = True
93+
lt_options["build"] = "test_build"
94+
lt_options["project"] = "unit_testing"
95+
lt_options["smartUI.project"] = "test"
96+
lt_options["name"] = "basic_unit_selinium"
97+
lt_options["w3c"] = True
98+
lt_options["plugin"] = "python-python"
99+
options.set_capability('LT:Options', lt_options)
93100
```
94101
You can generate capabilities for your test requirements with the help of our inbuilt [Desired Capability Generator](https://www.lambdatest.com/capabilities-generator/?utm_source=github&utm_medium=repo&utm_campaign=python-selenium-sample).
95102

lambdatest.py

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,41 @@
33
import os
44
from selenium import webdriver
55
from selenium.webdriver.common.by import By
6+
from selenium.webdriver.chrome.options import Options as ChromeOptions
67

78
username = os.getenv("LT_USERNAME") # Replace the username
89
access_key = os.getenv("LT_ACCESS_KEY") # Replace the access key
910

1011

11-
class FirstSampleTest(unittest.TestCase):
12-
# Generate capabilites from here: https://www.lambdatest.com/capabilities-generator/
13-
# setUp runs before each test case and
14-
def setUp(self):
15-
desired_caps = {
16-
'LT:Options': {
17-
"build": "Python Demo", # Change your build name here
18-
"name": "Python Demo Test", # Change your test name here
19-
"platformName": "Windows 11",
20-
"selenium_version": "4.0.0",
21-
"console": 'true', # Enable or disable console logs
22-
"network": 'true', # Enable or disable network logs
23-
#Enable Smart UI Project
24-
#"smartUI.project": "<Project Name>"
25-
},
26-
"browserName": "firefox",
27-
"browserVersion": "latest",
28-
}
12+
#paste your capibility options below
13+
14+
options = ChromeOptions()
15+
options.browser_version = "114.0"
16+
options.platform_name = "macOS High Sierra"
17+
lt_options = {}
18+
lt_options["username"] = username
19+
lt_options["accessKey"] = access_key
20+
lt_options["video"] = True
21+
lt_options["resolution"] = "1920x1080"
22+
lt_options["network"] = True
23+
lt_options["build"] = "test_build"
24+
lt_options["project"] = "unit_testing"
25+
lt_options["smartUI.project"] = "test"
26+
lt_options["name"] = "basic_unit_selinium"
27+
lt_options["w3c"] = True
28+
lt_options["plugin"] = "python-python"
29+
options.set_capability('LT:Options', lt_options)
30+
2931

3032
# Steps to run Smart UI project (https://beta-smartui.lambdatest.com/)
3133
# Step - 1 : Change the hub URL to @beta-smartui-hub.lambdatest.com/wd/hub
3234
# Step - 2 : Add "smartUI.project": "<Project Name>" as a capability above
3335
# Step - 3 : Run "driver.execute_script("smartui.takeScreenshot")" command wherever you need to take a screenshot
3436
# Note: for additional capabilities navigate to https://www.lambdatest.com/support/docs/test-settings-options/
3537

36-
self.driver = webdriver.Remote(
37-
command_executor="http://{}:{}@hub.lambdatest.com/wd/hub".format(
38-
username, access_key),
39-
desired_capabilities=desired_caps)
40-
41-
# tearDown runs after each test case
42-
43-
44-
def tearDown(self):
45-
self.driver.quit()
38+
class FirstSampleTest(unittest.TestCase):
39+
def setUp(self):
40+
driver = webdriver.Remote(command_executor="http://{}:{}@hub.lambdatest.com/wd/hub".format(username, access_key),options=options)
4641

4742
# """ You can write the test cases here """
4843
def test_demo_site(self):
@@ -87,7 +82,9 @@ def test_demo_site(self):
8782
print("Tests are run successfully!")
8883
else:
8984
driver.execute_script("lambda-status=failed")
90-
85+
# tearDown runs after each test case
86+
def tearDown(self):
87+
self.driver.quit()
9188

9289
if __name__ == "__main__":
93-
unittest.main()
90+
unittest.main()

0 commit comments

Comments
 (0)