Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eform-client/cypress/e2e/DeviceUsers.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class DeviceUsersPage extends PageWithNavbarPage{
// @ts-ignore
public rowNum(): Cypress.Chainable<number> {
// @ts-ignore
return cy.get('tbody > tr').should('have.length.gt', 0).then($rows => $rows.length);
return cy.wait(500).then(() => cy.get('tbody > tr').then($rows => $rows.length));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to fail, if there is no tr, this will give an error instead of returning 0, because there is no tr to be found in the dom within the tbody. As seen in the error:

 AssertionError: Timed out retrying after 4000ms: Expected to find element: `tbody > tr`, but never found it.
  at Context.eval (webpack://eform-angular/./cypress/e2e/DeviceUsers.page.ts:89:38)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot look at the above comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're correct - cy.get('tbody > tr') fails when no tr elements exist. Fixed by getting tbody first, then using jQuery's .find('tr').length which returns 0 for empty tables without timing out. Changes in commit 59da35b.

}

public getDeviceUser(num: number): DeviceUsersRowObject {
Expand Down
30 changes: 9 additions & 21 deletions eform-client/cypress/e2e/d/device-users.add.spec.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ describe('Device users page - Add new device user', function () {
it('should add new device user with first name and last name', () => {
const surname = generateRandmString();

// Ensure table is visible before counting rows
cy.get('tbody > tr', { timeout: 10000 }).should('have.length.gt', 0);

deviceUsersPage.rowNum().then((rowCountBeforeCreation) => {
countDeviceUsersBeforeCreating = rowCountBeforeCreation;

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

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

cy.get('#newDeviceUserBtn').should('be.visible').click();
cy.get('#newDeviceUserBtn', { timeout: 40000 }).should('be.visible').click();
cy.get('#firstName').should('be.visible').type(name);

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

cy.get('#newDeviceUserBtn', { timeout: 10000 }).should('be.visible').click();
cy.get('#newDeviceUserBtn', { timeout: 40000 }).should('be.visible').click();
cy.get('#lastName').should('be.visible').type(lastName);

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

cy.get('#cancelCreateBtn').should('be.visible').click();
cy.get('#newDeviceUserBtn', { timeout: 10000 }).should('be.visible');
cy.wait(500);
});

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

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

cy.get('#cancelCreateBtn').should('be.visible').click();
cy.get('#newDeviceUserBtn', { timeout: 10000 }).should('be.visible');
cy.wait(500);
});

it('should NOT create user if cancel was clicked', () => {
// Ensure table is visible before counting rows
cy.get('tbody > tr', { timeout: 10000 }).should('have.length.gt', 0);

deviceUsersPage.rowNum().then((rowCountBeforeCreation) => {
cy.get('#newDeviceUserBtn', { timeout: 10000 }).should('be.visible').click();
cy.get('#newDeviceUserBtn', { timeout: 40000 }).should('be.visible').click();
cy.get('#firstName').should('be.visible');
cy.wait(500);
cy.get('#cancelCreateBtn').should('be.visible').click();
cy.get('#newDeviceUserBtn', { timeout: 10000 }).should('be.visible');
cy.get('#newDeviceUserBtn', { timeout: 40000 }).should('be.visible');
cy.wait(500);

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

it('should clean up created test data', () => {
// Ensure table is visible before finding user
cy.get('tbody > tr', { timeout: 10000 }).should('have.length.gt', 0);

// Find and delete the test user
cy.get('#deviceUserFirstName').each(($el, index) => {
if ($el.text() === nameDeviceUser) {
Expand All @@ -136,13 +127,10 @@ describe('Device users page - Should not add new device user', function () {
cy.get('#saveDeleteBtn').should('be.visible').click();
cy.wait('@deleteUser', { timeout: 30000 });
cy.wait('@reloadDeviceUsers', { timeout: 30000 });
cy.get('#newDeviceUserBtn', { timeout: 10000 }).should('be.visible');
cy.get('#newDeviceUserBtn', { timeout: 40000 }).should('be.visible');
return false; // break the loop
}
});

// Ensure table is visible before counting rows
cy.get('tbody > tr', { timeout: 10000 }).should('have.length.gt', 0);

// Verify count is back to original
deviceUsersPage.rowNum().then((currentCount) => {
Expand Down
Loading