forked from Shahnawaz-Sk/python-selenium-sample_2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlambdatest.py
210 lines (171 loc) · 8.03 KB
/
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# import unittest
# import os
# from selenium import webdriver
# from selenium.webdriver.common.by import By
# username = os.getenv("LT_USERNAME") # Replace the username
# access_key = os.getenv("LT_ACCESS_KEY") # Replace the access key
# build_name = os.getenv("LT_BUILD_NAME")
# class FirstSampleTest(unittest.TestCase):
# # Generate capabilites from here: https://www.lambdatest.com/capabilities-generator/
# # setUp runs before each test case and
# def setUp(self):
# desired_caps = {
# 'LT:Options': {
# "build": build_name, # Change your build name here
# "name": "Python Demo Test", # Change your test name here
# "platformName": "Windows 11",
# "selenium_version": "4.0.0",
# "console": 'true', # Enable or disable console logs
# "network": 'true', # Enable or disable network logs
# #Enable Smart UI Project
# #"smartUI.project": "<Project Name>"
# },
# "browserName": "firefox",
# "browserVersion": "latest",
# }
# # Steps to run Smart UI project (https://beta-smartui.lambdatest.com/)
# # Step - 1 : Change the hub URL to @beta-smartui-hub.lambdatest.com/wd/hub
# # Step - 2 : Add "smartUI.project": "<Project Name>" as a capability above
# # Step - 3 : Run "driver.execute_script("smartui.takeScreenshot")" command wherever you need to take a screenshot
# # Note: for additional capabilities navigate to https://www.lambdatest.com/support/docs/test-settings-options/
# self.driver = webdriver.Remote(
# command_executor="http://{}:{}@hub.lambdatest.com/wd/hub".format(
# username, access_key),
# desired_capabilities=desired_caps)
# # tearDown runs after each test case
# def tearDown(self):
# self.driver.quit()
# # """ You can write the test cases here """
# def test_demo_site(self):
# # try:
# driver = self.driver
# driver.implicitly_wait(10)
# driver.set_page_load_timeout(30)
# driver.set_window_size(1920, 1080)
# # Url
# print('Loading URL')
# driver.get("https://stage-lambda-devops-use-only.lambdatestinternal.com/To-do-app/index.html")
# # Let's click on a element
# driver.find_element(By.NAME, "li1").click()
# location = driver.find_element(By.NAME, "li2")
# location.click()
# print("Clicked on the second element")
# #Take Smart UI screenshot
# #driver.execute_script("smartui.takeScreenshot")
# # Let's add a checkbox
# driver.find_element(By.ID, "sampletodotext").send_keys("LambdaTest")
# add_button = driver.find_element(By.ID, "addbutton")
# add_button.click()
# print("Added LambdaTest checkbox")
# # print the heading
# search = driver.find_element(By.CSS_SELECTOR, ".container h2")
# assert search.is_displayed(), "heading is not displayed"
# print(search.text)
# search.click()
# driver.implicitly_wait(3)
# # Let's download the invoice
# heading = driver.find_element(By.CSS_SELECTOR, ".container h2")
# if heading.is_displayed():
# heading.click()
# driver.execute_script("lambda-status=passed")
# print("Tests are run successfully!")
# else:
# driver.execute_script("lambda-status=failed")
# if __name__ == "__main__":
# unittest.main()
import unittest
import os
from selenium import webdriver
from selenium.webdriver.chrome.options import Options as ChromeOptions
from selenium.webdriver.common.by import By
# username = os.getenv("LT_USERNAME") # Replace the username
# username = os.getenv("BROWSERSTACK_USERNAME")
# # access_key = os.getenv("LT_ACCESS_KEY") # Replace the access key
# access_key = os.getenv("BROWSERSTACK_ACCESS_KEY")
# build_name = os.getenv("LT_BUILD_NAME")
class FirstSampleTest(unittest.TestCase):
# Generate capabilites from here: https://www.lambdatest.com/capabilities-generator/
# setUp runs before each test case and
def setUp(self):
BROWSERSTACK_USERNAME = os.environ.get("BROWSERSTACK_USERNAME") or "BROWSERSTACK_USERNAME"
BROWSERSTACK_ACCESS_KEY = os.environ.get("BROWSERSTACK_ACCESS_KEY") or "BROWSERSTACK_ACCESS_KEY"
BROWSERSTACK_BUILD_NAME = os.environ.get("BROWSERSTACK_BUILD_NAME")
URL = os.environ.get("URL") or "https://hub.browserstack.com/wd/hub"
bstack_options = {
"os" : "OS X",
"osVersion" : "Monterey",
"buildName" : BROWSERSTACK_BUILD_NAME,
"sessionName" : "BStack single python",
"userName": BROWSERSTACK_USERNAME,
"accessKey": BROWSERSTACK_ACCESS_KEY
}
bstack_options["source"] = "python:sample-main:v1.0"
options = ChromeOptions()
options.set_capability('bstack:options', bstack_options)
self.driver = webdriver.Remote(
command_executor=URL,
options=options)
# desired_caps = {
# 'LT:Options': {
# "build": build_name, # Change your build name here
# "name": "Python Demo Test", # Change your test name here
# "platformName": "Windows 11",
# "selenium_version": "4.0.0",
# "console": 'true', # Enable or disable console logs
# "network": 'true', # Enable or disable network logs
# #Enable Smart UI Project
# #"smartUI.project": "<Project Name>"
# },
# "browserName": "firefox",
# "browserVersion": "latest",
# }
# Steps to run Smart UI project (https://beta-smartui.lambdatest.com/)
# Step - 1 : Change the hub URL to @beta-smartui-hub.lambdatest.com/wd/hub
# Step - 2 : Add "smartUI.project": "<Project Name>" as a capability above
# Step - 3 : Run "driver.execute_script("smartui.takeScreenshot")" command wherever you need to take a screenshot
# Note: for additional capabilities navigate to https://www.lambdatest.com/support/docs/test-settings-options/
# self.driver = webdriver.Remote(
# command_executor="http://{}:{}@hub.lambdatest.com/wd/hub".format(
# username, access_key),
# desired_capabilities=desired_caps)
# tearDown runs after each test case
def tearDown(self):
self.driver.quit()
# """ You can write the test cases here """
def test_demo_site(self):
# try:
driver = self.driver
driver.implicitly_wait(10)
driver.set_page_load_timeout(30)
driver.set_window_size(1920, 1080)
# Url
print('Loading URL')
driver.get("https://stage-lambda-devops-use-only.lambdatestinternal.com/To-do-app/index.html")
# Let's click on a element
driver.find_element(By.NAME, "li1").click()
location = driver.find_element(By.NAME, "li2")
location.click()
print("Clicked on the second element")
#Take Smart UI screenshot
#driver.execute_script("smartui.takeScreenshot")
# Let's add a checkbox
driver.find_element(By.ID, "sampletodotext").send_keys("LambdaTest")
add_button = driver.find_element(By.ID, "addbutton")
add_button.click()
print("Added LambdaTest checkbox")
# print the heading
search = driver.find_element(By.CSS_SELECTOR, ".container h2")
assert search.is_displayed(), "heading is not displayed"
print(search.text)
search.click()
driver.implicitly_wait(3)
# Let's download the invoice
heading = driver.find_element(By.CSS_SELECTOR, ".container h2")
# if heading.is_displayed():
# heading.click()
# # driver.execute_script("lambda-status=passed")
# print("Tests are run successfully!")
# else:
# # driver.execute_script("lambda-status=failed")
if __name__ == "__main__":
unittest.main()