File tree Expand file tree Collapse file tree 5 files changed +59
-42
lines changed Expand file tree Collapse file tree 5 files changed +59
-42
lines changed Original file line number Diff line number Diff line change
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
+ '''
Original file line number Diff line number Diff line change
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 )
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 6
6
7
7
8
8
class HomePage (object ):
9
+ html = "html"
9
10
ok_button = "#ok"
10
11
cancel_button = "#cancel"
11
12
see_items_button = "button.items"
@@ -26,13 +27,13 @@ class CheckoutPage(object):
26
27
'''
27
28
# Now you can do something like this in your test files:
28
29
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
31
32
32
- class MyTests(MasterTestCase ):
33
+ class MyTests(BaseTestCase ):
33
34
34
35
def test_example(self):
35
- self.open(RANDOM_SHOPPING_WEBSITE )
36
+ self.login_to_site( )
36
37
self.click(HomePage.see_items_button)
37
38
self.click(ShoppingPage.buyable_item)
38
39
self.click(ShoppingPage.add_to_cart)
Original file line number Diff line number Diff line change 3
3
'''
4
4
5
5
from seleniumbase import BaseCase
6
- from google_objects import HomePage , ResultsPage
6
+ from . google_objects import HomePage , ResultsPage
7
7
8
8
9
9
class GoogleTests (BaseCase ):
You can’t perform that action at this time.
0 commit comments