Skip to content

Commit a7bf236

Browse files
authored
Merge pull request #180 from seleniumbase/driver-script-updates
Console script updates and driver updates
2 parents 3ea501a + 9883672 commit a7bf236

16 files changed

+493
-122
lines changed

.gitignore

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Compiled Python Bytecode
12
*.py[cod]
23

34
# Packages
@@ -35,23 +36,34 @@ nosetests.xml
3536
.project
3637
.pydevproject
3738

38-
# Other
39-
selenium-server-standalone.jar
40-
verbose_hub_server.dat
41-
verbose_node_server.dat
42-
ip_of_grid_hub.dat
43-
geckodriver.log
44-
downloaded_files
45-
archived_files
39+
# Web Drivers
40+
chromedriver
41+
geckodriver
42+
MicrosoftWebDriver.exe
43+
chromedriver.exe
44+
geckodriver.exe
45+
46+
# Logs
4647
logs
4748
latest_logs
4849
log_archives
4950
archived_logs
51+
geckodriver.log
52+
53+
# Reports
5054
latest_report
5155
report_archives
5256
archived_reports
5357
html_report.html
5458
report.html
59+
60+
# Other
61+
selenium-server-standalone.jar
62+
verbose_hub_server.dat
63+
verbose_node_server.dat
64+
ip_of_grid_hub.dat
65+
downloaded_files
66+
archived_files
5567
assets
5668
temp
5769
temp*

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ install:
2020
- "sudo rm -f /etc/boto.cfg"
2121
before_script:
2222
- "flake8 seleniumbase/*.py && flake8 seleniumbase/*/*.py && flake8 seleniumbase/*/*/*.py && flake8 seleniumbase/*/*/*/*.py"
23-
- "wget https://chromedriver.storage.googleapis.com/2.37/chromedriver_linux64.zip && unzip chromedriver_linux64.zip && sudo cp chromedriver /usr/local/bin/ && sudo chmod +x /usr/local/bin/chromedriver"
24-
- "wget https://github.com/mozilla/geckodriver/releases/download/v0.20.0/geckodriver-v0.20.0-linux64.tar.gz -O /tmp/geckodriver.tar.gz && tar -C /opt -xzf /tmp/geckodriver.tar.gz && sudo chmod 755 /opt/geckodriver && sudo ln -fs /opt/geckodriver /usr/bin/geckodriver && sudo ln -fs /opt/geckodriver /usr/local/bin/geckodriver"
23+
# - "wget https://chromedriver.storage.googleapis.com/2.41/chromedriver_linux64.zip && unzip chromedriver_linux64.zip && sudo cp chromedriver /usr/local/bin/ && sudo chmod +x /usr/local/bin/chromedriver"
24+
# - "wget https://github.com/mozilla/geckodriver/releases/download/v0.21.0/geckodriver-v0.21.0-linux64.tar.gz -O /tmp/geckodriver.tar.gz && tar -C /opt -xzf /tmp/geckodriver.tar.gz && sudo chmod 755 /opt/geckodriver && sudo ln -fs /opt/geckodriver /usr/bin/geckodriver && sudo ln -fs /opt/geckodriver /usr/local/bin/geckodriver"
2525
# - "wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2 && tar -xvf ./phantomjs-2.1.1-linux-x86_64.tar.bz2 && export PATH=$PWD/phantomjs-2.1.1-linux-x86_64/bin:$PATH"
26+
- "seleniumbase install chromedriver"
27+
- "seleniumbase install geckodriver"
2628
script:
2729
- "pytest examples/my_first_test.py --browser=chrome -s --headless --with-db_reporting"
2830
- "nosetests examples/boilerplates/boilerplate_test.py --browser=chrome --headless"

