Skip to content

Commit d4ec159

Browse files
authored
Merge pull request #361 from seleniumbase/update-methods-and-mysql
Update methods and mysql
2 parents b93af1c + 3d35556 commit d4ec159

File tree

15 files changed

+201
-73
lines changed

15 files changed

+201
-73
lines changed

.travis.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@ before_install:
1717
install:
1818
- "pip install --upgrade pip"
1919
- "pip install -r requirements.txt --upgrade"
20-
- "pip install mysqlclient==1.4.2"
2120
- "python setup.py develop"
2221
- "sudo rm -f /etc/boto.cfg"
2322
before_script:
2423
- "flake8 seleniumbase/*.py && flake8 seleniumbase/*/*.py && flake8 seleniumbase/*/*/*.py && flake8 seleniumbase/*/*/*/*.py"
25-
# - "wget https://chromedriver.storage.googleapis.com/2.40/chromedriver_linux64.zip && unzip chromedriver_linux64.zip && sudo cp chromedriver /usr/local/bin/ && sudo chmod +x /usr/local/bin/chromedriver"
26-
# - "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"
24+
# - "wget https://chromedriver.storage.googleapis.com/2.44/chromedriver_linux64.zip && unzip chromedriver_linux64.zip && sudo cp chromedriver /usr/local/bin/ && sudo chmod +x /usr/local/bin/chromedriver"
25+
# - "wget https://github.com/mozilla/geckodriver/releases/download/v0.24.0/geckodriver-v0.24.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"
2726
# - "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"
2827
- "seleniumbase"
2928
- "seleniumbase install chromedriver"

README.md

Lines changed: 100 additions & 36 deletions
Large diffs are not rendered by default.

examples/my_first_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class MyTestClass(BaseCase):
66
def test_basic(self):
77
self.open("https://xkcd.com/353/")
88
self.assert_element('img[alt="Python"]')
9+
self.assert_title("xkcd: Python")
910
self.click('a[rel="license"]')
1011
self.assert_text("free to copy and reuse")
1112
self.go_back()

help_docs/customizing_test_runs.md

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,26 @@ pytest test_suite.py --reruns 1 --reruns-delay 2
4343

4444
pytest test_suite.py --server=IP_ADDRESS --port=4444
4545

46+
pytest test_fail.py --pdb -s
47+
4648
pytest proxy_test.py --proxy=IP_ADDRESS:PORT
4749

4850
pytest proxy_test.py --proxy=USERNAME:PASSWORD@IP_ADDRESS:PORT
4951

5052
pytest user_agent_test.py --agent="USER-AGENT STRING"
5153

