Skip to content

Commit b1c6b95

Browse files
committed
Update boilerplates
1 parent bd46f60 commit b1c6b95

File tree

5 files changed

+59
-42
lines changed

5 files changed

+59
-42
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
'''
2+
You can use this as a boilerplate for your test framework.
3+
Define your customized library methods in a master class like this.
4+
Then have all your test classes inherit it.
5+
BaseTestCase will inherit SeleniumBase methods from BaseCase.
6+
'''
7+
8+
from seleniumbase import BaseCase
9+
10+
11+
class BaseTestCase(BaseCase):
12+
13+
def setUp(self):
14+
super(BaseTestCase, self).setUp()
15+
# Add custom setUp code for your tests AFTER the super().setUp()
16+
17+
def tearDown(self):
18+
# Add custom tearDown code for your tests BEFORE the super().tearDown()
19+
super(BaseTestCase, self).tearDown()
20+
21+
def login_to_site(self):
22+
# <<< Placeholder for actual code. Add your code here. >>>
23+
# Add frequently used methods like this in your base test case class.
24+
# This reduces the amount of duplicated code in your tests.
25+
# If the UI changes, the fix only needs to be applied in one place.
26+
pass
27+
28+
def example_method(self):
29+
# <<< Placeholder for actual code. Add your code here. >>>
30+
pass
31+
32+
33+
'''
34+
# Now you can do something like this in your test files:
35+
36+
from base_test_case import BaseTestCase
37+
38+
class MyTests(BaseTestCase):
39+
40+
def test_example(self):
41+
self.login_to_site()
42+
self.example_method()
43+
'''
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from .base_test_case import BaseTestCase
2+
from .page_objects import HomePage
3+
4+
5+
class MyTestClass(BaseTestCase):
6+
7+
def test_boilerplate(self):
8+
self.login_to_site()
9+
self.example_method()
10+
self.assert_element(HomePage.html)

examples/boilerplates/master_test_case.py

Lines changed: 0 additions & 37 deletions
This file was deleted.

examples/boilerplates/page_objects.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77

88
class HomePage(object):
9+
html = "html"
910
ok_button = "#ok"
1011
cancel_button = "#cancel"
1112
see_items_button = "button.items"
@@ -26,13 +27,13 @@ class CheckoutPage(object):
2627
'''
2728
# Now you can do something like this in your test files:
2829
29-
from master_class import MasterTestCase
30-
from page_objects import HomePage, ShoppingPage, CheckoutPage
30+
from .base_test_case import BaseTestCase
31+
from .page_objects import HomePage, ShoppingPage, CheckoutPage
3132
32-
class MyTests(MasterTestCase):
33+
class MyTests(BaseTestCase):
3334
3435
def test_example(self):
35-
self.open(RANDOM_SHOPPING_WEBSITE)
36+
self.login_to_site()
3637
self.click(HomePage.see_items_button)
3738
self.click(ShoppingPage.buyable_item)
3839
self.click(ShoppingPage.add_to_cart)

examples/boilerplates/samples/google_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
'''
44

55
from seleniumbase import BaseCase
6-
from google_objects import HomePage, ResultsPage
6+
from .google_objects import HomePage, ResultsPage
77

88

99
class GoogleTests(BaseCase):

0 commit comments

Comments
 (0)