Skip to content

Commit 3aeed00

Browse files
committed
Refactor the tests
1 parent 1dc6d92 commit 3aeed00

File tree

102 files changed

+838
-682
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+838
-682
lines changed

examples/boilerplates/base_test_case.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
'''
1+
"""
22
You can use this as a boilerplate for your test framework.
33
Define your customized library methods in a master class like this.
44
Then have all your test classes inherit it.
55
BaseTestCase will inherit SeleniumBase methods from BaseCase.
66
With Python 3, simplify "super(...)" to super().setUp() and super().tearDown()
7-
'''
7+
"""
88

99
from seleniumbase import BaseCase
1010

1111

1212
class BaseTestCase(BaseCase):
13-
1413
def setUp(self):
1514
super(BaseTestCase, self).setUp()
1615
# <<< Run custom setUp() code for tests AFTER the super().setUp() >>>
@@ -38,7 +37,7 @@ def example_method(self):
3837
pass
3938

4039

41-
'''
40+
"""
4241
# Now you can do something like this in your test files:
4342
4443
from base_test_case import BaseTestCase
@@ -51,4 +50,4 @@ def test_example(self):
5150
self.type("input", "Name")
5251
self.click("form button")
5352
...
54-
'''
53+
"""

examples/boilerplates/boilerplate_test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44

55
class MyTestClass(BaseTestCase):
6-
76
def test_boilerplate(self):
87
self.login()
98
self.example_method()

examples/boilerplates/classic_obj_test.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
from seleniumbase import BaseCase
33

44

5-
class DataPage():
6-
5+
class DataPage:
76
def go_to_data_url(self, sb):
87
sb.open("data:text/html,<p>Hello!</p><input />")
98

@@ -12,7 +11,6 @@ def add_input_text(self, sb, text):
1211

1312

1413
class ObjTests(BaseCase):
15-
1614
def test_data_url_page(self):
1715
DataPage().go_to_data_url(self)
1816
self.assert_text("Hello!", "p")

examples/boilerplates/file_parsing/parse_files.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,50 @@
1-
'''
1+
"""
22
Demonstration of parsing data from files.
33
In this example, login information is pulled for tests.
4-
'''
4+
"""
55

66
from seleniumbase import BaseCase
77

88

99
class ParseTestCase(BaseCase):
10-
1110
def setUp(self):
1211
super(ParseTestCase, self).setUp()
1312

1413
def get_login_credentials(self, user_type):
1514
# Example of parsing data from a file (Method 1)
16-
with open('qa_login_example.txt') as f:
15+
with open("qa_login_example.txt") as f:
1716
file_lines = [line.rstrip() for line in f]
1817
for line in file_lines:
19-
line_items = line.split(',')
18+
line_items = line.split(",")
2019
if line_items[0] == user_type:
2120
return line_items[1], line_items[2]
2221

2322
def get_all_login_credentials(self):
2423
# Example of parsing data from a file (Method 2)
2524
keys = {}
26-
with open('staging_login_example.txt') as f:
25+
with open("staging_login_example.txt") as f:
2726
file_lines = [line.rstrip() for line in f]
2827
for line in file_lines:
29-
line_items = line.split(',')
30-
if line_items[0] == 'admin':
31-
keys['admin'] = (
32-
{'username': line_items[1], 'password': line_items[2]})
33-
if line_items[0] == 'employee':
34-
keys['employee'] = (
35-
{'username': line_items[1], 'password': line_items[2]})
36-
if line_items[0] == 'customer':
37-
keys['customer'] = (
38-
{'username': line_items[1], 'password': line_items[2]})
28+
line_items = line.split(",")
29+
if line_items[0] == "admin":
30+
keys["admin"] = {
31+
"username": line_items[1],
32+
"password": line_items[2],
33+
}
34+
if line_items[0] == "employee":
35+
keys["employee"] = {
36+
"username": line_items[1],
37+
"password": line_items[2],
38+
}
39+
if line_items[0] == "customer":
40+
keys["customer"] = {
41+
"username": line_items[1],
42+
"password": line_items[2],
43+
}
3944
return keys
4045

4146

4247
class ParseTests(ParseTestCase):
43-
4448
def test_get_login_credentials(self):
4549
print("\nExample 1 of getting login info from parsing a config file:")
4650
print("")

