Skip to content
This repository has been archived by the owner on May 26, 2024. It is now read-only.

Test with cypress #180

Draft
wants to merge 29 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
2fc1fd9
test features file first draft
savitris Feb 8, 2023
df9f790
test: added scenarios huwelijk planner
savitris Feb 9, 2023
9aff223
test: WIP
savitris Feb 10, 2023
8858564
test feature files added with potential scenarios
savitris Feb 13, 2023
2168518
test: added scenarios + Potential Scenarios + Q's
savitris Feb 14, 2023
ae81bcb
test WIP added scenarios
savitris Feb 15, 2023
ead6c10
+tot Ik Partner 1 wil mijn contactgegevens opslaan
savitris Feb 16, 2023
7dfc062
test: scenario cleanup WIP
savitris Feb 16, 2023
30f1ec4
test Step 0 Musterscenario opruimen WIP
savitris Feb 17, 2023
32b2049
test: scenarios cleanup WIP
savitris Feb 20, 2023
8876556
test README 1st draft
savitris Feb 21, 2023
bb49508
test: added 1st scenario playwright
savitris Feb 22, 2023
d772c40
test: landing-pagina playwright heading -step 0
savitris Feb 23, 2023
cf92322
test: Step 0 commented out of feature files
savitris Feb 23, 2023
be11c28
test: added PRACTICE file with diff methods stp0-2
savitris Feb 24, 2023
22161e6
wip: use cypress cypress-testing-library and cypress-cucumber-preproc…
Yolijn Feb 28, 2023
b2a4d7b
fixup! wip: use cypress cypress-testing-library and cypress-cucumber-…
Yolijn Feb 28, 2023
56e4274
test: WIP cypress
savitris Mar 2, 2023
30df88e
test: WIP added cypress tests
savitris Mar 3, 2023
9e48f77
test: WIP previous progress -error-
savitris Mar 15, 2023
c324157
test: WIP eenvoudighuwelijk tijdslot bevestigd
savitris Mar 15, 2023
dd8d4c3
test: WIP gitignore screenshots videos + testlogs
savitris Mar 17, 2023
240826a
test WIP added "throw new Error" JS Exception
savitris Mar 20, 2023
b88eb1a
test: WIP scenarios in volgorde van verschijnen
savitris Mar 20, 2023
38d3d9b
test WIP Scenario Outline -> NL
savitris Mar 20, 2023
c11f593
test: WIP working tijd and typeHywelijk selectie
savitris Mar 21, 2023
8c49b5e
test: WIP Abstract Scenario en Voorbeelden
savitris Mar 22, 2023
43a1c47
test: WIP added DigID login scenario
savitris Mar 22, 2023
852c82b
TEST: WIP annotations highlighting/cleanup
savitris Mar 27, 2023
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
4 changes: 4 additions & 0 deletions .cypress-cucumber-preprocessorrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"stepDefinitions": "e2e/**/*.spec.ts",
"filterSpecs": true
}
27 changes: 27 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Playwright Tests
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
- name: Install dependencies
run: npm ci
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Run Playwright tests
run: npx playwright test
- uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

# testing
/coverage
/cypress/screenshots/
/cypress/videos/

# next.js
/.next/
Expand Down Expand Up @@ -40,3 +42,9 @@ src/generated/
/public/favicon.ico
playwright-report/
.cache/
/test-results/
/playwright-report/
/playwright/.cache/
/test-results/
/playwright-report/
/playwright/.cache/
48 changes: 48 additions & 0 deletions cucumber-messages.ndjson

Large diffs are not rendered by default.

Empty file added cucumber-report.json
Empty file.
28 changes: 28 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { defineConfig } from 'cypress';
import createBundler from '@bahmutov/cypress-esbuild-preprocessor';
import { addCucumberPreprocessorPlugin } from '@badeball/cypress-cucumber-preprocessor';
import createEsbuildPlugin from '@badeball/cypress-cucumber-preprocessor/esbuild';

export default defineConfig({
e2e: {
baseUrl: 'http://localhost:3000',
//baseUrl: 'https://utrecht-huwelijksplanner.frameless.io/',
specPattern: 'features-cucumber/**/*.feature',
async setupNodeEvents(
on: Cypress.PluginEvents,
config: Cypress.PluginConfigOptions,
): Promise<Cypress.PluginConfigOptions> {
// This is required for the preprocessor to be able to generate JSON reports after each run, and more,
await addCucumberPreprocessorPlugin(on, config);
on(
'file:preprocessor',
createBundler({
plugins: [createEsbuildPlugin(config)],
}),
);

// Make sure to return the config object as it might have been modified by the plugin.
return config;
},
},
});
5 changes: 5 additions & 0 deletions cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "hello@cypress.io",
"body": "Fixtures are a great way to mock data for responses to routes"
}
39 changes: 39 additions & 0 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import '@testing-library/cypress/add-commands';

