Your data in DB should have some kind of segmentation e.g. data for user-1 would not not overlap data for user-2.
In this case assign a segment of data to a scenario e.g. user-1
So you can have these steps in the SAME scenario
- Delete all the data for user-1
- Add some data for user-1
- verify data added for user-1
- update added data for user-1
- verify data updated for user-1
- delete ...
Another scenario can run tests with data for user-2 - so these scenarios can now run in parallel.
Implementation wise, what I found very useful is a feature in karate to "call scenario" from another feature file ( https://intuit.github.io/karate/#calling-other-feature-files ).
So I have, what I call "callable scenarios" in one feature file, to actually do the stuff in the line items in the test above.
The "test scenario" calls the feature in "callable scenario" to delete data, add data, update data ...., and even to verify
the data. The verify would do a "select" from the DB for the userid, and match against the expected data.
e.g. file crud-callable.feature has the following :
@delete-all
# Caller in "test scenario" can call this "callable scenario" with a syntax like :
# call crud-callable.feature@delete-all {userId: userId}
Scenario: Delete all for a user
* def userId = karate.get ('userId', 'testUserId1')
# delete data for userId
...
@add-data
Scenario: Add data for a user
...
@update-data
Scenario: Update data for a user
...
...
During development, the callable scenarios can be "unit tested" by running them manually, when they will use
the hardcoded userId e.g. 'testUserId1'. When called from an automated test - they will use the userId passed in by the
caller. Then these "callable scenarios" can be used from multiple "test scenarios", with each "test scenario" passing a
different userId to the "callable scenario"
Now if we have different test scenarios use different userIds (or different segments of data, depending how your data
is segmented in the database) - they can run be in parallel. Unless of course, you
have a trivial system that does not allow multiple users to use the system simultaneously without causing issues.