|
| 1 | + |
1 | 2 | import unittest
|
2 |
| -import sys |
| 3 | +import time |
| 4 | +import os |
3 | 5 | from selenium import webdriver
|
| 6 | +from selenium.webdriver.common.by import By |
| 7 | + |
| 8 | +username = os.getenv("LT_USERNAME") # Replace the username |
| 9 | +access_key = os.getenv("LT_ACCESS_KEY") # Replace the access key |
4 | 10 |
|
5 |
| -username = "Your Username" # Replace the username |
6 |
| -access_key = "Your Access Key" # Replace the access key |
7 | 11 |
|
8 | 12 | class FirstSampleTest(unittest.TestCase):
|
9 | 13 | # Generate capabilites from here: https://www.lambdatest.com/capabilities-generator/
|
10 |
| - # setUp runs before each test case and |
| 14 | + # setUp runs before each test case and |
11 | 15 | def setUp(self):
|
12 | 16 | desired_caps = {
|
13 |
| - "build": 'PyunitTest sample build', # Change your build name here |
14 |
| - "name": 'Py-unittest', # Change your test name here |
15 |
| - "browserName": 'Chrome', |
16 |
| - "version": '92.0', |
17 |
| - "platform": 'Windows 10', |
18 |
| - "resolution": '1024x768', |
19 |
| - "console": 'true', # Enable or disable console logs |
20 |
| - "network":'true' # Enable or disable network logs |
| 17 | + 'LT:Options': { |
| 18 | + "build": "Python Demo", # Change your build name here |
| 19 | + "name": "Python Demo Test", # Change your test name here |
| 20 | + "platformName": "Windows 11", |
| 21 | + "selenium_version": "4.0.0", |
| 22 | + "console": 'true', # Enable or disable console logs |
| 23 | + "network": 'true' # Enable or disable network logs |
| 24 | + }, |
| 25 | + "browserName": "Chrome", |
| 26 | + "browserVersion": "98.0", |
21 | 27 | }
|
| 28 | + |
22 | 29 | self.driver = webdriver.Remote(
|
23 |
| - command_executor="https://{}:{}@hub.lambdatest.com/wd/hub".format(username, access_key), |
24 |
| - desired_capabilities= desired_caps) |
| 30 | + command_executor="https://{}:{}@hub.lambdatest.com/wd/hub".format( |
| 31 | + username, access_key), |
| 32 | + desired_capabilities=desired_caps) |
25 | 33 |
|
26 | 34 |
|
27 | 35 | # tearDown runs after each test case
|
| 36 | + |
| 37 | + |
28 | 38 | def tearDown(self):
|
29 | 39 | self.driver.quit()
|
30 | 40 |
|
31 | 41 | # """ You can write the test cases here """
|
32 |
| - def test_unit_user_should_able_to_add_item(self): |
| 42 | + def test_demo_site(self): |
| 43 | + |
33 | 44 | # try:
|
34 | 45 | driver = self.driver
|
35 | 46 |
|
36 | 47 | # Url
|
37 |
| - driver.get("https://lambdatest.github.io/sample-todo-app/") |
| 48 | + print('Loading URL') |
| 49 | + driver.get("https://stage-demo.lambdatest.com/") |
| 50 | + |
| 51 | + # Let's select the location |
| 52 | + driver.find_element(By.ID, "headlessui-listbox-button-1").click() |
| 53 | + location = driver.find_element(By.ID, "Bali") |
| 54 | + location.click() |
| 55 | + print("Location is selected as Bali.") |
38 | 56 |
|
39 |
| - # Click on check box |
40 |
| - check_box_one = driver.find_element_by_name("li1") |
41 |
| - check_box_one.click() |
| 57 | + # Let's select the number of guests |
| 58 | + driver.find_element(By.ID, "headlessui-listbox-button-5").click() |
| 59 | + guests = driver.find_element(By.ID, "2") |
| 60 | + guests.click() |
| 61 | + print("Number of guests are selected.") |
42 | 62 |
|
43 |
| - # Click on check box |
44 |
| - check_box_two = driver.find_element_by_name("li2") |
45 |
| - check_box_two.click() |
| 63 | + # Searching for the results |
| 64 | + search = driver.find_element(By.XPATH, "//*[@id='search']") |
| 65 | + search.click() |
| 66 | + driver.implicitly_wait(3) |
46 | 67 |
|
47 |
| - # Enter item in textfield |
48 |
| - textfield = driver.find_element_by_id("sampletodotext") |
49 |
| - textfield.send_keys("Yey, Let's add it to list") |
| 68 | + # Let's select one of the hotels for booking |
| 69 | + reserve = driver.find_element(By.ID, "reserve-now") |
| 70 | + reserve.click() |
| 71 | + driver.implicitly_wait(3) |
| 72 | + proceed = driver.find_element(By.ID, "proceed") |
| 73 | + proceed.click() |
| 74 | + driver.implicitly_wait(3) |
| 75 | + print("Booking is confirmed.") |
50 | 76 |
|
51 |
| - # Click on add button |
52 |
| - add_button = driver.find_element_by_id("addbutton") |
53 |
| - add_button.click() |
| 77 | + # Let's download the invoice |
| 78 | + download = driver.find_element(By.ID, "invoice") |
| 79 | + if (download.is_displayed()): |
| 80 | + download.click() |
| 81 | + driver.execute_script("lambda-status=passed") |
| 82 | + print("Tests are run successfully!") |
| 83 | + else: |
| 84 | + driver.execute_script("lambda-status=failed") |
54 | 85 |
|
55 |
| - # Verified added item |
56 |
| - added_item = driver.find_element_by_xpath("//span[@class='done-false']").text |
57 |
| - print (added_item) |
58 | 86 |
|
59 | 87 | if __name__ == "__main__":
|
60 | 88 | unittest.main()
|
0 commit comments