/// <reference types="cypress" />
// ***********************************************
// This example commands.ts shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
//
// declare global {
// namespace Cypress {
// interface Chainable {
// login(email: string, password: string): Chainable<void>
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
// }
// }
// }
20 changes: 20 additions & 0 deletions cypress/support/e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/e2e.ts is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
97 changes: 97 additions & 0 deletions e2e/common-given.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { Given as Gegeven } from '@badeball/cypress-cucumber-preprocessor';

Gegeven('dat ik op de {string} pagina ben', (path: string) => {
if (path === 'utrecht huwelijksplanner') {
cy.visit('/');
} else {
cy.visit(path);
}
});

//this was giving an error
Gegeven('ik zie de heading {string}', (headingtitle: string) => {
cy.findByRole('heading', { name: headingtitle }).should('be.visible');
//cy.findByRole('heading', { name: text }).as('heading').should('be.visible');
//expect(cy.findByRole('heading', { name: headingtitle })).to.be.visible();
});

// this was giving an error
Gegeven('ik ben op stap {string}', (stepNumber: string) => {
//cy.findByRole('paragraph', { name: /Stap 1 van [0-9]/i }).should('be.visible');
//expect(cy.findByText(/Stap [0-9] van [0-9]/i)).to.be.visible();
//expect(cy.findByText(new RegExp(`Stap ${step} van [0-9]`, 'i'))).to.be.visible();
cy.findByText(new RegExp(`Stap ${stepNumber} van [0-9]+`, 'i')).should('be.visible');
});
//Playwright equivalent
//const step1 = await page.getByRole('paragraph', { name: /Stap 1 van [0-9]/i });
//expect(step1).toBeDefined();

//!!!Empty tests written just so Cypress doesn't complain
Gegeven('ik heb de {string} geselecteerd', (datum: string) => {
cy.log('TODO: FIXME: wachten op een datumprikker');
cy.log(datum);
//cy.pause();
//datum prikker selecteren input type date
//waarde invullen 14/04/2021
});

// Gegeven('ik heb een beschikbare tijdslot geselecteerd', () => {
// if (cy.get('[type="radio"]').first().check()) {
// return true;
// }
// cy.should('be.true');
// // radio value true? should be visible??
// // return 'pending';
// // cy.pause();
// });

Gegeven(
'ik heb een beschikbare {string} geselecteerd voor een {string} huwelijk',
(tijd: string, typeHuwelijk: string) => {
cy.log(tijd);
cy.log(typeHuwelijk);

if (typeHuwelijk === 'Eenvoudig') {
// look for an element with the text
// 'Flits/balie-huwelijk — Stadskantoor', save it as @pimplemees
cy.findByText('Flits/balie-huwelijk — Stadskantoor').as('pimplemees');

// get the @pimplemees element
// find it's siblings (two divs containing 2 children each: an input and a label)
// then look inside those siblings for a label with the "tijd".
cy.get('@pimplemees')
.siblings()
.children()
.contains(tijd) // finds a label with 'tijd' (12:00 - 12:15)
.as('timeSlot');

// then click that label to check the checkbox
cy.get('@timeSlot').click();
} else if (typeHuwelijk === 'Uitgebreid') {
cy.findByText('Flits/balie-huwelijk — Stadskantoor').as('uitgebreid');
cy.get('@uitgebreid')
.siblings()
.children()
.contains(tijd) // finds a label with 'tijd' (12:00 - 12:15)
.as('timeSlot');
cy.get('@timeSlot').click();
}
},
);

Gegeven('ik kan een {string} button zien', (text: string) => {
cy.findByRole('button', { name: text }).should('be.visible');
});

Gegeven('er is een {string} datum prikker op de pagina', (datumType: string) => {
cy.log('TODO: FIXME: wachten op een datumprikker');
cy.log(datumType);
// cy.findByLabelText(datumType).as('datePicker').should('be.visible');
// cy.get('@datePicker').should(`have.attr`, `type`, `date`);
});

Gegeven('ik kan de beschikbare trouwdata zien', () => {
cy.log('TODO: FIXME: wachten op een datumprikker');
// return 'pending';
// cy.pause();
});
124 changes: 124 additions & 0 deletions e2e/common-then.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import { Then as Dan } from '@badeball/cypress-cucumber-preprocessor';

