I tried to look for answers, but couldn't find. I want to write a function to delete a previously used test organization before I start my tests in testcafe.
It's quite a time-consuming action if to make it through UI. So I wonder if it is possible to use app actions and write a function to delete my test data?
My thoughts are to perform the next steps: 1. find all test organizations I want to delete 2. iterate through each of them, call ShowDeleteOrgModal() method, and after that call DeleteOrganisation() method.
I saw other test tools provide access to application actions using window(). Is there any way I can implement it in testCafe?
The button selector looks like this.
<button class="button_class" onclick="OurApplicationName.ShowDeleteOrgModal('organisation_id');
return false;">Delete Organisation</button>
We had implemented similar idea in cypress this way:
CleanUpOrgs() {
cy.window().then((win) => {
let numberOfOrgs = win.window.$('tr:contains(' + Cypress.env('testOrgName') + ')').length;
while (numberOfOrgs > 0) {
cy.get('table').contains('tr', Cypress.env('testOrgName')).then(elem => {
let orgId = elem[0].id.replace('OurApplicationName_', '');
cy.window().then((win) => {
win.window.OurApplicationName.ShowDeleteOrgModal(orgId);
win.window.OurApplicationName.DeleteOrganisation();
cy.wait(2000);
});
});
numberOfOrgs--;
}
});
},
How can I get access to the window using TestCafe?