|
| 1 | +""" |
| 2 | +Performance test example. |
| 3 | +
|
| 4 | +Uses decorators.print_runtime(), which prints the runtime duration |
| 5 | +of a method or "with"-block after the method (or block) completes. |
| 6 | +Also raises an exception when exceeding the time "limit" if set. |
| 7 | +
|
| 8 | +Arguments -> |
| 9 | + description # Optional - Shows description in print output. |
| 10 | + limit # Optional - Fail if the duration is above the limit. |
| 11 | +
|
| 12 | +Method / Function example usage -> |
| 13 | + from seleniumbase import decorators |
| 14 | +
|
| 15 | + @decorators.print_runtime("My Method") |
| 16 | + def my_method(): |
| 17 | + # code ... |
| 18 | + # code ... |
| 19 | +
|
| 20 | +"with"-block example usage -> |
| 21 | + from seleniumbase import decorators |
| 22 | +
|
| 23 | + with decorators.print_runtime("My Code Block"): |
| 24 | + # code ... |
| 25 | + # code ... |
| 26 | +""" |
| 27 | +from seleniumbase import BaseCase |
| 28 | +from seleniumbase import decorators |
| 29 | + |
| 30 | + |
| 31 | +class PerformanceClass(BaseCase): |
| 32 | + @decorators.print_runtime("Open Swag Labs and Log In") |
| 33 | + def login_to_swag_labs(self): |
| 34 | + with decorators.print_runtime("Open Swag Labs"): |
| 35 | + self.open("https://www.saucedemo.com") |
| 36 | + self.type("#user-name", "standard_user") |
| 37 | + self.type("#password", "secret_sauce\n") |
| 38 | + |
| 39 | + def test_performance_of_swag_labs(self): |
| 40 | + self.login_to_swag_labs() |
| 41 | + self.assert_element("div.inventory_list") |
| 42 | + self.assert_exact_text("PRODUCTS", "span.title") |
| 43 | + with decorators.print_runtime("Add backpack and see cart"): |
| 44 | + self.click('button[name*="backpack"]') |
| 45 | + self.click("#shopping_cart_container a") |
| 46 | + self.assert_text("Backpack", "div.cart_item") |
| 47 | + with decorators.print_runtime("Remove backpack from cart"): |
| 48 | + self.click('button:contains("Remove")') # HTML innerText |
| 49 | + self.assert_text_not_visible("Backpack", "div.cart_item") |
| 50 | + with decorators.print_runtime("Log out from Swag Labs", 3): |
| 51 | + self.js_click("a#logout_sidebar_link") |
| 52 | + self.assert_element("div#login_button_container") |
0 commit comments