Skip to content

Commit

Permalink
test: create login test cases and update PR files (#37)
Browse files Browse the repository at this point in the history
* test: create login test cases and update PR files

* tests: fix env name for cypress variables

* tests: cypress env vars attempt

* tests: fix cypress env action

* tests: cypress with react app env vars

---------

Co-authored-by: Ricardo Campos <ricardo.campos@encora.com>
  • Loading branch information
2 people authored and DerekRoberts committed May 14, 2024
1 parent bf11b95 commit e71b82f
Show file tree
Hide file tree
Showing 13 changed files with 112 additions and 157 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/cypress-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ jobs:
uses: cypress-io/github-action@v4
with:
browser: chrome
env:
CYPRESS_USERNAME: ${{ secrets.BCEID_USERNAME }}
CYPRESS_PASSWORD: ${{ secrets.BCEID_PASSWORD }}

- name: Upload screenshots on failure
uses: actions/upload-artifact@v3
Expand Down Expand Up @@ -48,6 +51,9 @@ jobs:

- name: Cypress run
run: cypress run --browser firefox
env:
CYPRESS_USERNAME: ${{ secrets.BCEID_USERNAME }}
CYPRESS_PASSWORD: ${{ secrets.BCEID_PASSWORD }}

- name: Upload screenshots on failure
uses: actions/upload-artifact@v3
Expand All @@ -74,6 +80,9 @@ jobs:
uses: cypress-io/github-action@v4
with:
browser: edge
env:
CYPRESS_USERNAME: ${{ secrets.BCEID_USERNAME }}
CYPRESS_PASSWORD: ${{ secrets.BCEID_PASSWORD }}

- name: Upload screenshots on failure
uses: actions/upload-artifact@v3
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/merge-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ jobs:
uses: cypress-io/github-action@v4
with:
browser: chrome
env:
CYPRESS_USERNAME: ${{ secrets.BCEID_USERNAME }}
CYPRESS_PASSWORD: ${{ secrets.BCEID_PASSWORD }}

- name: Upload screenshots on failure
uses: actions/upload-artifact@v3
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/pr-open.yml
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,12 @@ jobs:

- name: Cypress run
uses: cypress-io/github-action@v4
env:
CYPRESS_USERNAME: ${{ secrets.BCEID_USERNAME }}
CYPRESS_PASSWORD: ${{ secrets.BCEID_PASSWORD }}
CYPRESS_REACT_APP_KC_URL: ${{ secrets.REACT_APP_KC_URL }}
CYPRESS_REACT_APP_KC_REALM: ${{ secrets.REACT_APP_KC_REALM }}
CYPRESS_REACT_APP_KC_CLIENT_ID: ${{ secrets.REACT_APP_KC_CLIENT_ID }}
with:
browser: chrome
config: baseUrl=https://${{ env.NAME }}-${{ github.event.number }}-app.apps.silver.devops.gov.bc.ca
Expand Down
63 changes: 63 additions & 0 deletions cypress/e2e/smoke-test/login-page.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
describe('Login page test', () => {

let loginPageData: {
title: string,
subtitle: string,
description: string
};

beforeEach(() => {
cy.visit('/');

// Clear cookies and local storage
cy.clearCookies({ log: true })
cy.clearLocalStorage({ log: true })

// Loading test data
cy.fixture('login-page').then((ttls) => {
loginPageData = ttls;
});

});

it('login page is displayed and loads correctly', () => {
cy.getByDataTest('landing-title').should('have.text', loginPageData.title);
cy.getByDataTest('landing-subtitle').should('have.text', loginPageData.subtitle);
cy.getByDataTest('landing-desc').should('have.text', loginPageData.description);
});

it('navigate to the user form page IDIR', () => {
cy.getByDataTest('landing-button__idir').click();
cy.get('#idirLogo').should('be.visible');
});

it('navigate to the user form page BCeID', () => {
cy.getByDataTest('landing-button__bceid').click();
cy.get('#bceidLogo').should('be.visible');
});

it('try to access system using a link without user connected', () => {
cy.visit('https://nrsparwebapp-test-app.apps.silver.devops.gov.bc.ca/dashboard');
cy.getByDataTest('landing-title').should('have.text', loginPageData.title);
});

it.skip('log in with BCeID and validate if after timeout the user is disconnected', () => {
cy.login();
cy.wait(1800000); //wait for 30 minutes 1800000
cy.getByDataTest('landing-title').should('have.text', loginPageData.title);
});

it('log in with BCeID and validate user role', () => {
cy.login();
cy.getByDataTest('header-button__user').click();
cy.get('.user-data').find('p').contains('IDIR: undefined');
});

it('log in with BCeID and validate user information', () => {
cy.login();
cy.getByDataTest('header-button__user').click();
cy.get('.user-data').find('p').contains('NRS Load Test-3');
cy.get('.user-data').find('p').contains('nrpp_test@nrpp.compratech.com');
});

});
27 changes: 0 additions & 27 deletions cypress/e2e/smoke-test/main-page.cy.ts

This file was deleted.

103 changes: 0 additions & 103 deletions cypress/e2e/smoke-test/user-page.cy.ts

This file was deleted.

5 changes: 5 additions & 0 deletions cypress/fixtures/login-page.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"title": "Welcome to SPAR",
"subtitle": "Seed Planning and Registry Application",
"description": "Register and storage your seed and meet your annual reforestation needs using SPAR"
}
16 changes: 0 additions & 16 deletions cypress/fixtures/messages.json

This file was deleted.

6 changes: 0 additions & 6 deletions cypress/fixtures/titles.json

This file was deleted.

4 changes: 0 additions & 4 deletions cypress/fixtures/user.json

This file was deleted.

8 changes: 8 additions & 0 deletions cypress/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,13 @@ declare namespace Cypress {
* cy.createUser('Jhon', 'Doe')
*/
createUser(firstname: string, lastname: string): void

/**
* Custom command to log in on app.
*
* @example
* cy.login()
*/
login(): void
}
}
15 changes: 15 additions & 0 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,18 @@ Cypress.Commands.add('createUser', (firstname, lastname) => {
cy.log(response.body);
});
});

Cypress.Commands.add('login', () => {
const USERNAME = Cypress.env('USERNAME');
const PASSWORD = Cypress.env('PASSWORD');

cy.getByDataTest('landing-button__bceid').click();
cy.get('#bceidLogo').should('be.visible');
cy.get('input[name=user]')
.clear()
.type(USERNAME, { delay: 50 });
cy.get('input[name=password]')
.clear()
.type(PASSWORD, { delay: 50 });
cy.get('input[name=btnSubmit]').click();
});
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@
"build:production": "react-scripts build",
"test": "jest",
"eject": "react-scripts eject",
"lint": "./node_modules/.bin/eslint"
"lint": "./node_modules/.bin/eslint",
"cy:open": "cypress open",
"cy:run" : "cypress run"
},
"eslintConfig": {
"extends": [
Expand Down

0 comments on commit e71b82f

Please sign in to comment.