52-
pytest test_fail.py --pdb -s
54+
pytest my_first_test.py --settings_file=custom_settings.py
5355
```
5456

5557
You can interchange **pytest** with **nosetests**, but using pytest is strongly recommended because developers stopped supporting nosetests. Chrome is the default browser if not specified.
5658

5759
(NOTE: If you're using **pytest** for running tests outside of the SeleniumBase repo, **you'll want a copy of [pytest.ini](https://github.com/seleniumbase/SeleniumBase/blob/master/pytest.ini) at the base of the new folder structure**. If using **nosetests**, the same applies for [setup.cfg](https://github.com/seleniumbase/SeleniumBase/blob/master/setup.cfg).)
5860

61+
An easy way to override seleniumbase/config/settings.py is by using a custom settings file.
62+
Here's the command-line option to add to tests: (See [examples/custom_settings.py](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/custom_settings.py))
63+
``--settings_file=custom_settings.py``
64+
(Settings include default timeout values, a two-factor auth key, DB credentials, S3 credentials, Email Testing API credentials, and other important settings used by tests.)
65+
5966
#### **Running tests on [BrowserStack](https://www.browserstack.com/automate#)'s Selenium Grid, the [Sauce Labs](https://saucelabs.com/products/open-source-frameworks/selenium) Selenium Grid, the [TestingBot](https://testingbot.com/features) Selenium Grid, (or your own):**
6067

6168
Here's how to connect to a BrowserStack Selenium Grid server for running tests:
@@ -156,16 +163,51 @@ nosetests test_suite.py --report
156163

157164
(NOTE: You can add ``--show_report`` to immediately display Nosetest reports after the test suite completes. Only use ``--show_report`` when running tests locally because it pauses the test run.)
158165

159-
Here are some other useful arguments:
166+
Here are some other useful command-line options that come with Pytest:
160167
```bash
161-
-v # Prints the full test name rather than a dot for each test.
168+
-v # Prints the full test name for each test.
169+
-q # Prints fewer details in the console output when running tests.
162170
-x # Stop running the tests after the first failure is reached.
163-
```
164-
165-
Here's a **nosetests**-specific argument:
166-
```bash
167-
--logging-level=INFO # Hide DEBUG messages, which can be overwhelming.
168-
```
171+
--html=report.html # Creates a detailed test report after tests complete. (Using the pytest-html plugin)
172+
--collect-only # Show what tests would get run without actually running them.
173+
-s # See print statements. (Should be on by default with pytest.ini present.)
174+
-n=NUM # Multithread the tests using that many threads. (Speed up test runs!)
175+
```
176+
177+
SeleniumBase provides additional Pytest command-line options for tests:
178+
```bash
179+
--browser=BROWSER # (The web browser to use.)
180+
--cap_file=FILE # (The web browser's desired capabilities to use.)
181+
--settings_file=FILE # (Overrides SeleniumBase settings.py values.)
182+
--env=ENV # (Set a test environment. Use "self.env" to use this in tests.)
183+
--data=DATA # (Extra data to pass to tests. Use "self.data" in tests.)
184+
--user_data_dir=DIR # (Set the Chrome user data directory to use.)
185+
--server=SERVER # (The server / IP address used by the tests.)
186+
--port=PORT # (The port that's used by the test server.)
187+
--proxy=SERVER:PORT # (This is the proxy server:port combo used by tests.)
188+
--agent=STRING # (This designates the web browser's User Agent to use.)
189+
--extension_zip=ZIP # (Load a Chrome Extension .zip file, comma-separated.)
190+
--extension_dir=DIR # (Load a Chrome Extension directory, comma-separated.)
191+
--headless # (The option to run tests headlessly. The default on Linux OS.)
192+
--headed # (The option to run tests with a GUI on Linux OS.)
193+
--start_page=URL # (The starting URL for the web browser when tests begin.)
194+
--log_path=LOG_PATH # (The directory where log files get saved to.)
195+
--archive_logs # (Archive old log files instead of deleting them.)
196+
--demo_mode # (The option to visually see test actions as they occur.)
197+
--demo_sleep=SECONDS # (The option to wait longer after Demo Mode actions.)
198+
--highlights=NUM # (Number of highlight animations for Demo Mode actions.)
199+
--message_duration=SECONDS # (The time length for Messenger alerts.)
200+
--check_js # (The option to check for JavaScript errors after page loads.)
201+
--ad_block # (The option to block some display ads after page loads.)
202+
--verify_delay=SECONDS # (The delay before MasterQA verification checks.)
203+
--disable_csp # (This disables the Content Security Policy of websites.)
204+
--enable_sync # (The option to enable "Chrome Sync".)
205+
--maximize_window # (The option to start with the web browser maximized.)
206+
--save_screenshot # (The option to save a screenshot after each test.)
207+
--visual_baseline # (Set the visual baseline for Visual/Layout tests.)
208+
--timeout_multiplier=MULTIPLIER # (Multiplies the default timeout values.)
209+
```
210+
(For more details, see the full list of command-line options **[here](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/plugins/pytest_plugin.py)**.)
169211

170212
#### **Using a Proxy Server:**
171213

help_docs/method_summary.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ self.assert_equal(first, second, msg=None)
209209

210210
self.assert_not_equal(first, second, msg=None)
211211

212+
self.assert_title(title)
213+
212214
self.assert_no_js_errors()
213215

214216
self.get_google_auth_password(totp_key=None)

help_docs/mysql_installation.md

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,40 @@
55

