|
| 1 | + |
| 2 | +import unittest |
| 3 | +import time |
| 4 | +import os |
| 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 |
| 10 | + |
| 11 | + |
| 12 | +class FirstSampleTest(unittest.TestCase): |
| 13 | + # Generate capabilites from here: https://www.lambdatest.com/capabilities-generator/ |
| 14 | + # setUp runs before each test case and |
| 15 | + def setUp(self): |
| 16 | + desired_caps = { |
| 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": "firefox", |
| 26 | + "browserVersion": "latest", |
| 27 | + } |
| 28 | + |
| 29 | + self.driver = webdriver.Remote( |
| 30 | + command_executor="http://{}:{}@hub.lambdatest.com/wd/hub".format( |
| 31 | + username, access_key), |
| 32 | + desired_capabilities=desired_caps) |
| 33 | + |
| 34 | + |
| 35 | +# tearDown runs after each test case |
| 36 | + |
| 37 | + |
| 38 | + def tearDown(self): |
| 39 | + self.driver.quit() |
| 40 | + |
| 41 | + # """ You can write the test cases here """ |
| 42 | + def test_demo_site(self): |
| 43 | + |
| 44 | + # try: |
| 45 | + driver = self.driver |
| 46 | + |
| 47 | + # Url |
| 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.") |
| 56 | + |
| 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.") |
| 62 | + |
| 63 | + # Searching for the results |
| 64 | + search = driver.find_element(By.XPATH, "//*[@id='search']") |
| 65 | + assert search.is_displayed(), "Search is not displayed" |
| 66 | + search.click() |
| 67 | + driver.implicitly_wait(3) |
| 68 | + |
| 69 | + # Let's select one of the hotels for booking |
| 70 | + reserve = driver.find_element(By.ID, "reserve-now") |
| 71 | + reserve.click() |
| 72 | + driver.implicitly_wait(3) |
| 73 | + proceed = driver.find_element(By.ID, "proceed") |
| 74 | + proceed.click() |
| 75 | + driver.implicitly_wait(3) |
| 76 | + print("Booking is confirmed.") |
| 77 | + |
| 78 | + # Let's download the invoice |
| 79 | + download = driver.find_element(By.ID, "invoice") |
| 80 | + if (download.is_displayed()): |
| 81 | + download.click() |
| 82 | + driver.execute_script("lambda-status=passed") |
| 83 | + print("Tests are run successfully!") |
| 84 | + else: |
| 85 | + driver.execute_script("lambda-status=failed") |
| 86 | + |
| 87 | + |
| 88 | +if __name__ == "__main__": |
| 89 | + unittest.main() |
0 commit comments