Skip to content

Commit ece926f

Browse files
committed
python LT sample test
0 parents  commit ece926f

File tree

3 files changed

+122
-0
lines changed

3 files changed

+122
-0
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
## Python unittest automation Lambdatest
2+
=======================
3+
4+
Python selenium automation sample test for Lambdatest Cloud GRID.
5+
6+
7+
## Install Python
8+
- Download the latest python build from https://www.python.org/downloads/
9+
- Make sure pip should installed. you can check using `pip --version`
10+
11+
12+
### configuring test.
13+
- Replace {username} with your username
14+
- Replace {accessToken} with your username
15+
- List of supported platfrom, browser, version can be found at https://www.lambdatest.com/capabilities-generator/
16+
17+
18+
### Installating dependencies.
19+
```bash
20+
pip install selenium
21+
export PYTHONWARNINGS="ignore:Unverified HTTPS request" //Disable ssl warning
22+
```
23+
24+
### Executing test
25+
```bash
26+
python google-serach-lambdatest.py
27+
```

google-serach-lambdatest.py

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
"""
2+
LambdaTest selenium automation sample example
3+
Configuration
4+
----------
5+
username: Username can be found at automation dashboard
6+
accessToken: AccessToken can be genarated from automation dashboard or profile section
7+
8+
Result
9+
-------
10+
Execute Test on lambdatest Distributed Grid perform selenium automation based
11+
"""
12+
import unittest
13+
import time
14+
from selenium import webdriver
15+
from selenium.webdriver.common.keys import Keys
16+
17+
18+
19+
class LTAutomate(unittest.TestCase):
20+
21+
"""
22+
Setup remote driver
23+
Params
24+
----------
25+
platfrom : Supported platfrom - (Windows 10, Windows 8.1, Windows 8, Windows 7, macOS High Sierra, macOS Sierra, OS X El Capitan, OS X Yosemite, OS X Mavericks)
26+
browserName : Supported platfrom - (chrome, firefox, Internet Explorer, MicrosoftEdge)
27+
version : Supported list of version can be found at https://www.lambdatest.com/capabilities-generator/
28+
29+
Result
30+
-------
31+
"""
32+
def setUp(self):
33+
# username: Username can be found at automation dashboard
34+
username="{username}"
35+
# accessToken: AccessToken can be genarated from automation dashboard or profile section
36+
accessToken="{accessToken}"
37+
# gridUrl: gridUrl can be found at automation dashboard
38+
gridUrl = "beta-hub.lambdatest.com/wd/hub"
39+
40+
desired_cap = {
41+
'platform' : "win10",
42+
'browserName' : "chrome",
43+
'version' : "67.0",
44+
# Resolution of machine
45+
"resolution": "1024x768",
46+
"name": "LambdaTest python google search test ",
47+
"build": "LambdaTest python google search build",
48+
"network": True,
49+
"video": True,
50+
"visual": True,
51+
"console": True,
52+
}
53+
54+
# URL: https://{username}:{accessToken}@beta-hub.lambdatest.com/wd/hub
55+
url = "https://"+username+":"+accessToken+"@"+gridUrl
56+
57+
print("Initiating remote driver on platfrom: "+desired_cap["platform"]+" browser: "+desired_cap["browserName"]+" version: "+desired_cap["version"])
58+
self.driver = webdriver.Remote(
59+
desired_capabilities=desired_cap,
60+
command_executor= url
61+
)
62+
63+
"""
64+
Setup remote driver
65+
Params
66+
----------
67+
Execute test: navigate google.com search LambdaTest
68+
Result
69+
-------
70+
print title
71+
"""
72+
def test_search_in_google(self):
73+
driver = self.driver
74+
print("Driver initiated sucessfully. Navigate url")
75+
driver.get("https://www.google.com/ncr")
76+
77+
print("Searching lambdatest on google.com ")
78+
time.sleep(8)
79+
elem = driver.find_element_by_name("q")
80+
elem.send_keys("lambdatest.com")
81+
elem.submit()
82+
83+
print("Printing title of current page :"+driver.title)
84+
driver.execute_script("lambda-status=passed")
85+
print("Requesting to mark test : pass")
86+
87+
"""
88+
Quit selenium driver
89+
"""
90+
def tearDown(self):
91+
self.driver.quit()
92+
93+
if __name__ == "__main__":
94+
unittest.main()

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
selenium==3.141.0

0 commit comments

Comments
 (0)