66
(NOTE: If you're using this test framework from a local development machine and don't plan on writing to a MySQL DB from your local test runs, you can skip this step.)
77

8-
##### macOS:
8+
##### Linux (Ubuntu):
99
```bash
10-
brew install MySQL
10+
sudo apt update
11+
sudo apt install mysql-server
12+
sudo mysql_secure_installation
13+
sudo mysql -e 'CREATE DATABASE IF NOT EXISTS test_db;'
14+
sudo mysql -h 127.0.0.1 -u root test_db < seleniumbase/core/create_db_tables.sql
15+
sudo service mysql restart
1116
```
1217

13-
##### Windows:
14-
[Download MySQL here](http://dev.mysql.com/downloads/windows/)
15-
16-
That installs the MySQL library so that you can use database commands in your code. To make that useful, you'll want to have a MySQL DB that you can connect to.
18+
To change the password:
19+
```bash
20+
mysqladmin -u root -p'OLD_PASSWORD' password NEW_PASSWORD
21+
sudo service mysql restart
22+
```
1723

18-
#### Install the MySQL-Python connector
24+
##### MacOS:
25+
```bash
26+
brew install mysql
27+
```
1928

29+
Then you'll need to start the MySQL service:
2030
```bash
21-
pip install MySQL-python==1.2.5
31+
brew services start mysql
2232
```
2333

34+
Continue with additional steps below to setup your DB.
35+
36+
##### Windows:
37+
[Download MySQL here](http://dev.mysql.com/downloads/windows/)
38+
Follow the steps from the MySQL Downloads page.
39+
40+
Continue with additional steps below to setup your DB.
41+
2442
#### Access your MySQL DB
2543

2644
If you want a visual tool to help make your MySQL life easier, [try MySQL Workbench](http://dev.mysql.com/downloads/workbench/).
@@ -40,15 +58,3 @@ Example:
4058
```bash
4159
pytest my_first_test.py --with-db_reporting
4260
```
43-
44-
#### Windows mysql-python troubleshooting:
45-
46-
If you're having trouble with Windows mysql-python installation using pip, you can also try the following steps to install from an alternative source:
47-
48-
* Download the unofficial ``.whl`` format of MySQL-Python and Mysqlclient from [here](http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python).
49-
50-
* Open a console and then cd to where you've downloaded the MySQL-Python .whl file.
51-
52-
* Run the command ``pip install FILENAME.whl``
53-
54-
* If pip.exe is not recognized, you may find it in the "Scripts" directory from where python has been installed.

integrations/node_js/my_first_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class MyTestClass(BaseCase):
66
def test_basic(self):
77
self.open("https://xkcd.com/353/")
88
self.assert_element('img[alt="Python"]')
9+
self.assert_title("xkcd: Python")
910
self.click('a[rel="license"]')
1011
self.assert_text("free to copy and reuse")
1112
self.go_back()

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ parameterized>=0.7.0
2424
beautifulsoup4>=4.6.0
2525
pyopenssl>=19.0.0
2626
colorama>=0.4.1
27+
pymysql>=0.9.3
2728
pyotp>=2.3.0
2829
boto>=2.49.0
2930
flake8>=3.7.8

seleniumbase/console_scripts/sb_install.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def main():
9191
print('\nLocating the latest version of Chromedriver...')
9292
latest_version = requests.get(last).text
9393
if not requests.get(download_url).ok:
94-
fallback_version = "2.40"
94+
fallback_version = "2.44"
9595
download_url = ("http://chromedriver.storage.googleapis.com/"
9696
"%s/%s" % (fallback_version, file_name))
9797
else:

seleniumbase/console_scripts/sb_mkdir.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def main():
8181
data.append(" def test_basic(self):")
8282
data.append(' self.open("https://xkcd.com/353/")')
8383
data.append(" self.assert_element('img[alt=\"Python\"]')")
84+
data.append(' self.assert_title("xkcd: Python")')
8485
data.append(" self.click('a[rel=\"license\"]')")
8586
data.append(' self.assert_text("free to copy and reuse")')
8687
data.append(' self.go_back()')

0 commit comments

Comments
 (0)