I have entered the code right, and it worked too. But now i dont know why i am getting same error on different lines of code each time i test. The error comes at the chained commands. Sometimes its a chained Cy.find commands while sometimes its some other chained command.
::EDIT:: I have changed the code a bit tried doing different methods etc, but still getting the same error. So the code below(Code-1) is the cypress commands to execute the integration test. Since this particular test values might change so I made another file to pass all those values as a single object(Code-2).
FYI the code worked first time, when i didn't have Code-2, ie: when i manually inserted all those values.
Code-1:
/* eslint-disable no-undef */
import { cropFileName, testData } from '../test_case/quoteGen'
describe('waste-Quote-Generation-for-Permanant-Client', () => {
beforeEach(() => {
cy.visit('/login');
});
it('user login', () => {
// login
cy.findByPlaceholderText(/username/i).type(testData.username)
cy.findByPlaceholderText(/password/i).type(testData.pass)
cy.get('.newLoginPanelBtn').click();
// navigate to 'Sales' tab.
cy.findByRole('link', {
name: /sales/i,
timeout: 5000
})
.should('be.visible')
.click({ force : true });
// Click on 'Generate Quote'
cy.findByRole('link', {
name: /generate quote/i,
timeout: 5000
}).click({ force : true })
// cy.wait(3000)
// Select Template
cy.findByRole('link', {
name: /template/i,
timeout: 5000
})
.should('be.visible')
.click({ force : true })
// Select Client
if(testData.clientType!=='create')
cy.findByText(testData.client).click()
else{
cy.get('#newSiteName').click();
cy.get('#newSiteName').type(testData.client);
cy.get('#newSiteEmail').click();
cy.get('#newSiteEmail').type(testData.clientEmail);
cy.get('#createNewSite').click();
cy.wait(200);
cy.findByText(testData.client).click()
}
// Choose Type of Waste
if(testData.wasteTypeOpt.newName!==null){
cy.findByText(testData.wasteTypeOpt.name).click()
cy.get('#towAddNewBtn').click();
}else{
cy.findByText(testData.wasteTypeOpt.name).click()
cy.get('#towContinueBtn').click();
}
// Check if Job Card Exist
if(testData.jobCard.new){
cy.findByText(/create job card/i).click();
// Add Job Card and Verify Job Card
cy.get('.jobCardDiv1 .jobCardDivInpContentDiv:nth-child(6) .jobCardDivInp').click();
cy.get('.jobCardDiv1 .jobCardDivInpContentDiv:nth-child(6) .jobCardDivInp').type('1234');
cy.get('#jobCardDate > span:nth-child(2)').click();
cy.get('.MuiButton-textPrimary:nth-child(2) > .MuiButton-label').click();
cy.get('.newJobCardBtnActive').click({ force : true });
}
cy.get('#job-cards-list > div:first').click();
cy.get('.newJobCardBtnActive').click({ force : true })
// Select Attachments
cy.get('#attach-file-list').children().each((_,index, collection) => {
if(index!==3 && testData.attachments.includes(index))
collection.eq(index).click()
})
cy.get('#attach-file-list').children().findByText(cropFileName('safety attachments',25,5,5)).click()
setTimeout(() => {
cy.findByText(/add to attachment/i).click();
}, 3000);
cy.get('#quoteEditorButton').click();
// Click on 'Quote'
cy.get('#updateScopeOfWorkButton').click();
cy.get('#editTableEditorModal').find('tr').eq(0).then(tbrow => {
testData.scopeofWork.map((el, k) => {
cy.wrap(tbrow).findAllByPlaceholderText('Description').dblclick()
cy.wrap(tbrow).findAllByPlaceholderText('Description').type(el.descp)
cy.wrap(tbrow).find('.navbar-button').click();
cy.findAllByText(el.tow).click()
cy.wrap(tbrow).findByPlaceholderText('volume').dblclick()
cy.wrap(tbrow).findByPlaceholderText('volume').type(el.vol)
cy.wrap(tbrow).findByPlaceholderText('Unit').dblclick()
cy.wrap(tbrow).findByPlaceholderText('Unit').type(el.unit)
cy.wrap(tbrow).findByPlaceholderText('pricing').dblclick()
cy.wrap(tbrow).findByPlaceholderText('pricing').type(el.pricing)
if(k<testData.scopeofWork.length-1)
cy.get('#addNewRowScopeOfWork').click()
return 0
})
})
cy.get('#updateTableModalButton').click();
cy.get('#continueGNRTQT').click()
// Insert mail id, Click on Generate Quote.
cy.get('.quote-cnrf-to-layout:nth-child(2) .quote-cnrf-emails-input').click();
cy.get('.quote-cnrf-to-layout:nth-child(2) .quote-cnrf-emails-input').type(testData.email);
cy.get('.quote-cnrf-to-layout:nth-child(3) .quote-cnrf-emails-input').click();
cy.get('.quote-cnrf-emails-input:nth-child(2)').click();
cy.get('.quote-cnrf-emails-input:nth-child(2)').type('asdf');
cy.get('.quote-cnrf-emails-textarea').click();
cy.get('.quote-cnrf-emails-textarea').type('asdf');
if(testData.sendType)
cy.get('#generateandsend').click();
else
cy.get('#approvedQuote').click();
cy.get('.swal2-confirm').click();
})
})
Code 2:
export const testData = {
username : 'Tester',
pass : '##tester001',
tabType : "",
template : /template/i,
clientType : 'permanent', // permanent, temporary, create
client : /geolocated site/i,
clientEmail : null,
wasteTypeOpt: {
name : /dilution pit/i,
newName : null, },
jobCard : {
new : false,
},
attachments : [],
scopeofWork : [
{ descp : 'asdf',
tow : /grease/i,
vol : '10',
unit : '5',
pricing : '2'
}
],
email : '[email protected]',
sendType : true // true => 'Generate and send', false => 'Approved Quote'
}
export const cropFileName = (str, len, frnt, lst) => {
RegExp.escape = function(string) {
return string.replace(/[-\\^$*+?.()|[\]{}]/g, '\\$&')
};
let lastIndx = str ? str.length : 0
if(lastIndx <= len){
return new RegExp(str, "i")
}
else{
console.log('NewREgExp=>',new RegExp(RegExp.escape(str.substring(0,frnt)+'...'+str.substring(lastIndx-lst,lastIndx))))
return new RegExp(RegExp.escape(str.substring(0,frnt)+'...'+str.substring(lastIndx-lst,lastIndx)))
}
}
// ENCASE STRING in CASE INSENSITIVE \i
The 'cropFileName' function is used to manage all those long names. The long names will be snipped in CSS or JS by frontend, 'cropFileName' helps to determine the length of the string and decide whether to add '.' in between the string for RegEx conversion.