|
| 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