examples/boilerplates/page_objects.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
'''
1+
"""
22
Example of using the Page Object Pattern for tests, using CSS selectors.
33
Helps make your code more Readable, Maintainable, and Reusable.
44
Import a file like this at the top of your test files.
5-
'''
5+
"""
66

77

88
class Page(object):
@@ -28,7 +28,7 @@ class CheckoutPage(object):
2828
shop_more = "#shop-more"
2929

3030

31-
'''
31+
"""
3232
# Now you can do something like this in your test files:
3333
3434
from .base_test_case import BaseTestCase
@@ -44,4 +44,4 @@ def test_example(self):
4444
self.click(CheckoutPage.buy_now)
4545
self.assert_element("#success")
4646
self.assert_text("Order Received!", "#h2")
47-
'''
47+
"""

examples/boilerplates/samples/google_objects.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ class HomePage(object):
66
search_box = 'input[title="Search"]'
77
list_box = '[role="listbox"]'
88
search_button = 'input[value="Google Search"]'
9-
feeling_lucky_button = '''input[value="I'm Feeling Lucky"]'''
9+
feeling_lucky_button = """input[value="I'm Feeling Lucky"]"""
1010

1111

1212
class ResultsPage(object):
1313
google_logo = 'img[alt="Google"]'
14-
images_link = 'link=Images'
15-
search_results = 'div#center_col'
14+
images_link = "link=Images"
15+
search_results = "div#center_col"

examples/boilerplates/samples/google_test.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55

66

77
class GoogleTests(BaseCase):
8-
98
def test_google_dot_com(self):
10-
self.open('https://google.com/ncr')
11-
self.type(HomePage.search_box, 'github')
9+
self.open("https://google.com/ncr")
10+
self.type(HomePage.search_box, "github")
1211
self.assert_element(HomePage.list_box)
1312
self.assert_element(HomePage.search_button)
1413
self.assert_element(HomePage.feeling_lucky_button)
1514
self.click(HomePage.search_button)
16-
self.assert_text('github.com', ResultsPage.search_results)
15+
self.assert_text("github.com", ResultsPage.search_results)
1716
self.assert_element(ResultsPage.images_link)

examples/boilerplates/samples/sb_swag_test.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
""" Classic Page Object Model with the "sb" fixture """
22

33

4-
class LoginPage():
5-
4+
class LoginPage:
65
def login_to_swag_labs(self, sb, username):
76
sb.open("https://www.saucedemo.com")
87
sb.type("#user-name", username)
98
sb.type("#password", "secret_sauce")
109
sb.click('input[type="submit"]')
1110

1211

13-
class MyTests():
14-
12+
class MyTests:
1513
def test_swag_labs_login(self, sb):
1614
LoginPage().login_to_swag_labs(sb, "standard_user")
1715
sb.assert_element("#inventory_container")

examples/boilerplates/samples/swag_labs_test.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
from seleniumbase import BaseCase
44

55

6-
class LoginPage():
7-
6+
class LoginPage:
87
def login_to_swag_labs(self, sb, username):
98
sb.open("https://www.saucedemo.com")
109
sb.type("#user-name", username)
@@ -13,7 +12,6 @@ def login_to_swag_labs(self, sb, username):
1312

1413

1514
class MyTests(BaseCase):
16-
1715
def test_swag_labs_login(self):
1816
LoginPage().login_to_swag_labs(self, "standard_user")
1917
self.assert_element("#inventory_container")

examples/boilerplates/samples/test_page_objects.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,41 @@
33
from seleniumbase import BaseCase
44

55

6-
class GooglePage():
7-
6+
class GooglePage:
87
def go_to_google(self, sb):
98
sb.open("https://google.com/ncr")
109

1110
def do_search(self, sb, search_term):
12-
sb.type('input[title="Search"]', search_term + '\n')
11+
sb.type('input[title="Search"]', search_term + "\n")
1312

1413
def click_search_result(self, sb, content):
1514
sb.click('a[href*="%s"]' % content)
1615

1716

18-
class SeleniumBaseGitHubPage():
19-
17+
class SeleniumBaseGitHubPage:
2018
def click_seleniumbase_io_link(self, sb):
2119
link = '#readme article a[href*="seleniumbase.io"]'
2220
sb.wait_for_element_visible(link)
2321
sb.js_click(link)
2422
sb.switch_to_newest_window()
2523

2624

27-
class SeleniumBaseIOPage():
28-
25+
class SeleniumBaseIOPage:
2926
def do_search_and_click(self, sb, search_term):
3027
if sb.is_element_visible('[for="__search"] svg'):
3128
sb.click('[for="__search"] svg')
3229
sb.type('form[name="search"] input', search_term)
33-
sb.click('li.md-search-result__item h1:contains(%s)' % search_term)
30+
sb.click("li.md-search-result__item h1:contains(%s)" % search_term)
3431

3532

3633
class MyTests(BaseCase):
37-
3834
def test_page_objects(self):
3935
search_term = "SeleniumBase GitHub"
4036
expected_text = "seleniumbase/SeleniumBase"
4137
GooglePage().go_to_google(self)
4238
GooglePage().do_search(self, search_term)
43-
self.assert_text(expected_text, '#search')
39+
self.assert_text(expected_text, "#search")
4440
GooglePage().click_search_result(self, expected_text)
4541
SeleniumBaseGitHubPage().click_seleniumbase_io_link(self)
4642
SeleniumBaseIOPage().do_search_and_click(self, "Dashboard")
47-
self.assert_text("Dashboard", 'main h1')
43+
self.assert_text("Dashboard", "main h1")

0 commit comments

Comments
 (0)