0

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

1 Answers1

0

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.

Given Jack (the fitness enthusiast) completes the daily exercise task
When Jack fills out a questionnaire prompt about his habits 
Then Jack will receive the fitness enthusiasts advice to workouts
Given Jill (the workaholic) completes the daily exercise task
When Jill fills out a questionnaire prompt about his habits 
Then Jill will receive the workaholics advice to workouts
And an extra set of reminders is scheduled to remind Jill to take an early break 
M.P. Korstanje
  • 10,426
  • 3
  • 36
  • 58
  • I appreciate the answer I'm still certain that it's possible to reuse data for assertions (i.e. User answered 10 questions(store in list) => performed other tasks => went back to questions to see if answers are still there and correct (using list) ) I'm tired of hearing about tests should be independent: Yes, they should be in web automation. For native app - it has no sense. I need to check all functionality and features in user flow are very connected. I understand that everywhere, everyone repeat that "Tests should be independent", but it's not true for all projects – Denys Moroz Dec 27 '19 at 20:04
  • Your tests must be independent if you want to execute scenarios/tests parallel. There is no way around that. Aside from that I believe the answer I gave you should let you do what you want to do. Think about it. – M.P. Korstanje Dec 28 '19 at 18:05