-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathscroll.py
80 lines (62 loc) · 1.79 KB
/
scroll.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
import os
import unittest
import sys
from selenium import webdriver
username = os.environ.get("LT_USERNAME")
access_key = os.environ.get("LT_ACCESS_KEY")
class FirstSampleTest(unittest.TestCase):
# setUp runs before each test case
def setUp(self):
desired_caps = {
'LT:Options': {
"user": username,
"accessKey": access_key,
"build": "UnitTest-Selenium-Sample",
"name": "UnitTest-Selenium-Test",
"platformName": "Windows 11",
"selenium_version": "4.0.0"
},
"browserName": "Chrome",
"browserVersion": "latest",
}
self.driver = webdriver.Remote(
command_executor="http://hub.lambdatest.com:80/wd/hub",
desired_capabilities=desired_caps)
# tearDown runs after each test case
def tearDown(self):
self.driver.quit()
def scroll_bottom():
"""
Verify scrolling to bottom
:return: None
"""
driver.get('https://www.lambdatest.com/')
driver.maximize_window()
sleep(2)
success = driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
sleep(5)
assert success == True
def scroll_infinite():
"""
Verify infinite scroll
:return: None
"""
SCROLL_PAUSE_TIME = 0.5
# Get scroll height
last_height = driver.execute_script("return document.body.scrollHeight")
#controls how many times scrolled to bottom
scroll_pass = 0
#change to True for infinite scroll
while scroll_pass < 10:
# Scroll down to bottom
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
# Wait to load page
time.sleep(SCROLL_PAUSE_TIME)
# Calculate new scroll height and compare with last scroll height
new_height = driver.execute_script("return document.body.scrollHeight")
if new_height == last_height:
break
last_height = new_height
scroll_pass+=1
if __name__ == "__main__":
unittest.main()