I had existing UI tests using Xamarin UI Test and NUnit. In my test class I was able to decorate the class with
[TestFixture(Platform.Android)]
[TestFixture(Platform.iOS)]
I could in turn use this in my test setup and execution to handle different thing per platform and the test runner in VS would show things like "LoginTest - iOS", "LoginTest - Android".
I have switched to Appium and I am trying to use Specflow, but I can't figure out how to make a single Scenario target both platforms automatically. I don't want to have to change a config file to run iOS vs Android, when I run the tests I want to run both, or ideally have the test runner display different distinct tests for each platform but derived from the same feature/step code.
How do I parameterize the entire Scenario per platform?
**UPDATE Ok, so I have sort of stumbled on how to accomplish this but I am still not sure whether this is the optimal way.
In my feature file I have this for example:
Scenario Outline: Successful login
Given the user is on login page
And the user entered valid credentials
When the user presses sign in button
Then the user ends on dashboard page
Scenarios:
|platform|
|IOS|
|Android|
Adding the Scenarios table with no variable specified adds the table to the scenarioContext.ScenarioInfo.Arguments["platform"]
. It also adds an entry per platform to the test runner in VS.
The only real problem I see in this way is that you have to enter the Scenarios table of platforms for each Scenario Outline. This seems like it could become a nightmare later with tons of tests and say you want to add another platform. It would be great to be able to specify the table in an external file that was included or referenced some way by each feature file since I would likely use it for all my tests.
Ok, so I stumbled upon the Nuget SpecFlow.Contrib.Variants
.
This does exactly what I want and I was able to switch from my OOB workaround to the package without much issue.
With the Variants package you can decorate a feature or scenario with something like
@Platform:Android
@Platform:IOS
Then in test runner you get this much cleaner view like:
This allowed me to remove all my repeated:
Scenarios:
|platform|
|IOS|
|Android|
Very little setup, works great, I wish I found it first.