|
| 1 | +import os |
| 2 | +import unittest |
| 3 | +import sys |
| 4 | +from selenium import webdriver |
| 5 | + |
| 6 | +username = os.environ.get("LT_USERNAME") |
| 7 | +access_key = os.environ.get("LT_ACCESS_KEY") |
| 8 | + |
| 9 | + |
| 10 | +class FirstSampleTest(unittest.TestCase): |
| 11 | + |
| 12 | + # setUp runs before each test case |
| 13 | + def setUp(self): |
| 14 | + desired_caps = { |
| 15 | + 'LT:Options': { |
| 16 | + "user": username, |
| 17 | + "accessKey": access_key, |
| 18 | + "build": "Python-Selenium-Sample", |
| 19 | + "name": "Python-Selenium-Test", |
| 20 | + "platformName": "Windows 11", |
| 21 | + "selenium_version": "4.0.0" |
| 22 | + }, |
| 23 | + "browserName": "Chrome", |
| 24 | + "browserVersion": "latest", |
| 25 | + } |
| 26 | + |
| 27 | + self.driver = webdriver.Remote( |
| 28 | + command_executor="http://hub.lambdatest.com:80/wd/hub", |
| 29 | + desired_capabilities=desired_caps) |
| 30 | + |
| 31 | + |
| 32 | +# tearDown runs after each test case |
| 33 | + |
| 34 | + def tearDown(self): |
| 35 | + self.driver.quit() |
| 36 | + |
| 37 | + def scroll_bottom(): |
| 38 | + """ |
| 39 | + Verify scrolling to bottom |
| 40 | + :return: None |
| 41 | + """ |
| 42 | + driver.get('https://www.lambdatest.com/') |
| 43 | + driver.maximize_window() |
| 44 | + sleep(2) |
| 45 | + success = driver.execute_script("window.scrollTo(0, document.body.scrollHeight);") |
| 46 | + sleep(5) |
| 47 | + assert success == True |
| 48 | + |
| 49 | + def scroll_infinite(): |
| 50 | + """ |
| 51 | + Verify infinite scroll |
| 52 | + :return: None |
| 53 | + """ |
| 54 | + SCROLL_PAUSE_TIME = 0.5 |
| 55 | + |
| 56 | + # Get scroll height |
| 57 | + last_height = driver.execute_script("return document.body.scrollHeight") |
| 58 | + |
| 59 | + #controls how many times scrolled to bottom |
| 60 | + scroll_pass = 0 |
| 61 | + |
| 62 | + #change to True for infinite scroll |
| 63 | + while scroll_pass < 10: |
| 64 | + # Scroll down to bottom |
| 65 | + driver.execute_script("window.scrollTo(0, document.body.scrollHeight);") |
| 66 | + |
| 67 | + # Wait to load page |
| 68 | + time.sleep(SCROLL_PAUSE_TIME) |
| 69 | + |
| 70 | + # Calculate new scroll height and compare with last scroll height |
| 71 | + new_height = driver.execute_script("return document.body.scrollHeight") |
| 72 | + if new_height == last_height: |
| 73 | + break |
| 74 | + last_height = new_height |
| 75 | + scroll_pass+=1 |
| 76 | + |
| 77 | + |
| 78 | + |
| 79 | +if __name__ == "__main__": |
| 80 | + unittest.main() |
0 commit comments