'Is it possible to specifiy which step implementation to use in behave?

My test suite have features/scenarios for both desktop and mobile. some steps will eventually have the same name (i.e., when I go to home page, when i click order ... etc)

the implementation though would be different between mobile and desktop and the only solution I can come up with right now is to slightly change the scenario name when I go to home page on phone but I'm still looking for a way to specify which implementation to use.

I would also go for a better setup if you can recommend something (for example building two test suites, one for mobile and one for desktop) but it seems that that will create more work than it saves.



Solution 1:[1]

In my current Behave-based UI test framework, we rely on

Write once, test everywhere

principle. Meaning, the Gherkin is declarative, specifying via annotations/tags which scenario is applicable for desktop web or mobile. The names, steps and flow is the same for both platforms. The actual handling is done via DSL layer and Strategy pattern to pick up proper driver and flow at runtime. So, from design point of view it looks like this:

                              ===========================
                              | Gherkin (feature files) |
                              ===========================
                                          |
                         =====================================
                         | Step definitions (step_functions) |
                         =====================================
                                          |
                            ===============================
                            |            DSL              |
                            | (domain_models, strategies) |
                            |     e.g. login, register    |
                            ===============================
                                          |
                      ==============================================
                      |              Selenium Wrappers             |
                      |    (facade, decorators, adapters, proxy)   |
                      |e.g. atoms/element_actions.py or elementium |
                      ==============================================
                                          |
                         =========================================
                        |          Automation code              |
                        | (python bindings, protractor porting) |
                        =========================================
                                   /                  \
          _________________________________________________________________
                                SELENIUM ARCHITECTURE HERE
                              /                            \
                     ==============                 =================
                     | appium_api |                 | webdriver_api |
                     ==============                 =================
                            |                               |
                    =======   ===========    ==============   ===============
                    | iOS |   | Android |    |ChromeDriver|   |FirefoxDriver|
                    =======   ===========    ==============   ===============

All you need to do is pass custom flags to your specific/CI run, like so -D platform=desktop -D browser=chrome. This can be picked up via TagsManager and executed to proper strategy via dispatch mapping.

So, you don't need

building two test suites, one for mobile and one for desktop

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ekostadinov