Search code examples
pythonselenium-webdriverpython-behave

How to create several implementation for the same named steps (behave)


I have two scenarios for two pages (homepage and property page). And in these scenarios I have the same steps (I fill in "field" with "text"). I need to implement one for homepage and one for property page. But behave sees only one implementation. How could I do the different implementation for the same named steps? I dont want to do hardcode and call the same action differently.

My stack: behave + python + selenium + pageObject


Solution

  • Somehow, somewhere, you have to put in code to say the things are different.

    • Add another variable to the statement (I fill in "field" on "page" with "text")
    • Use two statements (I fill in homepage "field" with "text" && I fill in property "field" with "text")
    • Add logic to the method to dynamically figure out what page it is looking at to know what field is which

    All have advantages and drawbacks. You'll need to decide which works best for your situation. The problem with having a generic statement is that it can be applied to too many areas and eventually something has to give.