forked from LambdaTest/python-selenium-sample
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoogle-serach-lambdatest.py
97 lines (80 loc) · 3.08 KB
/
google-serach-lambdatest.py
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import unittest
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
class LTAutomate(unittest.TestCase):
"""
LambdaTest selenium automation sample example
Configuration
----------
username: Username can be found at automation dashboard
accessToken: AccessToken can be genarated from automation dashboard or profile section
Result
-------
Execute Test on lambdatest Distributed Grid perform selenium automation based
"""
def setUp(self):
"""
Setup remote driver
Params
----------
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)
browserName : Supported platfrom - (chrome, firefox, Internet Explorer, MicrosoftEdge)
version : Supported list of version can be found at https://www.lambdatest.com/capabilities-generator/
Result
-------
"""
# username: Username can be found at automation dashboard
username="{username}"
# accessToken: AccessToken can be genarated from automation dashboard or profile section
accessToken="{accessToken}"
# gridUrl: gridUrl can be found at automation dashboard
gridUrl = "hub.lambdatest.com/wd/hub"
desired_cap = {
'platform' : "win10",
'browserName' : "chrome",
'version' : "67.0",
# Resolution of machine
"resolution": "1024x768",
"name": "LambdaTest python google search test ",
"build": "LambdaTest python google search build",
"network": True,
"video": True,
"visual": True,
"console": True,
}
# URL: https://{username}:{accessToken}@beta-hub.lambdatest.com/wd/hub
url = "https://"+username+":"+accessToken+"@"+gridUrl
print("Initiating remote driver on platfrom: "+desired_cap["platform"]+" browser: "+desired_cap["browserName"]+" version: "+desired_cap["version"])
self.driver = webdriver.Remote(
desired_capabilities=desired_cap,
command_executor= url
)
def test_search_in_google(self):
"""
Setup remote driver
Params
----------
Execute test: navigate google.com search LambdaTest
Result
-------
print title
"""
driver = self.driver
print("Driver initiated sucessfully. Navigate url")
driver.get("https://www.google.com/ncr")
print("Searching lambdatest on google.com ")
time.sleep(8)
elem = driver.find_element_by_name("q")
elem.send_keys("lambdatest.com")
elem.submit()
print("Printing title of current page :"+driver.title)
driver.execute_script("lambda-status=passed")
print("Requesting to mark test : pass")
def tearDown(self):
"""
Quit selenium driver
"""
self.driver.quit()
if __name__ == "__main__":
unittest.main()