I have a framework for native iOS testing which utilizes Appium, TestNg, Cucumber, PicoContainer
And I`m looking for best way to store data fetched from one step/scenario that later can be used to assert another scenario
Example: Scenario: user can answer on survey question Given User answers on Survey Question with {var1} Then success screen displayed
Scenario: previously answered question has value that user sent initially Given user on reviewMyAnswers screen Then answer hold value of {var1}
I just give generic example. In reality i have a lot of data like this that need to be validated and i want to store answer from first scenario in separate class and then retrieve it when needed by key and value pairs somehow like that
public classWhereIstoreTestData() {
ANSWER1;
ANSWER2;
PRODUCT1;
ETC...;
}
@Given(User answers on Survey Question with {var1}{
poSurvey.AnswerOnQuestion;
classWhereIstoreTestData().setValue(key.Answer1,value.poSurvey.getAnswerValue)
@Then(answer hold value of {var1}{
assertThat(classWhereIstoreTestData().getValue(key.Answer1),equalsTo(poSurvey.GetAcceptedAnswerValue)
I`ve seen tutorials (there are just couple on google) , but could not get them They all seem much more complicated then they suppose to be
My app is not too big and i guess i gonna be using just one stepdefs file. But i still don't want to use static variables for this purpose cause I'm planning to use parrallelization in future
Much like Unit Tests, Scenarios should be independent from each other and sharing data makes them depend on each other. This is a problem. Esp. if you want to use parallel execution later on you can't guaranteed that the Scenario that consumes the data won't run at the same time as the one that produces it.
In short. You can't share data in any way other then using static variables.
And you shouldn't have to. Rather then writing out the answers to the questionnaire step by step in a feature file and then trying to reuse this data, what you can do is store the answer in a
Map<String, String>
in your step definition file and use it to fill out all questions of the questionnaire all at once in a single step. Or if you need to fill out an entire flow to get where you want to test your thing, do all that and the questionnaire in a single step.Now you'll probably have a few different scenarios and different ways to progress through the application. If you specify these paths technically you'll get rather dry feature file. However if you use personas to name these variations they'll become more understand able.