Part 19 Cypress Data Driven Tests | Working with Files/Fixtures
HTML-код
- Опубликовано: 11 сен 2024
- In this video I've shown
1. Working with Files/Fixtures in Cypress?
2. Data Driven Tests
3. Run Test Against Multiple Set of Data
4. Cypress Commands used
a. cy.fixture()
b. cy.readFile() &
c. cy.writeFile()
JAVASCRIPT
• JavaScript Tutorial fo...
FRAMEWORK, ASSERTION, REPORT
• JavaScript Testing Fra...
ELEMENT LOCATOR
jQuery -
• jQuery - find UI eleme...
CSS SELECTOR
• Learn CSS Selectors (i...
XPath
• Master XPath for UI Au...
Nodejs Basics • Nodejs Basics
WEB & API CONCEPTS
Important API Testing Concepts - API TESTING 101
• Important API Testing ...
Learn API Testing using Postman
• Learn API Testing usin...
Github Link: -
github.com/qab...
Conduit App link: -
react-redux.re...
Nice course! Possible to add one for data handling for cypress through excel sheet or .csv?
Sure, I will try to add it
@@QABoxLetsTest Sure, that would be really nice, since we couldn't find any single content across for cypress data automation via excel sheet :) ! & Thanks for the quick response though!!!
I tried to perform fetching of data from the fixtures but I am getting "Cannot read property 'userDetails' of undefined
"
inside the describe suite, i have created a it block
before the it block, i have used before each and used the fixtures to get the data and store it in the variable
tried to use the variable to fetch the data and use them in the script.
Could you please help in here?
Kindly check the code here
www.github.com/qaboxletstest/Cypress-Demo/tree/master/cypress%2Fintegration%2FQABOX%2FTC_15_DataDriven.spec.js
What if i have multiple data like 100 set of data for login in single fixture file how can i iterate and test it
Even simpler than what I've explained, follow the steps
1. cy.fixture your data file with array of credential objects
2. Use then method and in then method callback you will have array of credentials as an argument, let's call it creds
3. Inside then callback function do creds.forEach and afterwards it's straightforward
Write describe and it blocks like I've shown in the video and supply the data from each cred object like cred.email and cred.password
Hope that answers your question
@@QABoxLetsTest
No still i am not able to do so
My data is in this format
{
"cred": [
{
"un": "cat",
"pw": "ca1"
},
{
"un": "dog",
"pw": "da1"
}
]
}
So how can i iterate this data
If you use this format then you have to say nameofimport.cred.forEach and then follow the steps mentioned above.
Could you explain Writing to the fixture file as well? I have to cover SIgn-up flow and want a different username every time.
Thanks
You have to use both cy.readFile() and cy.writeFile() to achieve this. You can write something like:
cy.readFile("cypress/fixtures/dataFile.json", (err, data) => {
if (err) {
return console.error(err);
};
}).then((data) => {
data.table[0].number = 3
data.table[1].number = 4
cy.writeFile("cypress/fixtures/dataFile.json", JSON.stringify(data))
})
Assuming the fixture file would read
{
table: [
{
name: 'Joe',
number: 1,
},
{
name: 'Bob',
number: 2,
},
],
};
Hello, i have a json file which loads and does not change when i select from dropdown.
For example my fixture file has both negative and positive values.
how to make it display only positive values when i select positive.
the data are not getting refreshed
Hey, couldn't make out what you are doing in here. You select and drop-down and want your json file to be filtered. These are two different operations, one happens on app and other on file.
@@QABoxLetsTest no what i want is that my mock network request display the correct info when i select from a dropdown
Current it is displaying just the fixture file without applying the select
So you loaded the drop-down via fixture file by mocking the api call. Now you want some default item to be selected in that. Right?
If so then an item is selected when it has a selected attribute added to it. So, if that isn't added, which may happen because at time developers use Javascript to add attributes, you need to add an attribute by yourself. Mocking might have not called the application javascript.
How to read data form xml file please?
how to read data from .csv file in cypress
Use a relevant npm package to read csv file and rest of it remains the same as explained in this series