Dan('zie ik de heading {string}', (text: string) => {
cy.findByRole('heading', { name: text }).as('heading').should('be.visible');
//expect(cy.findByRole('heading', { name: headingtitle })).to.be.visible();
});

Dan('ben ik op stap {string}', (stepNumber: string) => {
//cy.findByText(/Stap [0-9] van [0-9]/i).should('include.text', `Stap ${stepNumber}`);
cy.findByText(new RegExp(`Stap ${stepNumber} van [0-9]+`, 'i')).should('be.visible');
});

Dan('zie ik een {string} button', (text: string) => {
cy.findByRole('button', { name: text }).should('have.class', 'utrecht-button');
});

Dan('word ik naar de {string} pagina gestuurd', (path: string) => {
// console.log(cy.location('pathname'));
// console.log(path);
// cy.url().should('include', path);

if (path === 'trouw-opties/huwelijk') {
throw new Error(
'TODO: FIXME: De bug zorgt dat we niet kan werken https://github.com/frameless/utrecht-huwelijksplanner/issues/147',
);
} else {
cy.log(path);
cy.location('pathname').should('include', path);
}
//expect(cy.url()).to.include(path);
});

Dan('is er een {string} datum prikker op de pagina', (datumType: string) => {
cy.findByLabelText(datumType).as('datePicker').should('be.visible');
// cy.get('@datePicker').its('type').should('equal', 'date');

cy.get('@datePicker').should(`have.attr`, `type`, `date`);

// cy.get('@datePicker').invoke('attr', 'type').should('equal', 'date');
});

Dan('kan ik de beschikbare trouwdatums zien', () => {
cy.log('TODO: FIXME: wachten op een datumprikker');
});

Dan('zie ik tijdslot checkbox opties voor trouwen op de geselecteerde dag', () => {
cy.get('time').should('be.visible');
// cy.get('[data-test-id="test-example"]').should('have.length', 6) <- for reference
});

// Dan('de tijdslot checkbox wordt geselecteerd', () => {
// if (cy.get('[type="radio"]').first().check()) {
// return true;
// cy.get('@datePicker').should(`have.attr`, `type`, `date`);
// }
// cy.should('be.true');
// // radio value true? should be visible??
// // return 'pending';
// // cy.pause();
//REPLACEMENT SEE BELOW
// });

Dan('de tijdslot checkbox wordt geselecteerd', () => {
cy.get('[type="radio"]').first().as('first-radio-button');

cy.get('@first-radio-button').should('be.checked');
});

Dan(
'zie ik het correcte {string} huwelijk met de vroeger geselecteerde {string} en {string} combinatie',
(typeHuwelijk: string, datum: string, tijd: string) => {
cy.log(datum, tijd, typeHuwelijk);

cy.get('.utrecht-spotlight-section').should('contain', typeHuwelijk);

// .should('contain', typeHuwelijk);

// datum is written like yyyy-mm-dd, but we want to look for
// day month year
// cy.get('.utrecht-spotlight-section > :nth-child(2)').contains(datum);

// cy.get('[datetime]').contains(datum);
// <time datetime="">2021-04-14</time>

// get an element that has a datetime attribute
// and then check it has a datetime attribute
// with the value '2021-04-14'
// cy.get('[datetime]').should(`have.attr`, `datetime`, datum);

// get an element with a datetime attribute with CSS attribute selectors
// whose value starts with '2021-04-14'
//cy.get(`[datetime^=${datum}]`).should('be.visible');

cy.get('.utrecht-spotlight-section time').should('have.attr', 'datetime').and('contain', datum);

// cy.get('.utrecht-spotlight-section').should('contain', '10:00 - 10:10');
cy.get('.utrecht-spotlight-section').should('contain', tijd);
//'Locatie Stadskantoor - Eenvoudig huwelijkwoensdag 14 april 2021, 10:00 - 10:10Kosten: € 168,00';
},
);

//
// Extra tests voor commented Scenarios
Dan('zie ik een {string} infobox', (heading: string) => {
cy.findByRole('heading', { name: heading })
.parent()
.should('match', 'aside')
.and('have.class', 'utrecht-spotlight-section')
.and('have.class', 'utrecht-spotlight-section--info');
});

Dan('zie ik een {string} button die zich gedraagd als link', (text: string) => {
cy.findByRole('link', { name: text })
.should('have.class', 'utrecht-button-link')
.and('have.class', 'utrecht-button-link--primary-action');
});

Dan('kan ik geen datum selecteren', () => {
cy.log('TODO: FIXME: wachten op een datumprikker');
});

Dan('ik krijg een melding om een datum tussen een jaar te selecteren', () => {
cy.log('TODO: FIXME: wachten op een datumprikker');
});
Loading