Skip to content

Commit d7011a2

Browse files
authored
Merge pull request #415 from seleniumbase/update-methods
Update methods
2 parents 8dc34a1 + 6cd44d6 commit d7011a2

File tree

8 files changed

+60
-13
lines changed

8 files changed

+60
-13
lines changed

help_docs/how_it_works.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
[<img src="https://cdn2.hubspot.net/hubfs/100006/images/super_logo_sb4.png" title="SeleniumBase" height="48">](https://github.com/seleniumbase/SeleniumBase/blob/master/README.md)
2+
13
<a id="how_seleniumbase_works"></a>
2-
### <img src="https://cdn2.hubspot.net/hubfs/100006/images/super_square_logo_3a.png" title="SeleniumBase" height="32"> **How SeleniumBase Works:**
4+
## <img src="https://cdn2.hubspot.net/hubfs/100006/images/super_square_logo_3a.png" title="SeleniumBase" height="32"> **How it works:**
35

4-
At the core, SeleniumBase works by extending [Pytest](https://docs.pytest.org/en/latest/) and [Nosetests](http://nose.readthedocs.io/en/latest/) as a direct plugin to each one. SeleniumBase automatically spins up web browsers for tests, and then gives those tests access to the SeleniumBase libraries through the BaseCase class, [found here](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/fixtures/base_case.py). Now you can use "``--browser=chrome``" to specify the web browser to use (Default = "Chrome"). You can also include additional plugins for additional features such as "``--demo_mode``" (for highlighting elements & changing the speed of test runs) and "``--proxy=IP_ADDRESS:PORT``" (for using a proxy server during test runs). There are also other plugins available such as "``--with-db_reporting``", "``--with-s3_logging``", and more.
6+
At the core, SeleniumBase works by extending [pytest](https://docs.pytest.org/en/latest/) and [nosetests](http://nose.readthedocs.io/en/latest/) as a direct plugin to each one. SeleniumBase automatically spins up web browsers for tests, and then gives those tests access to the SeleniumBase libraries through the [BaseCase class](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/fixtures/base_case.py). Tests are also given access to SeleniumBase [command-line arguments](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/plugins/pytest_plugin.py), which provide additional functionality.
57

6-
(NOTE: Pytest and Nosetests work by automatically running any Python method that starts with "``test``" from the file that you specified on the command line. You can also run all tests from a specific class in a file, or even pick out an individual test to run.)
8+
(NOTE: pytest and nosetests use a feature called test discovery to automatically find and run Python methods that start with "``test_``" from the file that you specified on the command line.)
79

810
To use SeleniumBase calls you need the following:
911
```python

help_docs/install.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
## ![http://seleniumbase.com](https://cdn2.hubspot.net/hubfs/100006/images/super_logo_tiny.png "SeleniumBase") SeleniumBase Installation
1+
[<img src="https://cdn2.hubspot.net/hubfs/100006/images/super_logo_sb4.png" title="SeleniumBase" height="48">](https://github.com/seleniumbase/SeleniumBase/blob/master/README.md)
2+
3+
## <img src="https://cdn2.hubspot.net/hubfs/100006/images/super_square_logo_3a.png" title="SeleniumBase" height="32"> Installation
24

35
If you're installing SeleniumBase from a cloned copy on your machine, use:
46
```

help_docs/method_summary.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ self.switch_to_default_driver()
157157

158158
self.save_screenshot(name, folder=None)
159159

160+
self.save_page_source(name, folder=None)
161+
160162
self.wait_for_ready_state_complete(timeout=None)
161163

162164
self.wait_for_angularjs(timeout=None)

help_docs/webdriver_installation.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
## Installing Google Chromedriver, Firefox Geckodriver, Microsoft Edge Driver, etc.
1+
[<img src="https://cdn2.hubspot.net/hubfs/100006/images/super_logo_sb4.png" title="SeleniumBase" height="48">](https://github.com/seleniumbase/SeleniumBase/blob/master/README.md)
22

3+
## <img src="https://cdn2.hubspot.net/hubfs/100006/images/super_square_logo_3a.png" title="SeleniumBase" height="32"> Installing webdrivers
34

4-
To run web automation, you'll need to download a web driver for each browser you plan on using and place those on your System **[PATH](http://java.com/en/download/help/path.xml)**. Additionaly, you can place drivers in the [SeleniumBase `drivers` folder](https://github.com/seleniumbase/SeleniumBase/blob/master/drivers). If you plan on taking the latter option, here are some commands that'll automatically download the driver you need into the ``drivers`` folder once you've installed SeleniumBase:
5+
To run web automation, you'll need to download webdrivers for each browser you plan on using, and then place those on your System **[PATH](http://java.com/en/download/help/path.xml)**. Additionaly, you can place drivers in the [SeleniumBase `drivers` folder](https://github.com/seleniumbase/SeleniumBase/blob/master/drivers). If you plan on taking the latter option, here are some commands that'll automatically download the driver you need into the ``drivers`` folder once you've installed SeleniumBase:
56

67
```bash
78
seleniumbase install chromedriver
@@ -10,6 +11,10 @@ seleniumbase install edgedriver
1011
seleniumbase install iedriver
1112
seleniumbase install operadriver
1213
```
14+
* If you have the latest version of Chrome installed, get the latest chromedriver (<i>otherwise it defaults to chromedriver 2.44 for compatibility reasons</i>):
15+
```bash
16+
seleniumbase install chromedriver latest
17+
```
1318

1419
If you plan on using the [Selenium Grid integration](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/utilities/selenium_grid/ReadMe.md) (which allows for remote webdriver), you'll need to put the drivers on your System PATH. On macOS and Linux, ``/usr/local/bin`` is a good PATH spot. On Windows, you may need to set the System PATH under Environment Variables to include the location where you placed the driver files. As a shortcut, you could place the driver files into your Python ``Scripts/`` folder in the location where you have Python installed, which should already be on your System PATH.
1520

@@ -37,7 +42,7 @@ brew cask install chromedriver
3742
brew install geckodriver
3843
```
3944

40-
(NOTE: If your existing version of chromedriver is less than 2.40, **upgrading is required** in order to keep up with the latest version of Chrome!)
45+
(NOTE: If your existing version of chromedriver is less than 2.44, **upgrading is required** in order to keep up with the latest version of Chrome!)
4146

4247
```bash
4348
brew cask upgrade chromedriver
@@ -50,15 +55,15 @@ brew upgrade geckodriver
5055
If you still need the web drivers, here are some scripts to help you install chromedriver and geckodriver on a Linux machine:
5156

5257
```bash
53-
wget http://chromedriver.storage.googleapis.com/2.40/chromedriver_linux64.zip
58+
wget http://chromedriver.storage.googleapis.com/2.44/chromedriver_linux64.zip
5459
unzip chromedriver_linux64.zip
5560
mv chromedriver /usr/local/bin/
5661
chmod +x /usr/local/bin/chromedriver
5762
```
5863

5964
```bash
60-
wget https://github.com/mozilla/geckodriver/releases/download/v0.21.0/geckodriver-v0.21.0-linux64.tar.gz
61-
tar xvfz geckodriver-v0.21.0-linux64.tar.gz
65+
wget https://github.com/mozilla/geckodriver/releases/download/v0.26.0/geckodriver-v0.26.0-linux64.tar.gz
66+
tar xvfz geckodriver-v0.26.0-linux64.tar.gz
6267
mv geckodriver /usr/local/bin/
6368
chmod +x /usr/local/bin/geckodriver
6469
```

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ pymysql>=0.9.3
3434
pyotp>=2.3.0
3535
boto>=2.49.0
3636
cffi>=1.13.2
37-
tqdm>=4.37.0
37+
tqdm>=4.38.0
3838
flake8>=3.7.9
3939
certifi>=2019.9.11

seleniumbase/fixtures/base_case.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,6 +1468,15 @@ def save_screenshot(self, name, folder=None):
14681468
""" The screenshot will be in PNG format. """
14691469
return page_actions.save_screenshot(self.driver, name, folder)
14701470

1471+
def save_page_source(self, name, folder=None):
1472+
""" Saves the page HTML to the current directory (or given subfolder).
1473+
If the folder specified doesn't exist, it will get created.
1474+
@Params
1475+
name - The file name to save the current page's HTML to.
1476+
folder - The folder to save the file to. (Default = current folder)
1477+
"""
1478+
return page_actions.save_page_source(self.driver, name, folder)
1479+
14711480
def wait_for_ready_state_complete(self, timeout=None):
14721481
try:
14731482
# If there's an alert, skip

seleniumbase/fixtures/page_actions.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from selenium.webdriver.remote.errorhandler import NoSuchFrameException
3333
from selenium.webdriver.remote.errorhandler import NoSuchWindowException
3434
from seleniumbase.config import settings
35+
from seleniumbase.core import log_helper
3536

3637

3738
def is_element_present(driver, selector, by=By.CSS_SELECTOR):
@@ -488,6 +489,32 @@ def save_screenshot(driver, name, folder=None):
488489
pass
489490

490491

492+
def save_page_source(driver, name, folder=None):
493+
"""
494+
Saves the page HTML to the current directory (or given subfolder).
495+
If the folder specified doesn't exist, it will get created.
496+
@Params
497+
name - The file name to save the current page's HTML to.
498+
folder - The folder to save the file to. (Default = current folder)
499+
"""
500+
if "." not in name:
501+
name = name + ".html"
502+
if folder:
503+
abs_path = os.path.abspath('.')
504+
file_path = abs_path + "/%s" % folder
505+
if not os.path.exists(file_path):
506+
os.makedirs(file_path)
507+
html_file_path = "%s/%s" % (file_path, name)
508+
else:
509+
html_file_path = name
510+
page_source = driver.page_source
511+
html_file = codecs.open(html_file_path, "w+", "utf-8")
512+
rendered_source = log_helper.get_html_source_with_base_href(
513+
driver, page_source)
514+
html_file.write(rendered_source)
515+
html_file.close()
516+
517+
491518
def _get_last_page(driver):
492519
try:
493520
last_page = driver.current_url

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.32.22',
48+
version='1.32.23',
4949
description='Fast, Easy, and Reliable Browser Automation & Testing.',
5050
long_description=long_description,
5151
long_description_content_type='text/markdown',
@@ -117,7 +117,7 @@
117117
'pyotp>=2.3.0',
118118
'boto>=2.49.0',
119119
'cffi>=1.13.2',
120-
'tqdm>=4.37.0',
120+
'tqdm>=4.38.0',
121121
'flake8>=3.7.9',
122122
'certifi>=2019.9.11',
123123
],

0 commit comments

Comments
 (0)