See Test Steps in Python when using selenium
I'm converting some manual tests to Python and using Selenium to test them. Currently the manual steps are written like to:
Requirement 1 - Can add new person, if none exists Step 1 - Search for the person using valid demographics Step 2 - If none exist, click add new person Step 3 - confirm previously entered demographics populated form Step 4 - Create person Step 5 - Confirm person now exists
I'm currently using
HtmlTestRunnerwhich does work to a degree. What I'd like to see or be able to obtain is the breakdown of each test. Where I can see the test being ran. The number of steps ran and their pass/fail status.
Requirement 1 - Pass Step 1 - Pass Step 2 - Pass Step 3 - Pass Step 4 - Fail Step 5 - Fail 1 test ran, 5 assertions, 3 passed, 2 failed (or something like this)
I'm not sure if perhaps it's possible to use dependent tests with
unittest. Where perhaps each step should be it's own test, but I'd need the driver and the current browser status available to continue the tests forward and not have to redo each step.
So if there is a commonly accepted way to achieve something like this that would be great!
This is where the use of techniques like using a Page Object Model come into play. In essence you are abstracting the mechanics of what your code does so your test code looks clean.
Taking your example scenario with 5 steps (note that my syntax will not be true python because I am not familiar enough with the language - not that what I'm writing is actual code):
// Scenario 1: Can add a new person if none can be found @Test def can_add_new_person_if_person_not_found: if search_for_person(personObject): Assert(fail) // the test is that we don't find them so finding the person is a failure - obviously the assert syntax is wrong) else: add_new_person(personObject) // steps 2 through 4, since the core of the scenario is not that the add proceeds correctly, it's that you get to add them once you've tried to find them) Assert(search_for_person(personObject) == true) //step 5
Obviously you define and set up your person object in a before test routine or as part of a data driven test suite. That object should have all the demographic information you use to search for them.
You also have one or more page objects which have the locators for the fields you interact with, and the ability to make changes. Your person details object may look a little like this (again, this is NOT code and should not be used as such):
class PersonPage def add_new_person(person) click_page_button("Add Person") enter_first_name(person.FirstName) enter_last_name(person.LastName) // and so on for any other fields you want to use click_page_button("Save") return PersonPage() def find_person(person): enter_search(person.FirstName) //etc. click_page_button("Find") return search_results().count > 0 def search_results(): return = driver.Instance.findElements.By(*resultListLocator goes here*)
You can see how this is working. Just please don't try to use my pseudo code.