I need some help please. i have two functions that i need to pass the value of a variable from one to another and i cant get it to work
these are the functions written in the format that i would use to run them
it("Account Details Status OK button works",() =>{
login();
access_financial_enquiry();
check_f_e_overview_account_details_status_modal_ok();
//logout();
})
it("Account Details Status is updated",() =>{
login();
access_financial_enquiry();
check_f_e_overview_account_details_status_modal_isupdated();
//logout();
})
The functions i am talking about start with check. They are in two seperate its as the first has to use a {force: true} to click a button as it has been covered by another element (i have tried everything i can think of to resolve this and this is the only way i can get it to work)
Ok so in the first function it opens a modal, sets a status different to the value that is on the screen, and clicks another button. Then a status ok modal opens for confirmation and i have to click the ok button. Its this button that is covered by another element and i cant get passed this unless i use force true.
export function check_f_e_overview_account_details_status_modal_ok() {
//CHECK THE STATUS OK BUTTON WORKS
cy.get("[name = 'accountid']").type('GCS_M822')
cy.get('.ng-scope > .glyphicons').click()
//Click the Status edit link
cy.get('.ng-binding > .ng-scope > .glyphicons').click()
//Check what the value of the status is and select another status value
cy.get('h3').contains("Financial Account Status Change").closest("form").find('span').eq(1).then((el) => {
let StatusOk = el.text();
if (StatusOk == "00 (Active)") {
cy.get('.modal-body > :nth-child(2) > .col-sm-9 > .form-control').select('05 (Decline)')
} else //if (StatusOk == "05 (Decline)")
{
cy.get('.modal-body > :nth-child(2) > .col-sm-9 > .form-control').select('00 (Active)')
}
return cy.wrap(StatusOk).as('MyCustomContent')
});
Ok as you can see it i use a wrap and alias to return the value StatusOK. This is the status before we made a change and the variable i want to pass to the next function. This is the last bit of code in the function and i am also using a setStatus (setter) to pass the value.
cy.get('@MyCustomContent').then(($StatusOk) => {
cy.task('setStatus', StatusOk);
});
cy.get('.modal-body > :nth-child(3) > .col-sm-9 > .form-control').type('No Good Reason')
cy.get('.modal-body > :nth-child(4) > .col-sm-9 > .form-control').type('Testing Memo')
cy.get('.btn-primary > .ng-scope').click()
//check the update ok modal appears correctly
cy.get('#updateSuccess').find(".modal-title").contains('Update OK').should('exist')
cy.get('.modal-body').contains('Financial Account Status Change (General) was updated OK').should('exist')
cy.get('.modal-footer').find('.btn').contains('OK').should('exist').scrollIntoView().click({force: true})
}
I have created a index.js file and placed it in my support folder with the following getters and setters
setStatus: (val) => { return (StatusOk = val); }
getStatus: () => { return StatusOk; }
Ok so the 2nd function i have had to create and this logs back in and opens the modal
export function check_f_e_overview_account_details_status_modal_isupdated(){
cy.get(':nth-child(6) > .dropdown > .dropdown-toggle').should('be.visible')
cy.get(':nth-child(6) > .dropdown > .dropdown-toggle').click()
cy.get(':nth-child(6) > .dropdown > .dropdown-menu > :nth-child(2) > a').click()
cy.get("[name = 'accountid']").type('GCS_M822')
cy.get('.ng-scope > .glyphicons').click()
//Check the status has changed
cy.get('.ng-binding > .ng-scope > .glyphicons').click()
This is the getter that i am using to check the StatusOk
cy.task('getStatus').then((StatusOk) => {
cy.get('.col-sm-9 > .form-control-static > .ng-scope > .ng-binding').contains(StatusOk).should('be.visible');
});
//cy.get('.ng-binding').parents('.ng-scope').contains(StatusOk).should('be.visible')
}
The two functions are saved to a utils.js file and the utils file is imported to the first file. When i run my script it is passing but when i check my results it is not included checks for the
setter
`cy.get('@MyCustomContent').then(($StatusOk) => {
cy.task('setStatus', StatusOk);
})
and getter
cy.task('getStatus').then((StatusOk) => {
cy.get('.col-sm-9 > .form-control-static > .ng-scope > .ng-binding').contains(StatusOk).should('be.visible');
});
Hopefully i have explained it enough so someone can help. thanks for taking the time to read my question