1

I'm working on an automation project for a mobile app in ios and android. I'm using Java-Appium-Cucumber framework for writing tests.

Below shows my project structure

src

 android

  features

  step_definitions

 ios

  features

  step_definitions

I need a step "User logins to the app" for both android and ios. But the implementation in android and ios are different. So I wrote two step definitions in android > step_definitions and in ios > step_definitions.

But this results in duplicate step definition error.

PS:

  1. I do not want to have a single step definition with implementation as if(android) {doAndroidWay()} else (doIOSWay), because then I would have to check platform in all methods.

  2. I do not want to have multiple steps as 'User logs into the app in android' and 'User logs into the app in ios'

Is there any other way to get rid of duplicate step def error? Something like tell cucumber to look for steps only in android > step_definitions when running a scenario from android > features ?

Any help is appreciated.

Raedwald
  • 46,613
  • 43
  • 151
  • 237
SP.
  • 85
  • 3
  • 13
  • Are you using two separate runners for ios and android? – Grasshopper May 20 '18 at 14:26
  • @Grasshopper Yep, separate runners for android and ios – SP. May 22 '18 at 04:41
  • If you do not have any common stepdefinition code between android and ios, then use the glue option to tell the respective runners to look for the stepdef code in the subfolders. For android use glue="android.step_definitions" and for ios use glue="ios.step_definitions". – Grasshopper May 22 '18 at 04:56
  • Thanks a lot, now I can run the FeatureRunner successfully by providing the glue option as you had mentioned. But when I try to run a scenario from intellij (like a Right Click > Run Scenario) then I'm getting the step definition error. Is there any work around for that? – SP. May 22 '18 at 06:48
  • Not much idea about intellij. There should be a configuration setting when u run the scenario directly. Will add the comment as an answer so u can close this. Thx – Grasshopper May 22 '18 at 07:06

1 Answers1

1

If you do not have any common stepdefinition code between android and ios, then use the glue option to tell the respective runners to look for the stepdef code in the subfolders. For android use 'glue="android.step_definitions"' and for ios use 'glue="ios.step_definitions"'

Grasshopper
  • 8,908
  • 2
  • 17
  • 32