using multiple data files in 2 context's to run the same test twice with different data #9415
Unanswered
DanW985
asked this question in
Questions and Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi Guys,
Wondered if someone could help me out? I have just started to use Cypress and have hit a bit of a brick wall. Any responses would be greatly received. Please be gentle as not only is Cypress new to me, Java is too :'(
Scenario:
I have one test that I want to run with two different data sources (in this case two JSON files in the "fixtures" folder of the Cypress project.
Problem
The Cypress dashboard tells me that the data is not defined. The test runner does display the 2 different contexts so I assume that the forEach is reading them.
Setup
I have this block of code to define what the available files are called and to assign a context to them;
const availablefixtures = [
{
"name": "testdata",
"context": "1"
},
{
"name": "testdata2",
"context": "2"
}
]
Within the describe block I have this code;
{
//loop through both fixtures
availablefixtures.forEach((availablefixtures) =>
{
describe(availablefixtures.context, () =>
{
beforeEach(function ()
{
cy.fixture(availablefixtures.name).then(function(data)
{
this.data=data ;
})
})
I then have this code to run the test;
//Caling
cy.visit('https://react-redux.realworld.io/#/login?_k=9lnk0q');
cy.get('fieldset.form-group:nth-child(1) > input:nth-child(1)').type(this.data.Username)
cy.get('fieldset.form-group:nth-child(2) > input:nth-child(1)').type(this.data.Password);
cy.get('fieldset.form-group:nth-child(1) > input:nth-child(1)').should('have.value', this.data.Username);
cy.get('fieldset.form-group:nth-child(2) > input:nth-child(1)').should('have.value', this.data.Password);
})
})
})
Beta Was this translation helpful? Give feedback.
All reactions