Skip to content

Updates #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down Expand Up @@ -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:**
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions examples/ReadMe.md
Original file line number Diff line number Diff line change
@@ -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:

Expand All @@ -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``), you’ll 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``), you’ll 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:**

Expand Down
Empty file.
Empty file.
56 changes: 56 additions & 0 deletions examples/boilerplates/file_parsing/parse_files.py
Original file line number Diff line number Diff line change
@@ -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"])
3 changes: 3 additions & 0 deletions examples/boilerplates/file_parsing/qa_login_example.txt
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions examples/boilerplates/file_parsing/staging_login_example.txt
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions examples/boilerplates/master_class.py
Original file line number Diff line number Diff line change
@@ -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()
'''
Empty file.
42 changes: 42 additions & 0 deletions examples/boilerplates/pom_lib/page_selectors.py
Original file line number Diff line number Diff line change
@@ -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")
'''
22 changes: 11 additions & 11 deletions integrations/google_cloud/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -146,31 +146,31 @@ 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.
* Under the Google Cloud Platform menu, go to "Deployment Manager"
* 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:
Expand All @@ -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":

Expand All @@ -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!
2 changes: 1 addition & 1 deletion seleniumbase/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
DB_HOST = "127.0.0.1"
DB_USERNAME = "root"
DB_PASSWORD = "test"
DB_SCHEMA = "test"
DB_SCHEMA = "test_db"


# Amazon S3 Bucket Credentials
Expand Down
3 changes: 2 additions & 1 deletion seleniumbase/plugins/db_reporting_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def options(self, parser, env):
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)

Expand Down
14 changes: 13 additions & 1 deletion seleniumbase/plugins/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion server_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

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',
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

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',
Expand Down