Merge pull request #134 from seleniumbase/updates

Updates - Adding more env options and adding boilerplates.
This commit is contained in:
Michael Mintz 2018-02-01 17:49:58 -05:00 committed by GitHub
commit 927cdf8410
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 169 additions and 23 deletions

View File

@ -112,8 +112,6 @@ pytest my_first_test.py --with-selenium --browser=chrome --demo_mode
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.)
If you ever make any changes to your local copy of ``settings.py``, you may need to run ``python setup.py develop`` for those changes to take effect.
```bash
nosetests my_first_test.py --with-selenium --browser=chrome --demo_mode --demo_sleep=1.2
```
@ -158,6 +156,8 @@ pytest my_first_test.py --with-testing_base --browser=chrome
(NOTE: If you're using **pytest** instead of nosetests for running tests outside of the SeleniumBase repo, **you'll need a copy of [pytest.ini](https://github.com/seleniumbase/SeleniumBase/blob/master/pytest.ini) at the base of the new folder structure, already provided here.**
If you want to pass additional data from the command line to your tests, you can use ``--data=STRING``. Now inside your tests, you can use ``self.data`` to access that.
<a id="creating_visual_reports"></a>
### ![http://seleniumbase.com](https://cdn2.hubspot.net/hubfs/100006/images/super_logo_tiny.png "SeleniumBase") **Creating Visual Test Suite Reports:**
@ -349,10 +349,10 @@ self.click('a[name*="partial_name"]')
#### Asserting visibility of text inside an element on a page within some number of seconds:
```python
self.wait_for_text_visible("Make it so!", "div#trek div.picard div.quotes", timeout=3)
self.wait_for_text_visible("Tea. Earl Grey. Hot.", "div#trek div.picard div.quotes", timeout=1)
self.assert_text("Make it so!", "div#trek div.picard div.quotes")
self.assert_text("Tea. Earl Grey. Hot.", "div#trek div.picard div.quotes", timeout=3)
```
(NOTE: The short versions of this are ``self.find_text(TEXT, ELEMENT)`` and ``self.assert_text(TEXT, ELEMENT)``)
(NOTE: ``self.find_text(TEXT, ELEMENT)`` and ``self.wait_for_text(TEXT, ELEMENT)`` also do this. For backwords compatibility, older method names were kept, but the default timeout may be different.)
#### Asserting Anything

View File

@ -1,6 +1,6 @@
## Running SeleniumBase Scripts
(NOTE: If you didn't install SeleniumBase properly, these scripts won't work. Installation steps include "``pip install seleniumbase``" and/or "``python setup.py install``" from the top-level directory.)
(NOTE: If you didn't install SeleniumBase properly, these scripts won't work. Installation steps include "``pip install seleniumbase``" and/or "``python setup.py develop``" from the top-level directory.)
To makes things easier, here's a simple GUI program that allows you to kick off a few example scripts by pressing a button:
@ -14,7 +14,7 @@ python gui_test_runner.py
![](http://cdn2.hubspot.net/hubfs/100006/images/GUI_Test_Runner_5.png "GUI Test Runner")
If you run scripts with logging enabled, (using ``--with-testing_base``), youll see two folders appear: “latest_logs” and “archived_logs”. The “latest_logs” folder will contain log files from the most recent test run, but logs will only be created if the test run is failing. Afterwards, logs from the “latest_logs” folder will get pushed to the “archived_logs” folder if you have have the ``ARCHIVE_EXISTING_LOGS`` feature enabled in [settings.py](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/config/settings.py). Make sure to run ``python setup.py install`` for your changes to take effect if you make any changes to that file.
If you run scripts with logging enabled, (using ``--with-testing_base``), youll see two folders appear: “latest_logs” and “archived_logs”. The “latest_logs” folder will contain log files from the most recent test run, but logs will only be created if the test run is failing. Afterwards, logs from the “latest_logs” folder will get pushed to the “archived_logs” folder if you have have the ``ARCHIVE_EXISTING_LOGS`` feature enabled in [settings.py](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/config/settings.py).
**For running scripts the usual way, here are some of the example run commands:**

View File

View File

View File

@ -0,0 +1,56 @@
from seleniumbase import BaseCase
class ParseTestCase(BaseCase):
def setUp(self):
super(ParseTestCase, self).setUp()
def get_login_credentials(self, user_type):
# Example of parsing data from a file
f = open('qa_login_example.txt', "r")
file_data = f.read()
file_lines = file_data.split('\n')
for line in file_lines:
line_items = line.split(',')
if line_items[0] == user_type:
return line_items[1], line_items[2]
f.close()
def get_all_login_credentials(self):
# Example of parsing data from a file (Method 2)
keys = {}
f = open("staging_login_example.txt")
file_data = f.read()
file_lines = file_data.split('\n')
for line in file_lines:
line_items = line.split(',')
if line_items[0] == 'admin':
keys['admin'] = (
{'username': line_items[1], 'password': line_items[2]})
if line_items[0] == 'employee':
keys['employee'] = (
{'username': line_items[1], 'password': line_items[2]})
if line_items[0] == 'customer':
keys['customer'] = (
{'username': line_items[1], 'password': line_items[2]})
f.close()
return keys
class ParseTests(ParseTestCase):
def test_get_login_credentials(self):
print("\nExample 1 of getting login info from parsing a config file:")
print("")
username, password = self.get_login_credentials("admin")
print("Getting Admin User login data:")
print("Username: %s" % username)
print("Password: %s" % password)
print("\nExample 2 of getting login info from parsing a config file:")
print("")
keys = self.get_all_login_credentials()
print("Getting Customer login data:")
print("Username: %s" % keys["customer"]["username"])
print("Password: %s" % keys["customer"]["password"])

View File

@ -0,0 +1,3 @@
admin,admin_username_qa,admin_password_qa
employee,employee_username_qa,employee_password_qa
customer,customer_username_qa,customer_password_qa

View File

@ -0,0 +1,3 @@
admin,admin_username_staging,admin_password_staging
employee,employee_username_staging,employee_password_staging
customer,customer_username_staging,customer_password_staging

View File

@ -0,0 +1,29 @@
'''
You can use this as a boilerplate for your test framework.
Define your customized library methods here.
Then have all your test classes inherit it.
The master class will inherit SeleniumBase methods from BaseCase.
'''
from seleniumbase import BaseCase
class MasterTestCase(BaseCase):
def setUp(self):
super(MasterTestCase, self).setUp()
def example_method(self):
pass
'''
# Now you can do something like this in your test files:
from master_class import MasterTestCase
class MyTests(MasterTestCase):
def test_example(self):
self.example_method()
'''

View File

View File

@ -0,0 +1,42 @@
'''
Example of using the Page Object Model (POM) for tests, using page selectors.
Helps make your code more Readable, Maintainable, and Reusable.
Import a file like this in your test files.
'''
class HomePage(object):
ok_button = "#ok"
cancel_button = "#cancel"
see_items = "button.items"
class ShoppingPage(object):
buyable_item = 'img[alt="Item"]'
add_to_cart = "button.add"
go_to_checkout = "#checkout"
class CheckoutPage(object):
remove_from_cart = "button.remove"
pay_now = "#pay-now"
shop_more = "#shop-more"
'''
# Now you can do something like this in your test files:
from master_class import MasterTestCase
from pom_lib.page_selectors import HomePage, ShoppingPage, CheckoutPage
class MyTests(MasterTestCase):
def test_example(self):
self.open(RANDOM_SHOPPING_WEBSITE)
self.click(HomePage.see_items)
self.click(ShoppingPage.buyable_item)
self.click(ShoppingPage.add_to_cart)
self.click(CheckoutPage.pay_now)
self.assert_element("#success")
self.assert_text("Order Received!", "#h2")
'''

View File

@ -76,7 +76,7 @@ sudo pip install -r server_requirements.txt --upgrade
#### Step 12. Install SeleniumBase (Make sure you already installed the requirements above)
```bash
sudo python server_setup.py install
sudo python server_setup.py develop
```
#### Step 13. Run an [example test](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/my_first_test.py) in Chrome to verify installation (Takes ~10 seconds)
@ -146,7 +146,7 @@ If you have a web application that you want to test, you'll be able to create Se
* Give the instance a zone
* Click "Create"
#### Step 22. Get the Connection credentials for your new MySQL DB
#### Step 22. Get the Connection credentials for your new MySQL Instance
* Under the Google Cloud Platform menu, go to "Compute Engine"
* Find your new MySQL instance and then write down the value written in the "External IP" section.
@ -154,23 +154,23 @@ If you have a web application that you want to test, you'll be able to create Se
* Find your new MySQL instance and then click on it.
* Write down the values for Admin username and password. (Username should be "root")
#### Step 23. Get a MySQL GUI tool so that you can connect to your MySQL DB
#### Step 23. Get a MySQL GUI tool so that you can connect to your MySQL Instance
* You can download [MySQL Workbench](http://dev.mysql.com/downloads/tools/workbench/) for this.
#### Step 24. Create a new connection to your MySQL DB
#### Step 24. Create a new connection to your MySQL Instance
* Use the MySQL DB credentials that you saved in Step 21 for this.
#### Step 25. Create a new schema in your MySQL DB
#### Step 25. Create a new database/schema in your MySQL Instance
* You can name your schema ``test``.
* You can name your database/schema ``test_db``.
#### Step 26. Create the necessary tables in your MySQL schema
#### Step 26. Create the necessary tables in your MySQL database/schema
* Run a SQL script in your MySQL schema using [testcaserepository.sql](https://raw.githubusercontent.com/seleniumbase/SeleniumBase/master/seleniumbase/core/testcaserepository.sql)
* Run a SQL script in your MySQL database/schema using [testcaserepository.sql](https://raw.githubusercontent.com/seleniumbase/SeleniumBase/master/seleniumbase/core/testcaserepository.sql)
#### Step 27. Have your local clone of SeleniumBase connect to your MySQL DB
#### Step 27. Have your local clone of SeleniumBase connect to your MySQL Instance
* Update the MySQL connection details in your [settings.py](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/config/settings.py) file to use the credentials that you saved in Step 21.
* Run the following command again from the top-level SeleniumBase folder to make sure that SeleniumBase uses the updated credentials:
@ -179,7 +179,7 @@ If you have a web application that you want to test, you'll be able to create Se
sudo python setup.py install
```
#### Step 28. Have your SeleniumBase Jenkins jobs use your MySQL DB
#### Step 28. Have your SeleniumBase Jenkins jobs use your MySQL Instance
* For the "Execute shell", use the following as your updated "Command":
@ -192,6 +192,6 @@ nosetests examples/my_test_suite.py --with-selenium --headless --browser=chrome
#### Step 29. Run your new Jenkins job
* Click on "Build Now"
* If all goes well, you should be seeing new rows appear in your MySQL DB.
* If all goes well, you should be seeing new rows appear in your MySQL DB tables.
#### Step 30. Congratulations! If you made it this far, you're awesome!

View File

@ -101,7 +101,7 @@ MASTERQA_MAX_IDLE_TIME_BEFORE_QUIT = 600
DB_HOST = "127.0.0.1"
DB_USERNAME = "root"
DB_PASSWORD = "test"
DB_SCHEMA = "test"
DB_SCHEMA = "test_db"
# Amazon S3 Bucket Credentials

View File

@ -37,7 +37,8 @@ class DBReporting(Plugin):
super(DBReporting, self).options(parser, env=env)
parser.add_option('--database_environment', action='store',
dest='database_env',
choices=('prod', 'qa', 'test'),
choices=('prod', 'qa', 'staging',
'test', 'local', 'master'),
default='test',
help=SUPPRESS_HELP)

View File

@ -23,6 +23,17 @@ def pytest_addoption(parser):
dest='with_selenium',
default=False,
help="Use if tests need to be run with a web browser.")
parser.addoption('--env', action='store',
dest='environment',
choices=(
constants.Environment.QA,
constants.Environment.STAGING,
constants.Environment.PRODUCTION,
constants.Environment.MASTER,
constants.Environment.LOCAL,
constants.Environment.TEST),
default=constants.Environment.TEST,
help="The environment to run the tests in.")
parser.addoption('--data', dest='data',
default=None,
help='Extra data to pass from the command line.')
@ -39,7 +50,8 @@ def pytest_addoption(parser):
help="Use to record test data in the MySQL database.")
parser.addoption('--database_env', action='store',
dest='database_env',
choices=('prod', 'qa', 'test'),
choices=(
'prod', 'qa', 'staging', 'test', 'local', 'master'),
default='test',
help=optparse.SUPPRESS_HELP)
parser.addoption('--with-s3_logging', action="store_true",

View File

@ -8,7 +8,7 @@ from setuptools import setup, find_packages # noqa
setup(
name='seleniumbase',
version='1.4.15',
version='1.4.16',
description='Web Automation & Testing Framework - http://seleniumbase.com',
long_description='Web Automation and Testing Framework - seleniumbase.com',
platforms='Mac * Windows * Linux * Docker',

View File

@ -8,7 +8,7 @@ from setuptools import setup, find_packages # noqa
setup(
name='seleniumbase',
version='1.4.15',
version='1.4.16',
description='Web Automation & Testing Framework - http://seleniumbase.com',
long_description='Web Automation and Testing Framework - seleniumbase.com',
platforms='Mac * Windows * Linux * Docker',