Skip to content

Commit 927cdf8

Browse files
authored
Merge pull request #134 from seleniumbase/updates
Updates - Adding more env options and adding boilerplates.
2 parents 077df5a + 4044a1f commit 927cdf8

File tree

16 files changed

+169
-23
lines changed

16 files changed

+169
-23
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@ pytest my_first_test.py --with-selenium --browser=chrome --demo_mode
112112

113113
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.)
114114

115-
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.
116-
117115
```bash
118116
nosetests my_first_test.py --with-selenium --browser=chrome --demo_mode --demo_sleep=1.2
119117
```
@@ -158,6 +156,8 @@ pytest my_first_test.py --with-testing_base --browser=chrome
158156

159157
(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.**
160158

159+
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.
160+
161161

162162
<a id="creating_visual_reports"></a>
163163
### ![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"]')
349349
#### Asserting visibility of text inside an element on a page within some number of seconds:
350350

351351
```python
352-
self.wait_for_text_visible("Make it so!", "div#trek div.picard div.quotes", timeout=3)
353-
self.wait_for_text_visible("Tea. Earl Grey. Hot.", "div#trek div.picard div.quotes", timeout=1)
352+
self.assert_text("Make it so!", "div#trek div.picard div.quotes")
353+
self.assert_text("Tea. Earl Grey. Hot.", "div#trek div.picard div.quotes", timeout=3)
354354
```
355-
(NOTE: The short versions of this are ``self.find_text(TEXT, ELEMENT)`` and ``self.assert_text(TEXT, ELEMENT)``)
355+
(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.)
356356

357357
#### Asserting Anything
358358

examples/ReadMe.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Running SeleniumBase Scripts
22

3-
(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.)
3+
(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.)
44

55
To makes things easier, here's a simple GUI program that allows you to kick off a few example scripts by pressing a button:
66

@@ -14,7 +14,7 @@ python gui_test_runner.py
1414

1515
![](http://cdn2.hubspot.net/hubfs/100006/images/GUI_Test_Runner_5.png "GUI Test Runner")
1616

17-
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.
17+
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).
1818

1919
**For running scripts the usual way, here are some of the example run commands:**
2020

examples/boilerplates/__init__.py

Whitespace-only changes.

examples/boilerplates/file_parsing/__init__.py

Whitespace-only changes.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
from seleniumbase import BaseCase
2+
3+
4+
class ParseTestCase(BaseCase):
5+
6+
def setUp(self):
7+
super(ParseTestCase, self).setUp()
8+
9+
def get_login_credentials(self, user_type):
10+
# Example of parsing data from a file
11+
f = open('qa_login_example.txt', "r")
12+
file_data = f.read()
13+
file_lines = file_data.split('\n')
14+
for line in file_lines:
15+
line_items = line.split(',')
16+
if line_items[0] == user_type:
17+
return line_items[1], line_items[2]
18+
f.close()
19+
20+
def get_all_login_credentials(self):
21+
# Example of parsing data from a file (Method 2)
22+
keys = {}
23+
f = open("staging_login_example.txt")
24+
file_data = f.read()
25+
file_lines = file_data.split('\n')
26+
for line in file_lines:
27+
line_items = line.split(',')
28+
if line_items[0] == 'admin':
29+
keys['admin'] = (
30+
{'username': line_items[1], 'password': line_items[2]})
31+
if line_items[0] == 'employee':
32+
keys['employee'] = (
33+
{'username': line_items[1], 'password': line_items[2]})
34+
if line_items[0] == 'customer':
35+
keys['customer'] = (
36+
{'username': line_items[1], 'password': line_items[2]})
37+
f.close()
38+
return keys
39+
40+
41+
class ParseTests(ParseTestCase):
42+
43+
def test_get_login_credentials(self):
44+
print("\nExample 1 of getting login info from parsing a config file:")
45+
print("")
46+
username, password = self.get_login_credentials("admin")
47+
print("Getting Admin User login data:")
48+
print("Username: %s" % username)
49+
print("Password: %s" % password)
50+
51+
print("\nExample 2 of getting login info from parsing a config file:")
52+
print("")
53+
keys = self.get_all_login_credentials()
54+
print("Getting Customer login data:")
55+
print("Username: %s" % keys["customer"]["username"])
56+
print("Password: %s" % keys["customer"]["password"])
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
admin,admin_username_qa,admin_password_qa
2+
employee,employee_username_qa,employee_password_qa
3+
customer,customer_username_qa,customer_password_qa
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
admin,admin_username_staging,admin_password_staging
2+
employee,employee_username_staging,employee_password_staging
3+
customer,customer_username_staging,customer_password_staging

examples/boilerplates/master_class.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'''
2+
You can use this as a boilerplate for your test framework.
3+
Define your customized library methods here.
4+
Then have all your test classes inherit it.
5+
The master class will inherit SeleniumBase methods from BaseCase.
6+
'''
7+
8+
from seleniumbase import BaseCase
9+
10+
11+
class MasterTestCase(BaseCase):
12+
13+
def setUp(self):
14+
super(MasterTestCase, self).setUp()
15+
16+
def example_method(self):
17+
pass
18+
19+
20+
'''
21+
# Now you can do something like this in your test files:
22+
23+
from master_class import MasterTestCase
24+
25+
class MyTests(MasterTestCase):
26+
27+
def test_example(self):
28+
self.example_method()
29+
'''

examples/boilerplates/pom_lib/__init__.py

Whitespace-only changes.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
'''
2+
Example of using the Page Object Model (POM) for tests, using page selectors.
3+
Helps make your code more Readable, Maintainable, and Reusable.
4+
Import a file like this in your test files.
5+
'''
6+
7+
8+
class HomePage(object):
9+
ok_button = "#ok"
10+
cancel_button = "#cancel"
11+
see_items = "button.items"
12+
13+
14+
class ShoppingPage(object):
15+
buyable_item = 'img[alt="Item"]'
16+
add_to_cart = "button.add"
17+
go_to_checkout = "#checkout"
18+
19+
20+
class CheckoutPage(object):
21+
remove_from_cart = "button.remove"
22+
pay_now = "#pay-now"
23+
shop_more = "#shop-more"
24+
25+
26+
'''
27+
# Now you can do something like this in your test files:
28+
29+
from master_class import MasterTestCase
30+
from pom_lib.page_selectors import HomePage, ShoppingPage, CheckoutPage
31+
32+
class MyTests(MasterTestCase):
33+
34+
def test_example(self):
35+
self.open(RANDOM_SHOPPING_WEBSITE)
36+
self.click(HomePage.see_items)
37+
self.click(ShoppingPage.buyable_item)
38+
self.click(ShoppingPage.add_to_cart)
39+
self.click(CheckoutPage.pay_now)
40+
self.assert_element("#success")
41+
self.assert_text("Order Received!", "#h2")
42+
'''

0 commit comments

Comments
 (0)