Skip to content

Commit

Permalink
Added helper methods for single right delegations in playwright and m…
Browse files Browse the repository at this point in the history
…ade changes in cypress tests (#922)

* Added helper methods for single right delegations in playwright and made changes in cypress tests

* Merge conflicts resolved

* Update Dockerfile

* Update backend/src/Altinn.AccessManagement.UI/Altinn.AccessManagement.UI/Altinn.AccessManagement.UI.csproj

* Update backend/src/Altinn.AccessManagement.UI/Altinn.AccessManagement.UI.Tests/Altinn.AccessManagement.UI.Tests.csproj

* Update backend/src/Altinn.AccessManagement.UI/Altinn.AccessManagement.UI/Altinn.AccessManagement.UI.csproj

* Update backend/src/Altinn.AccessManagement.UI/Dockerfile

* Update cypress/package.json

* Update package.json

* Update package.json

* Update package.json

* Update package.json
  • Loading branch information
sneha-sirure authored May 28, 2024
1 parent 714cd7c commit 627813c
Show file tree
Hide file tree
Showing 17 changed files with 757 additions and 345 deletions.
6 changes: 3 additions & 3 deletions cypress/pageObjects/profile3/APIadministration.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export const apiDelegering = {
apiAdministrationPanel: '#apiAdministrationPanelHeader',
searchForOrgOrAPI: '*[class^="fds-search-field-"]',
searchForOrgOrAPI: 'input[type="search"]',
searchedOrgResultContainer: '*[class^="_actionBarWrapper_"]',
listOfOrgsOrAPIs: '*[class^="_baseListItemContent_"]',
seachedAPIResultContainer: '*[class^="_delegableApisContainer"]',
seachedAPIResultContainer: ':nth-child(1) > *[class^="_delegableApisContainer"]',
selectedAPIsForDelegationResultContainer: ':nth-child(2) > *[class^="_delegableApisContainer"]',
apiListInConfirmationPage: '*[class^="_listContainer_"]',
orgListInConfirmationPage: '*[class^="_baseListItemContent"]',
orgInDelegationsOverviewPage: '*[class^="_actionBarWrapper"]',
previousDelegatedOrgsContainer: '*[class^="_delegableOrgsContainer_"]',
previousDelegatedOrgsContainer: '*[class^="_actionBarWrapper_"]',
};
28 changes: 10 additions & 18 deletions cypress/src/e2e/profile/APIdelegering.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,38 +185,30 @@ describe('API delegering tests', () => {

//click option in filter, click same option again and verify if it resets
cy.contains('Testdepartement').click();
cy.wait(200);
cy.get('input[type="checkbox"]').should('be.checked');

cy.contains('button', `Testdepartement`).find('[type=checkbox]').should('be.checked');
cy.contains('Testdepartement').click();
cy.contains('Testdepartement').siblings().should('not.be.checked');
cy.contains('button', `Testdepartement`).find('[type=checkbox]').should('not.be.checked');

//select Testdepartement option from filter and verify only APIs with Testdepartement as provider is listed
cy.contains('Testdepartement').click();
cy.get('input[type="checkbox"]').should('be.checked');
cy.contains('button', `Testdepartement`).find('[type=checkbox]').should('be.checked');
cy.get('button').contains(new RegExp('^Bruk$', 'g')).should('be.enabled').click();
cy.get(
':nth-child(1) > *[class^="_delegableApisContainer"] > *[class^="_actionBarWrapper"]',
).each(($ele) => {
cy.wrap($ele).should('contain', 'Testdepartement');
// .and('not.contain', 'Digitaliseringsdirektoratet');
cy.get('button').contains('Filtrer på etat').click();
//cy.get('button').contains('Filtrer på etat').click();
//cy.contains('')
});

//click on Add for first element in the list and verify if it is listed under Valgte API
cy.get(apiDelegering.searchForOrgOrAPI, { timeout: 1000 })
.eq(1)
.first()
.type('Maskinporten Schema - AM - K6');
//searching for API in seach field to mach the exact string. Ref: https://stackoverflow.com/a/57894080
cy.get(apiDelegering.seachedAPIResultContainer)
.contains(new RegExp('^' + 'Maskinporten Schema - AM - K6' + '$', 'g'))
.click();
//clicking Add button for adding API to the list
cy.get(`button[aria-label="Legg til Maskinporten Schema - AM - K6"]`).first().click();
cy.get(apiDelegering.selectedAPIsForDelegationResultContainer).should('not.be.empty');
cy.get(
':nth-child(2) > *[class^="_delegableApisContainer"] > *[class^="_actionBarWrapper"]',
).each(($ele) => {
cy.get('*[class^="_actionBarTexts_"]').each(($ele) => {
cy.wrap($ele)
.should('contain', 'Testdepartement')
.and('not.contain', 'Digitaliseringsdirektoratet');
Expand Down Expand Up @@ -448,9 +440,9 @@ describe('API delegering tests', () => {
cy.contains('Gi og fjerne API tilganger', { timeout: 6000 }).should('be.visible').click();
cy.contains('Deleger nytt API').click();
cy.get('h1').should('contain', 'Gi tilgang til nytt API');
cy.get(apiDelegering.searchForOrgOrAPI, { timeout: 1000 })
.eq(1)
.type('Maskinporten Schema - AM - K6 - NUF');
cy.get(apiDelegering.searchForOrgOrAPI, { timeout: 1000 }).type(
'Maskinporten Schema - AM - K6 - NUF',
);
cy.get('*[class^="_actionBarActions_"]').first().click();
cy.get('.fds-alert').should(
'have.text',
Expand Down
12 changes: 6 additions & 6 deletions cypress/src/support/APIadministration.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Cypress.Commands.add('chooseOrgToDelegateAPI', (supplierOrg, supplierOrgName) =>
cy.wait(1000);
cy.get('h1').should('contain', 'Gi tilgang til nytt API');
cy.get('h2').should('contain', 'Ny virksomhet?');
cy.get(apiDelegering.searchForOrgOrAPI, { timeout: 1000 }).eq(1).type(supplierOrg);
cy.get(apiDelegering.searchForOrgOrAPI, { timeout: 1000 }).type(supplierOrg);
cy.get('h4').should('contain', 'Virksomheter basert på ditt søk');
cy.get(apiDelegering.searchedOrgResultContainer, { timeout: 1000 }).should(
'contains.text',
Expand All @@ -49,13 +49,13 @@ Cypress.Commands.add('chooseOrgToDelegateAPI', (supplierOrg, supplierOrgName) =>
Cypress.Commands.add('chooseAPIToBeDelegated', (apiName) => {
cy.contains('Deleger nytt API').click();
cy.get('h1').should('contain', 'Gi tilgang til nytt API');
cy.get(apiDelegering.searchForOrgOrAPI, { timeout: 1000 }).eq(1).type(apiName);
cy.get(apiDelegering.searchForOrgOrAPI, { timeout: 1000 }).type(apiName);
//searching for API in seach field to mach the exact string. Ref: https://stackoverflow.com/a/57894080
cy.get(apiDelegering.seachedAPIResultContainer)
.contains(new RegExp('^' + apiName + '$', 'g'))
.click();
//clicking Add button for adding API to the list
cy.get(`button[aria-label="Legg til ${apiName}"]`).first().click();
cy.get('button[aria-label*="Legg til"]').first().click();
});

Cypress.Commands.add('verifyAPIselectedForDelegation', (apiName) => {
Expand Down Expand Up @@ -140,7 +140,7 @@ Cypress.Commands.add('filterAPIUsingAPIProvidersFilterAndAddAPI', (apiName) => {
cy.get('button').contains('Filtrer på etat').click();
cy.wait(1000);
cy.contains('Testdepartement').click();
cy.get('input[type="checkbox"]').should('be.checked');
cy.contains('button', `Testdepartement`).find('[type=checkbox]').should('be.checked');
cy.get('button').contains(new RegExp('^Bruk$', 'g')).should('be.enabled').click();

//clicking Add button for adding API
Expand Down Expand Up @@ -187,14 +187,14 @@ Cypress.Commands.add(
);

Cypress.Commands.add('addAPIToListAndMakeItReadyToAddNextAPI', (apiName) => {
cy.get(apiDelegering.searchForOrgOrAPI, { timeout: 1000 }).eq(1).type(apiName);
cy.get(apiDelegering.searchForOrgOrAPI, { timeout: 1000 }).type(apiName);
//searching for API in seach field to mach the exact string. Ref: https://stackoverflow.com/a/57894080
cy.get(apiDelegering.seachedAPIResultContainer)
.contains(new RegExp('^' + apiName + '$', 'g'))
.click();
//clicking Add button for adding API to the list
cy.get(`button[aria-label="Legg til ${apiName}"]`).first().click();
cy.get(apiDelegering.searchForOrgOrAPI, { timeout: 1000 }).eq(1).type('{selectall}{backspace}');
cy.get(apiDelegering.searchForOrgOrAPI, { timeout: 1000 }).type('{selectall}{backspace}');
});

Cypress.Commands.add('addMultipleAPIsToDelegateAPI', (apiName1, apiName2, apiName3) => {
Expand Down
19 changes: 15 additions & 4 deletions playwright/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,19 @@ Team Autorisasjon has adopted Playwright as key tool for automating end-to-end t
Run the below command to run Playwright tests with the environment in headless mode

```cmd
yarn run env:at22,
yarn run env:at23,
yarn run env:at24,
yarn run env:tt02
yarn run env:AT22,
yarn run env:AT23,
yarn run env:AT24,
yarn run env:TT02
```
Run the below command to run Playwright tests with the environment in UI mode

```cmd
yarn run env:AT22 --ui
```
Run the below command to see playwright autogenerated report after passing test

```cmd
yarn playwright show-report
```

3 changes: 2 additions & 1 deletion playwright/config/.env.at21
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
BASE_URL = "https://at21.altinn.cloud"
ENV_NAME="at21"
BASE_URL="https://at21.altinn.cloud"
3 changes: 2 additions & 1 deletion playwright/config/.env.at22
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
BASE_URL = "https://at22.altinn.cloud"
ENV_NAME="at22"
BASE_URL="https://at22.altinn.cloud"
3 changes: 2 additions & 1 deletion playwright/config/.env.at23
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
BASE_URL = "https://at23.altinn.cloud"
ENV_NAME="at23"
BASE_URL="https://at23.altinn.cloud"
3 changes: 2 additions & 1 deletion playwright/config/.env.at24
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
BASE_URL = "https://at24.altinn.cloud"
ENV_NAME="at24"
BASE_URL="https://at24.altinn.cloud"
23 changes: 4 additions & 19 deletions playwright/e2eTests/idPortenLogin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,10 @@
/* eslint-disable import/no-named-as-default-member */
import { chromium, test } from '@playwright/test';

test('Login with TestID', async () => {
const browser = await chromium.launch();
const context = await browser.newContext();
const page = await context.newPage();
import { loginWithUser } from 'playwright/pages/loginPage';

console.log(process.env.BASE_URL);
await page.goto(process.env.BASE_URL as string);
await page.click("'Logg inn/Min profil'");
await page.click('//*[@id="testid1"]');
await page.getByLabel('Personidentifikator (').fill('03857298151');
await page.getByRole('button', { name: 'Autentiser' }).click();
test('Login with TestID', async ({ page, context }) => {
const login = new loginWithUser(page);

//to open new tab in same window
//const page1 = await context.newPage();
//await page1.goto(process.env.BASE_URL as string);

//to open session in incognito mode

const newContext = await browser.newContext();
const newPage = await newContext.newPage();
await newPage.goto(process.env.BASE_URL as string);
await login.gotoLoginPage('03835898554', page);
});
73 changes: 73 additions & 0 deletions playwright/e2eTests/singleRightsDelegering.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/* eslint-disable import/default */
/* eslint-disable import/no-named-as-default-member */

import { test } from './../fixture/pomFixture';

test('User A who is DAGL/HADM for org delegates resources/Altinn 3 app/Altinn 2 services to User B', async ({
login,
delegate,
delegateRights,
deleteRights,
logoutUser,
coverebyRights,
context,
page,
}) => {
await login.gotoLoginPage('03835898554', page);
await login.chooseReportee('OPPKLARENDE OMKOMMEN TIGER AS', page);

//To delete rights - setup
// GIVEN user without delegated rights to ROMANTISK ESKE
await deleteRights.revokeRightsSSN('ROMANTISK ESKE');

//To delegate rights
// WHEN user delegates to ROMANTISK ESKE
await delegate.delegateToSSN('11868898854', 'ESKE');
await delegateRights.delegateRightsToSSN('Ressurs for enkeltrettigheter testing');
await delegateRights.delegateRightsToSSN('Automatiseringstest for Access Management');
await delegateRights.delegateRightsToSSN('Altinn2 reporting service for authorization tests');
await logoutUser.gotoLogoutPage('OPPKLARENDE OMKOMMEN TIGER AS', page);
// await context1.close();
await context.clearCookies();

//Login with covereby User

await login.gotoLoginPage('11868898854', page);
await login.chooseReportee('OPPKLARENDE OMKOMMEN TIGER AS', page);
await coverebyRights.checkCoverebyRights();
// await context.close();
});

test('User A who is DAGL/HADM for org delegates resources/Altinn 3 app/Altinn 2 services to Org B', async ({
login,
delegate,
delegateRights,
deleteRights,
logoutUser,
coverebyRights,
context,
page,
}) => {
await login.gotoLoginPage('03835898554', page);
await login.chooseReportee('OPPKLARENDE OMKOMMEN TIGER AS', page);

//To delete rights - setup
// GIVEN user without delegated rights to ROMANTISK ESKE
await deleteRights.revokeRightsSSN('GJESTFRI RESERVERT HUND DA');

//To delegate rights
// WHEN user delegates to
await delegate.delegateToOrg('310832170', 'GJESTFRI RESERVERT HUND DA');
await delegateRights.delegateRightsToSSN('Ressurs for enkeltrettigheter testing');
await delegateRights.delegateRightsToSSN('Automatiseringstest for Access Management');
await delegateRights.delegateRightsToSSN('Altinn2 reporting service for authorization tests');
await logoutUser.gotoLogoutPage('OPPKLARENDE OMKOMMEN TIGER AS', page);
// await context1.close();
await context.clearCookies();

//Login with covereby User

await login.gotoLoginPage('21908498426', page);
await login.chooseReportee('OPPKLARENDE OMKOMMEN TIGER AS', page);
await coverebyRights.checkCoverebyRights();
});
40 changes: 40 additions & 0 deletions playwright/fixture/pomFixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { test as baseTest } from '@playwright/test';
import { use } from 'chai';
import { loginWithUser, logoutWithUser } from 'playwright/pages/loginPage';
import {
delegateRightsToUser,
delegateToUser,
revokeRights,
coverebyUserRights,
} from 'playwright/pages/profile/delegationPage';

// Define the fixtures
const test = baseTest.extend<{
login: loginWithUser;
delegate: delegateToUser;
delegateRights: delegateRightsToUser;
deleteRights: revokeRights;
logoutUser: logoutWithUser;
coverebyRights: coverebyUserRights;
}>({
login: async ({ page }, use) => {
await use(new loginWithUser(page));
},
delegate: async ({ page }, use) => {
await use(new delegateToUser(page));
},
delegateRights: async ({ page }, use) => {
await use(new delegateRightsToUser(page));
},
deleteRights: async ({ page }, use) => {
await use(new revokeRights(page));
},
logoutUser: async ({ page }, use) => {
await use(new logoutWithUser(page));
},
coverebyRights: async ({ page }, use) => {
await use(new coverebyUserRights(page));
},
});

export { test };
Loading

0 comments on commit 627813c

Please sign in to comment.