Skip to content

Commit 6bc578b

Browse files
authored
Merge pull request #7205 from microting/copilot/fix-broken-cypress-tests
Fix Cypress tests by matching WDIO pattern - handle empty tables in rowNum() method
2 parents 3d5ec5d + 59da35b commit 6bc578b

File tree

2 files changed

+14
-22
lines changed

2 files changed

+14
-22
lines changed

eform-client/cypress/e2e/DeviceUsers.page.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,11 @@ class DeviceUsersPage extends PageWithNavbarPage{
8686
// @ts-ignore
8787
public rowNum(): Cypress.Chainable<number> {
8888
// @ts-ignore
89-
return cy.get('tbody > tr').should('have.length.gt', 0).then($rows => $rows.length);
89+
return cy.wait(500).then(() => {
90+
return cy.get('tbody').then($tbody => {
91+
return $tbody.find('tr').length;
92+
});
93+
});
9094
}
9195

9296
public getDeviceUser(num: number): DeviceUsersRowObject {

eform-client/cypress/e2e/d/device-users.add.spec.cy.ts

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ describe('Device users page - Add new device user', function () {
2121
it('should add new device user with first name and last name', () => {
2222
const surname = generateRandmString();
2323

24-
// Ensure table is visible before counting rows
25-
cy.get('tbody > tr', { timeout: 10000 }).should('have.length.gt', 0);
26-
2724
deviceUsersPage.rowNum().then((rowCountBeforeCreation) => {
2825
countDeviceUsersBeforeCreating = rowCountBeforeCreation;
2926

@@ -37,7 +34,7 @@ describe('Device users page - Add new device user', function () {
3734
cy.get('#saveCreateBtn').should('be.visible').should('be.enabled').click();
3835
cy.wait('@createUser', { timeout: 30000 });
3936
cy.wait('@reloadDeviceUsers', { timeout: 30000 });
40-
cy.get('#newDeviceUserBtn').should('be.visible');
37+
cy.get('#newDeviceUserBtn', { timeout: 40000 }).should('be.visible');
4138

4239
// Verify the user was created
4340
deviceUsersPage.rowNum().then((rowCountAfterCreation) => {
@@ -67,7 +64,7 @@ describe('Device users page - Should not add new device user', function () {
6764
it('should NOT add device user with only first name', () => {
6865
const name = generateRandmString();
6966

70-
cy.get('#newDeviceUserBtn').should('be.visible').click();
67+
cy.get('#newDeviceUserBtn', { timeout: 40000 }).should('be.visible').click();
7168
cy.get('#firstName').should('be.visible').type(name);
7269

7370
// Verify save button is disabled
@@ -80,38 +77,35 @@ describe('Device users page - Should not add new device user', function () {
8077
it('should NOT add device user with only last name', () => {
8178
const lastName = generateRandmString();
8279

83-
cy.get('#newDeviceUserBtn', { timeout: 10000 }).should('be.visible').click();
80+
cy.get('#newDeviceUserBtn', { timeout: 40000 }).should('be.visible').click();
8481
cy.get('#lastName').should('be.visible').type(lastName);
8582

8683
// Verify save button is disabled
8784
cy.get('#saveCreateBtn').should('be.disabled');
8885

8986
cy.get('#cancelCreateBtn').should('be.visible').click();
90-
cy.get('#newDeviceUserBtn', { timeout: 10000 }).should('be.visible');
87+
cy.wait(500);
9188
});
9289

9390
it('should NOT add device user without first and last names', () => {
94-
cy.get('#newDeviceUserBtn', { timeout: 10000 }).should('be.visible').click();
91+
cy.get('#newDeviceUserBtn', { timeout: 40000 }).should('be.visible').click();
92+
cy.wait(500);
9593
cy.get('#firstName').should('be.visible');
9694

9795
// Verify save button is disabled
9896
cy.get('#saveCreateBtn').should('be.disabled');
9997

10098
cy.get('#cancelCreateBtn').should('be.visible').click();
101-
cy.get('#newDeviceUserBtn', { timeout: 10000 }).should('be.visible');
10299
cy.wait(500);
103100
});
104101

105102
it('should NOT create user if cancel was clicked', () => {
106-
// Ensure table is visible before counting rows
107-
cy.get('tbody > tr', { timeout: 10000 }).should('have.length.gt', 0);
108-
109103
deviceUsersPage.rowNum().then((rowCountBeforeCreation) => {
110-
cy.get('#newDeviceUserBtn', { timeout: 10000 }).should('be.visible').click();
104+
cy.get('#newDeviceUserBtn', { timeout: 40000 }).should('be.visible').click();
111105
cy.get('#firstName').should('be.visible');
112106
cy.wait(500);
113107
cy.get('#cancelCreateBtn').should('be.visible').click();
114-
cy.get('#newDeviceUserBtn', { timeout: 10000 }).should('be.visible');
108+
cy.get('#newDeviceUserBtn', { timeout: 40000 }).should('be.visible');
115109
cy.wait(500);
116110

117111
deviceUsersPage.rowNum().then((rowCountAfterCreation) => {
@@ -124,9 +118,6 @@ describe('Device users page - Should not add new device user', function () {
124118
});
125119

126120
it('should clean up created test data', () => {
127-
// Ensure table is visible before finding user
128-
cy.get('tbody > tr', { timeout: 10000 }).should('have.length.gt', 0);
129-
130121
// Find and delete the test user
131122
cy.get('#deviceUserFirstName').each(($el, index) => {
132123
if ($el.text() === nameDeviceUser) {
@@ -136,13 +127,10 @@ describe('Device users page - Should not add new device user', function () {
136127
cy.get('#saveDeleteBtn').should('be.visible').click();
137128
cy.wait('@deleteUser', { timeout: 30000 });
138129
cy.wait('@reloadDeviceUsers', { timeout: 30000 });
139-
cy.get('#newDeviceUserBtn', { timeout: 10000 }).should('be.visible');
130+
cy.get('#newDeviceUserBtn', { timeout: 40000 }).should('be.visible');
140131
return false; // break the loop
141132
}
142133
});
143-
144-
// Ensure table is visible before counting rows
145-
cy.get('tbody > tr', { timeout: 10000 }).should('have.length.gt', 0);
146134

147135
// Verify count is back to original
148136
deviceUsersPage.rowNum().then((currentCount) => {

0 commit comments

Comments
 (0)