Reputation: 2762
We are in the midst of writing e2e tests for our angular app using Cypress.io. The problem we are facing is that even though we know that tests should not depend on each other, but realistically speaking it seems impossible to achieve this in a real world app. Suppose a user needs to perform the following actions
Now if we have to write tests for these scenarios, we will either have to write one giant test that does all of this in one go or find a way to make them run in a sequence where perhaps each next test depends on the state left by the previous. I am curious how everyone tackles this situation because I feel it should appear very frequently in real enterprise apps.
Upvotes: 2
Views: 1726
Reputation: 1027
Take a look a the Cypress Real World App created for demonstrating real-world usage of Cypress testing methods, patterns, practices, and workflows.
https://www.cypress.io/blog/2020/06/11/introducing-the-cypress-real-world-app/
Upvotes: 0
Reputation: 516
Basically when you write E2E tests, first thumb rule is your tests have to be independently run and it should not depend on previous tests. Here you are running independent tests, but at the same time you are making API call to complete your pre-req steps(in login case, signup is done through API)
So basically you can proceed as below.
Write test for Signup functionality.
Now for login test, you will not do SignUp process again thru UI. So all you have to do make API call to do SignUp process.
Reason: Your UI for SignUp UI might have broken, and rest of the functionalities work fine. So you will not use UI route to do that. So make API call
As mentioned above, you will make API calls to do 1st & 2nd test case to land on for 3rd case
As mentioned above, you will make API calls to do 1st & 2nd & 3rd test case to land on for 4th case
As mentioned above, you will make API calls to do 1st & 2nd & 3rd & 4th test case to land on for 5th case
Upvotes: 3
Reputation: 1248
Basically what I'll be doing is create 5 test files which include corresponding tests. But each test will have different pre-requisites. In your scenario,
What I would do is,
Then if we take test case for Create a category
As prerequisites (beforeeach)
in test cases (it)
The reason to cluster your test scrips is it's easy to individually check the components if needed. If not the test file will be huge and it will make it really hard to update and most importantly when you do a modification on Create a sub-category and if you run the automation, cypress will go through all the test cases even they are not relevant.
As I was saying, Create a product in a specific subcategory
As pre-requests,
In all of these steps, to check the test scenarios of Create a product in a specific subcategory we don't have to go through the login validations, or create category validation or create subcategory validations. We just need a VALID login, VALID category, and a VALID sub-category. Most probably we can have them available before running the test.
so we will be,
Navigating to login with a valid login, select our category and the subcategory ( or you can create new ones ) and then do all the invalid and valid scenario testing to check the Create a product in a specific subcategory. Because it doesn't make sense you running all the login validations when you need to check the create product functionality.
Hope this helps, Cheers
Upvotes: 2
Reputation: 2762
Posting this for anyone else who stumbles upon this question in future and is considering Cypress.io for writing e2e tests.
This blog post on their website summarizes best practices of writing e2e tests.
An excellent talk by Brian Mann shows best practices of writing e2e tests using Cypress.io
Basically we can use commands in Cyprus to perform common actions that need to run before every test.
Answer by Mudithra is perfectly valid for my question to explain in general how we should tackle scenarios where a test is a prerequisite for another test.
Upvotes: 0