forked from LambdaTest/python-selenium-sample
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lambdatest.py
100 lines (81 loc) · 3.25 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
import unittest
import os
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options as ChromeOptions
username = os.getenv("LT_USERNAME") # Replace the username
access_key = os.getenv("LT_ACCESS_KEY") # Replace the access key
# paste your capibility options below
options = ChromeOptions()
options.browser_version = "latest"
options.platform_name = "win10"
lt_options = {}
lt_options["username"] = username
lt_options["accessKey"] = access_key
lt_options["video"] = True
lt_options["resolution"] = "1920x1080"
lt_options["network"] = True
lt_options["build"] = "test_build"
lt_options["project"] = "unit_testing"
lt_options["smartUI.project"] = "test"
lt_options["name"] = "basic_unit_selinium"
lt_options["w3c"] = True
lt_options["plugin"] = "python-python"
options.set_capability("LT:Options", lt_options)
# 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/
class FirstSampleTest(unittest.TestCase):
driver = None
def setUp(self):
self.driver = webdriver.Remote(
command_executor="http://{}:{}@hub.lambdatest.com/wd/hub".format(
username, access_key
),
options=options,
)
# """ 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")
# tearDown runs after each test case
def tearDown(self):
self.driver.quit()
if __name__ == "__main__":
unittest.main()