I am doing automation testing using Cypress with JavaScript.
I have to manage a test case for add, search and edit user. I have created a different test case for each. After adding user, I verified recent created user by searching it. I also search same user before to edit it.
In Cypress, test cases run in a sequence. My first case for 'add user', second for 'Search user' and last one for 'Edit user'. After adding it automatically perform search actions. But before edit, I have to call all functions which are used in a 'Search' test case. I am using the POM framework.
Here is the code I have written:
describe('User management', function(){
it('Add user', function(){
obj.clickOnAddUserButton()
obj.fillDetails()
obj.clickOnSaveButton()
})
it('Search user', function(){
obj.searchName()
obj.searchRole()
obj.verifyName()
obj.verifyRole()
})
it('Edit user', function(){
obj.searchName()
obj.searchRole()
obj.verifyName()
obj.verifyRole()
obj.editUser()
})
})
Is it possible to call it() from the other it(), like a function we call?
I tried the following solution to understand but I was fail: Cypress - have 1 test call another test and run it
I also go through the following link which doesn't help me: How to call the common test case in other test case in protractor
Let give me an example what I want exactly.
describe('User management', function(){
it('Add user', function(){
obj.clickOnAddUserButton()
obj.fillDetails()
obj.clickOnSaveButton()
})
it('Search user', function(){
obj.searchName()
obj.searchRole()
obj.verifyName()
obj.verifyRole()
})
it('Edit user', function(){
//Here I want to call it() instead of calling same functions here
//i.e. it('Search user')
obj.editUser()
})
})
You can just rearrange the code you already have a little bit.
A test pattern in general is
it('test-name', callbackFunction).You can't nest
it()because the Cypress runner needs to manage those functions for things like retries and reporting results.But you can move
callbackFunctionto make it reuseable.Composing inside the Page Object
It's going to be tidier to compose that
searchUser()function inside the page object itselfSeparating steps from workflows
Or one more abstraction, compose a
UserWorkflowpage object