README.md

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ SeleniumBase was originally built for [testing HubSpot's platform](https://produ
6363

6464
## Get Started:
6565

66-
Before installation, **[install Python](https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/install_python_pip_git.md)** and **[get a WebDriver](https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/webdriver_installation.md)** on your system PATH.
66+
Before installation, **[install Python](https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/install_python_pip_git.md)** and **[install a web driver](https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/webdriver_installation.md)**.
6767

6868

6969
### ![http://seleniumbase.com](https://cdn2.hubspot.net/hubfs/100006/images/super_logo_tiny.png "SeleniumBase") **Step 1:** Clone SeleniumBase
@@ -151,32 +151,23 @@ If the example test is moving too fast for your eyes to see what's going on, you
151151
pytest my_first_test.py --demo_mode
152152
```
153153

154-
You can override the default wait time by either updating [settings.py](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/config/settings.py) or by using ``--demo_sleep={NUM}`` when using Demo Mode. (NOTE: If you use ``--demo_sleep={NUM}`` without using ``--demo_mode``, nothing will happen.)
155-
156-
```bash
157-
pytest my_first_test.py --demo_mode --demo_sleep=1.2
158-
```
159-
160-
You can also use the following in your scripts to slow down the tests:
154+
You can use the following in your scripts to help you debug issues::
161155

162156
```python
163157
import time; time.sleep(5) # sleep for 5 seconds (add this after the line you want to pause on)
164158
import ipdb; ipdb.set_trace() # waits for your command. n = next line of current method, c = continue, s = step / next executed line (will jump)
159+
import pytest; pytest.set_trace() # similar to ipdb, but specific to pytest
165160
```
166161

167-
(NOTE: If you're using pytest instead of nosetests and you want to use ipdb in your script for debugging purposes, you'll need to add ``--capture=no`` (or ``-s``) on the command line, or use ``import pytest; pytest.set_trace()`` instead of using ipdb. More info on that [here](http://stackoverflow.com/questions/2678792/can-i-debug-with-python-debugger-when-using-py-test-somehow).)
168-
169-
You may also want to have your test sleep in other situations where you need to have your test wait for something. If you know what you're waiting for, you should be specific by using a command that waits for something specific to happen.
170-
171-
If you need to debug things on the fly (in case of errors), use this:
162+
**To pause an active test that throws an exception or error, add ``--pdb --pdb-failures -s``:**
172163

173164
```bash
174165
pytest my_first_test.py --browser=chrome --pdb --pdb-failures -s
175166
```
176167

177-
The above code (with --pdb) will leave your browser window open in case there's a failure, which is possible if the web pages from the example change the data that's displayed on the page. (ipdb commands: 'c', 's', 'n' => continue, step, next). You may need the ``-s`` in order to see all console output.
168+
The code above will leave your browser window open in case there's a failure. (ipdb commands: 'c', 's', 'n' => continue, step, next).
178169

179-
Here are some other useful nosetest arguments for appending to your run commands:
170+
Here are some other useful **nosetest**-specific arguments:
180171

181172
```bash
182173
--logging-level=INFO # Hide DEBUG messages, which can be overwhelming.
@@ -185,7 +176,7 @@ Here are some other useful nosetest arguments for appending to your run commands
185176
--with-id # If -v is also used, will number the tests for easy counting.
186177
```
187178

188-
During test failures you'll get detailed log files, which include screenshots, page source, and basic test info, which will get added to the logs folder at ``latest_logs/``. (Unless you have ARCHIVE_EXISTING_LOGS set to True in [settings.py](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/config/settings.py), log files with be cleaned up at the start of the next test run. If the archive feature is enabled, those logs will get saved to the ``archived_logs/`` folder.) The ``my_test_suite.py`` collection contains tests that fail on purpose so that you can see how logging works.
179+
During test failures, logs and screenshots from the most recent test run will get saved to the ``latest_logs/`` folder. Those logs will get moved to ``archived_logs/`` if you have ARCHIVE_EXISTING_LOGS set to True in [settings.py](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/config/settings.py), otherwise log files with be cleaned up at the start of the next test run. The ``my_test_suite.py`` collection contains tests that fail on purpose so that you can see how logging works.
189180

190181
```bash
191182
cd examples/
@@ -210,7 +201,7 @@ To run Pytest multithreaded on multiple CPUs at the same time, add ``-n=NUM`` or
210201
<a id="creating_visual_reports"></a>
211202
### ![http://seleniumbase.com](https://cdn2.hubspot.net/hubfs/100006/images/super_logo_tiny.png "SeleniumBase") **Creating Visual Test Suite Reports:**
212203

213-
(NOTE: The command line args are different for Pytest vs Nosetests)
204+
(NOTE: Several command line args are different for Pytest vs Nosetests)
214205

215206
#### **Pytest Reports:**
216207

console_scripts/ReadMe.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,32 @@
11
## Console Scripts
22

3+
SeleniumBase console scripts help you get things done more easily, such as installing web drivers, creating a test directory with necessary configuration files, converting old Webdriver unittest scripts into SeleniumBase code, and using the Selenium Grid.
4+
5+
For running tests from the command line, [use **pytest** with SeleniumBase](https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/customizing_test_runs.md).
6+
7+
### install
8+
9+
* Usage:
10+
``seleniumbase install [DRIVER_NAME]``
11+
(Drivers: chromedriver, geckodriver, edgedriver)
12+
13+
* Example:
14+
``seleniumbase install chromedriver``
15+
16+
* Output:
17+
Installs the specified webdriver.
18+
(chromedriver is required for Google Chrome automation)
19+
(geckodriver is required for Mozilla Firefox automation)
20+
(edgedriver is required for Microsoft Edge automation)
21+
322
### mkdir
423

524
* Usage:
625
``seleniumbase mkdir [DIRECTORY_NAME]``
726

27+
* Example:
28+
``seleniumbase mkdir gui_tests``
29+
830
* Output:
931
Creates a new folder for running SeleniumBase scripts.
1032
The new folder contains default config files,
@@ -15,7 +37,7 @@ test frameworks.
1537
### convert
1638

1739
* Usage:
18-
``seleniumbase convert [MY_TEST.py]``
40+
``seleniumbase convert [PYTHON_WEBDRIVER_UNITTEST_FILE]``
1941

2042
* Output:
2143
Converts a Selenium IDE exported WebDriver unittest

console_scripts/run.py

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55
seleniumbase [COMMAND] [PARAMETERS]
66
77
Examples:
8-
seleniumbase mkdir [DIRECTORY_NAME]
9-
seleniumbase convert [PYTHON_WEBDRIVER_UNITTEST_FILE]
8+
seleniumbase install chromedriver
9+
seleniumbase mkdir gui_tests
10+
seleniumbase convert my_old_webdriver_unittest.py
1011
seleniumbase grid-hub start
1112
seleniumbase grid-node start --hub=127.0.0.1
1213
"""
1314

1415
import sys
1516
from console_scripts import sb_mkdir
17+
from console_scripts import sb_install
1618
from integrations.selenium_grid import grid_hub
1719
from integrations.selenium_grid import grid_node
1820
from integrations.selenium_ide import convert_ide
@@ -32,18 +34,37 @@ def show_basic_usage():
3234
print("")
3335
print("Commands:")
3436
print("")
37+
print(" install [DRIVER_NAME]")
3538
print(" mkdir [NEW_TEST_DIRECTORY_NAME]")
3639
print(" convert [PYTHON_WEBDRIVER_UNITTEST_FILE]")
3740
print(" grid-hub {start|stop|restart} [OPTIONS]")
3841
print(" grid-node {start|stop|restart} --hub=[HUB_IP] [OPTIONS]")
3942
print("")
4043

4144

45+
def show_install_usage():
46+
print(" ** install **")
47+
print("")
48+
print(" Usage:")
49+
print(" seleniumbase install [DRIVER_NAME]")
50+
print(" (Drivers: chromedriver, geckodriver, edgedriver)")
51+
print(" Example:")
52+
print(" seleniumbase install chromedriver")
53+
print(" Output:")
54+
print(" Installs the specified webdriver.")
55+
print(" (chromedriver is required for Chrome automation)")
56+
print(" (geckodriver is required for Firefox automation)")
57+
print(" (edgedriver is required for MS Edge automation)")
58+
print("")
59+
60+
4261
def show_mkdir_usage():
4362
print(" ** mkdir **")
4463
print("")
4564
print(" Usage:")
4665
print(" seleniumbase mkdir [DIRECTORY_NAME]")
66+
print(" Example:")
67+
print(" seleniumbase mkdir gui_tests")
4768
print(" Output:")
4869
print(" Creates a new folder for running SeleniumBase scripts.")
4970
print(" The new folder contains default config files,")
@@ -105,6 +126,7 @@ def show_detailed_help():
105126
show_basic_usage()
106127
print("More Info:")
107128
print("")
129+
show_install_usage()
108130
show_mkdir_usage()
109131
show_convert_usage()
110132
show_grid_hub_usage()
@@ -123,14 +145,20 @@ def main():
123145
command = sys.argv[1]
124146
command_args = sys.argv[2:]
125147

126-
if command == "convert":
148+
if command == "install":
149+
if len(command_args) >= 1:
150+
sb_install.main()
151+
else:
152+
show_basic_usage()
153+
show_install_usage()
154+
elif command == "convert":
127155
if len(command_args) == 1:
128156
convert_ide.main()
129157
else:
130158
show_basic_usage()
131159
show_convert_usage()
132160
elif command == "mkdir":
133-
if len(command_args) == 1:
161+
if len(command_args) >= 1:
134162
sb_mkdir.main()
135163
else:
136164
show_basic_usage()
@@ -149,7 +177,11 @@ def main():
149177
show_grid_node_usage()
150178
elif command == "help" or command == "--help":
151179
if len(command_args) >= 1:
152-
if command_args[0] == "mkdir":
180+
if command_args[0] == "install":
181+
print("")
182+
show_install_usage()
183+
return
184+
elif command_args[0] == "mkdir":
153185
print("")
154186
show_mkdir_usage()
155187
return

0 commit comments

Comments
 (0)