Skip to content

Commit 7442fa6

Browse files
authored
Merge pull request #496 from seleniumbase/add-additional-scroll-methods
Add additional scroll methods
2 parents ca7b6c8 + 8033607 commit 7442fa6

File tree

6 files changed

+64
-4
lines changed

6 files changed

+64
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[<img src="https://cdn2.hubspot.net/hubfs/100006/fancy_logo_8.png" title="SeleniumBase" align="center" height="38">](https://github.com/seleniumbase/SeleniumBase/blob/master/README.md)<br />
1+
[<img src="https://cdn2.hubspot.net/hubfs/100006/fancy_logo_9.png" title="SeleniumBase" align="center" height="38">](https://github.com/seleniumbase/SeleniumBase/blob/master/README.md)<br />
22

33
[<img src="https://img.shields.io/github/release/seleniumbase/SeleniumBase.svg?color=2277EE" alt="SeleniumBase" />](https://github.com/seleniumbase/SeleniumBase/releases) [<img src="https://img.shields.io/pypi/v/seleniumbase.svg?color=22AAEE" alt=" " />](https://pypi.python.org/pypi/seleniumbase) [<img src="https://badges.gitter.im/seleniumbase/SeleniumBase.svg" alt=" " />](https://gitter.im/seleniumbase/SeleniumBase) [<img src="https://img.shields.io/travis/seleniumbase/SeleniumBase/master.svg" alt=" " />](https://travis-ci.org/seleniumbase/SeleniumBase) [<img src="https://github.com/seleniumbase/SeleniumBase/workflows/CI%20build/badge.svg">](https://github.com/seleniumbase/SeleniumBase/actions)<br />
44

help_docs/method_summary.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ self.scroll_to(selector, by=By.CSS_SELECTOR)
172172

173173
self.slow_scroll_to(selector, by=By.CSS_SELECTOR)
174174

175+
self.scroll_to_top()
176+
177+
self.scroll_to_bottom()
178+
175179
self.click_xpath(xpath)
176180

177181
self.js_click(selector, by=By.CSS_SELECTOR, all_matches=False)

help_docs/mobile_testing.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[<img src="https://cdn2.hubspot.net/hubfs/100006/images/SeleniumBaseText_F.png" title="SeleniumBase" align="center" height="40">](https://github.com/seleniumbase/SeleniumBase/blob/master/README.md)
2+
## <img src="https://cdn2.hubspot.net/hubfs/100006/images/super_square_logo_3a.png" title="SeleniumBase" height="32"> Mobile Testing
3+
4+
Use ``--mobile`` to run your SeleniumBase tests using Chrome's (or Edge's) mobile device emulator with default values for device metrics (CSS Width, CSS Height, Pixel-Ratio) and user agent.
5+
6+
To configure the mobile device metrics, use ``--metrics="CSS_Width,CSS_Height,Pixel_Ratio"``. To configure the user agent, use ``--agent="USER-AGENT-STRING"``.
7+
8+
To find real values for device metrics, [see this GitHub Gist](https://gist.github.com/sidferreira/3f5fad525e99b395d8bd882ee0fd9d00). For a list of available user agent strings, [check out this page](https://developers.whatismybrowser.com/useragents/explore/).
9+
10+
--------
11+
12+
Here's an example of running a mobile test (See https://github.com/seleniumbase/SeleniumBase/blob/master/examples/test_skype_site.py):
13+
14+
```bash
15+
pytest test_skype_site.py --mobile --browser=edge
16+
```
17+
[<img src="https://cdn2.hubspot.net/hubfs/100006/images/skype_mobile_test_2.gif" title="SeleniumBase Mobile Testing">](https://cdn2.hubspot.net/hubfs/100006/images/skype_mobile_test_2.gif)
18+
19+
20+
--------
21+
22+
Here's another example of running a mobile test (https://github.com/seleniumbase/SeleniumBase/blob/master/examples/test_swag_labs.py), which demonstrates using ``--metrics`` and ``--agent`` with ``--mobile``.:
23+
24+
```bash
25+
# Run tests using Chrome's mobile device emulator (default settings)
26+
pytest test_swag_labs.py --mobile
27+
28+
# Run mobile tests specifying CSS Width, CSS Height, and Pixel-Ratio
29+
pytest test_swag_labs.py --mobile --metrics="411,731,3"
30+
31+
# Run mobile tests specifying the user agent
32+
pytest test_swag_labs.py --mobile --agent="Mozilla/5.0 (Linux; Android 9; Pixel 3 XL)"
33+
```
34+
[<img src="https://cdn2.hubspot.net/hubfs/100006/images/swag_labs_gif.gif" title="SeleniumBase Mobile Testing">](https://cdn2.hubspot.net/hubfs/100006/images/swag_labs_gif.gif)
35+
36+
--------
37+
38+
If you're new to SeleniumBase, read https://github.com/seleniumbase/SeleniumBase to help you get started.

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pymysql==0.9.3
3939
pyotp==2.3.0
4040
boto==2.49.0
4141
cffi>=1.13.2
42-
tqdm>=4.42.0
42+
tqdm>=4.42.1
4343
flake8==3.7.9
4444
certifi>=2019.11.28
4545
pdfminer.six==20191110;python_version<"3.5"

seleniumbase/fixtures/base_case.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,6 +1826,24 @@ def slow_scroll_to(self, selector, by=By.CSS_SELECTOR, timeout=None):
18261826
selector, by=by, timeout=timeout)
18271827
self.__slow_scroll_to_element(element)
18281828

1829+
def scroll_to_top(self):
1830+
scroll_script = "window.scrollTo(0, 0);"
1831+
try:
1832+
self.execute_script(scroll_script)
1833+
time.sleep(0.012)
1834+
return True
1835+
except Exception:
1836+
return False
1837+
1838+
def scroll_to_bottom(self):
1839+
scroll_script = "window.scrollTo(0, 10000);"
1840+
try:
1841+
self.execute_script(scroll_script)
1842+
time.sleep(0.012)
1843+
return True
1844+
except Exception:
1845+
return False
1846+
18291847
def click_xpath(self, xpath):
18301848
# Technically self.click() will automatically detect an xpath selector,
18311849
# so self.click_xpath() is just a longer name for the same action.

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
setup(
4747
name='seleniumbase',
48-
version='1.35.1',
48+
version='1.35.2',
4949
description='Fast, Easy, and Reliable Browser Automation & Testing.',
5050
long_description=long_description,
5151
long_description_content_type='text/markdown',
@@ -121,7 +121,7 @@
121121
'pyotp==2.3.0',
122122
'boto==2.49.0',
123123
'cffi>=1.13.2',
124-
'tqdm>=4.42.0',
124+
'tqdm>=4.42.1',
125125
'flake8==3.7.9',
126126
'certifi>=2019.11.28',
127127
'pdfminer.six==20191110;python_version<"3.5"',

0 commit comments

Comments
 (0)