As I am relatively new to cypress, I am encountering an issue that I could use some help with. In the fixtures folder, there is a TestData.json file that contains the following data:
{
"data1":
{
"Client": "Client1",
"ClientID": "202300001",
"PlanTypes": ["type1", "type2"]
},
"data2":
{
"Client": "Client2",
"ClientID": "202300001",
"PlanTypes": ["type3", "type4", "type5"]
}
}
The website I'm working on has a dropdown list with items like these:
Client Plan Types: "", "type1", "type2", "For Validation" (where "" and "For Validation" are default items while type1 and type2 are dynamic and change per client)
To tackle this, I have successfully extracted these items into an array named "arr1". However, my struggle lies in comparing arr1 with PlanTypes (from fixtures). Also, I need to dynamically add "" and "For Validation" values to PlanTypes before comparison without altering the fixture file itself.
Below is a snippet of my code:
script.js
import filePage from "../../../support/page-objects/filePage";
const filePage = new filePage()
const testDataFile = '/TestData.json'
cy.fixture(testDataFile).then((testData) => {
const msTestData = testData.data1
filePage.checkPlanTypes(msTestData);
});
filePage.js
checkPlanTypes(msTestData) {
let arr1 = []
this.elements.dataPlanTypeList().find('li').each((planTypeData) => {
arr1.push(planTypeData.text().trim())
}).then(() => {
let clientPlanTypes = []
clientPlanTypes.push("")
clientPlanTypes.push(msTestData)
clientPlanTypes.push("For Validation")
expect(clientPlanTypes).to.have.same.members(arr1)
})
}
Upon running the code, an error message appears stating "expected [ Array(4) ] to have the same members as [ Array(3) ]".
I also attempted "
cy.wrap(arr1).should('deep.equal', clientPlanTypes)
", but it resulted in another error: "expected [ Array(4) ] to deeply equal [ Array(3) ]"
When I cy.log(clientPlanTypes)
, the output is "[, [REGULAR, VIP], For Validation]"
If you have any insights or suggestions on how to effectively compare PlanTypes (clientPlanTypes) and arr1, your assistance would be greatly appreciated. Thank you!