Update example test boilerplates
This commit is contained in:
parent
73520c67fe
commit
09693a4937
|
@ -18,15 +18,14 @@ class BaseTestCase(BaseCase):
|
||||||
# Add custom tearDown code for your tests BEFORE the super().tearDown()
|
# Add custom tearDown code for your tests BEFORE the super().tearDown()
|
||||||
super(BaseTestCase, self).tearDown()
|
super(BaseTestCase, self).tearDown()
|
||||||
|
|
||||||
def login_to_site(self):
|
def login(self):
|
||||||
# <<< Placeholder for actual code. Add your code here. >>>
|
# <<< Placeholder. Add your code here. >>>
|
||||||
# Add frequently used methods like this in your base test case class.
|
# Reduce duplicate code in tests by having reusable methods like this.
|
||||||
# This reduces the amount of duplicated code in your tests.
|
# If the UI changes, the fix can be applied in one place.
|
||||||
# If the UI changes, the fix only needs to be applied in one place.
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def example_method(self):
|
def example_method(self):
|
||||||
# <<< Placeholder for actual code. Add your code here. >>>
|
# <<< Placeholder. Add your code here. >>>
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@ -38,6 +37,6 @@ from base_test_case import BaseTestCase
|
||||||
class MyTests(BaseTestCase):
|
class MyTests(BaseTestCase):
|
||||||
|
|
||||||
def test_example(self):
|
def test_example(self):
|
||||||
self.login_to_site()
|
self.login()
|
||||||
self.example_method()
|
self.example_method()
|
||||||
'''
|
'''
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
from .base_test_case import BaseTestCase
|
from .base_test_case import BaseTestCase
|
||||||
from .page_objects import HomePage
|
from .page_objects import Page
|
||||||
|
|
||||||
|
|
||||||
class MyTestClass(BaseTestCase):
|
class MyTestClass(BaseTestCase):
|
||||||
|
|
||||||
def test_boilerplate(self):
|
def test_boilerplate(self):
|
||||||
self.login_to_site()
|
self.login()
|
||||||
self.example_method()
|
self.example_method()
|
||||||
self.assert_element(HomePage.html)
|
self.assert_element(Page.html)
|
||||||
|
|
|
@ -1,17 +1,21 @@
|
||||||
'''
|
'''
|
||||||
Example of using the Page Object Model (POM) for tests, using page selectors.
|
Example of using the Page Object Pattern for tests, using CSS selectors.
|
||||||
Helps make your code more Readable, Maintainable, and Reusable.
|
Helps make your code more Readable, Maintainable, and Reusable.
|
||||||
Import a file like this at the top of your test files.
|
Import a file like this at the top of your test files.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
|
||||||
class HomePage(object):
|
class Page(object):
|
||||||
html = "html"
|
html = "html"
|
||||||
ok_button = "#ok"
|
ok_button = "#ok"
|
||||||
cancel_button = "#cancel"
|
cancel_button = "#cancel"
|
||||||
see_items_button = "button.items"
|
see_items_button = "button.items"
|
||||||
|
|
||||||
|
|
||||||
|
class HomePage(object):
|
||||||
|
see_items_button = "button.items"
|
||||||
|
|
||||||
|
|
||||||
class ShoppingPage(object):
|
class ShoppingPage(object):
|
||||||
buyable_item = 'img[alt="Item"]'
|
buyable_item = 'img[alt="Item"]'
|
||||||
add_to_cart = "button.add"
|
add_to_cart = "button.add"
|
||||||
|
@ -33,7 +37,7 @@ from .page_objects import HomePage, ShoppingPage, CheckoutPage
|
||||||
class MyTests(BaseTestCase):
|
class MyTests(BaseTestCase):
|
||||||
|
|
||||||
def test_example(self):
|
def test_example(self):
|
||||||
self.login_to_site()
|
self.login()
|
||||||
self.click(HomePage.see_items_button)
|
self.click(HomePage.see_items_button)
|
||||||
self.click(ShoppingPage.buyable_item)
|
self.click(ShoppingPage.buyable_item)
|
||||||
self.click(ShoppingPage.add_to_cart)
|
self.click(ShoppingPage.add_to_cart)
|
||||||
|
|
Loading…
Reference in New Issue