Writing Tests - RMuskovets/pytest-stepper-plugin GitHub Wiki

As you probably know from Pytest wiki and/or some tutorials, all "vanilla" tests are functions whose names start with test_...

But not with this plugin. Now tests can also be lists of steps!

When I worked with automated tests for websites, I saw a pattern like this:

def test_can_login_on_website(browser):
    i = BaseActions(browser)
    i.go_to(WEBSITE_BASE_URL)
    i.see_element(Locators.LOGIN_LINK)
    i.click(Locators.LOGIN_LINK)
    i.wait(3)  # wait for the redirect to be completed
    i.see_element(Locators.EMAIL_FIELD)
    i.fill_field(Locators.EMAIL_FIELD, "[email protected]")
    i.see_element(Locators.PASSWORD_FIELD)
    i.fill_field(Locators.PASSWORD_FIELD, "th1s 1s 4 v3ry g00d p4ssw0rd")
    i.see_element(Locators.LOGIN_BUTTON)
    i.click(Locators.LOGIN_BUTTON)

I think this is too much code, so here's how the same test would look using the Stepper plugin (assuming you have all the needed step functions):

test_can_login_on_website = [
    go_to(WEBSITE_BASE_URL),
    see_element(Locators.LOGIN_LINK), click(Locators.LOGIN_LINK),
    wait(3),
    see_element(Locators.EMAIL_FIELD), fill_field(Locators.EMAIL_FIELD, "[email protected]"),
    see_element(Locators.PASSWORD_FIELD), fill_field(Locators.PASSWORD_FIELD, "th1s 1s 4 v3ry g00d p4ssw0rd"),
    see_element(Locators.LOGIN_BUTTON), click(Locators.LOGIN_BUTTON)
]

This doesn't have all those i.something() calls, but the best part is that you can actually see which step failed (if some):

platform linux -- Python 3.x.y, pytest-a.b.c, py-d.e.f, pluggy-g.h.i
rootdir: /home/username/automated-tests
collected N items

tests/test_login.py F <many spaces> [100%]

============================ FAILURES ============================
_________________ test: test_can_login_on_website ________________
test execution failed at step #N, reason: <some reason>
traceback:
<a good-old traceback>

So yes, that's all.
To create a test you make a list of steps you want to execute.
If some step failed, the test will stop and show the step's number.