Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

End to end testing with cypress #2124

Draft
wants to merge 54 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
8abf534
Added Cypress tests to municipality fact page
Feb 11, 2020
ffc0446
added npm package start-server-and-test for ci scripts
Feb 11, 2020
41950a0
Fixing duplicate pipline names on drone
Feb 11, 2020
38424d3
Merge branch 'master' into test2
Feb 12, 2020
c8e5d0e
Reinstalled Cypress to remove Sizzle build failure
Feb 12, 2020
e7a161c
Drone build fails, using included<version> docker image
Feb 12, 2020
c84c109
Running build in debug mode
Feb 12, 2020
7f25ab0
Using docker image cypress/base:10.16.0
Feb 12, 2020
ef87ebf
Debugging drone failure
Feb 12, 2020
6d931e4
Running with similar drone setup as other environments
Feb 12, 2020
c434275
added step to install dependencies
Feb 12, 2020
4a4abf2
Running build without Cypress
Feb 13, 2020
730b5ea
Added build step to install Cypress dependencies and run tests
Feb 13, 2020
ded2fc8
Fixing drone step error
Feb 13, 2020
d8a2b5d
Added 'depends on deploy' when running test
Feb 13, 2020
099f011
Moved npm run test:ci command to deploy step
Feb 13, 2020
67f70ae
Changed Cypress test script in drone
Feb 13, 2020
3c74ba0
added docker image of cypress
Feb 13, 2020
c3f5819
added docker image of Cypress2
Feb 13, 2020
cbaf546
added npm ci
Feb 13, 2020
48f5011
added Cypress as devdependency
Feb 13, 2020
5445155
Merge branch 'master' into test2
Feb 13, 2020
237a8cf
Merge from master
Feb 13, 2020
66fd312
DOM lib was added to tsconifg to solve type missing error
Feb 13, 2020
07dae00
e2e script added to run Cypress in test environment
Feb 13, 2020
c75dd3d
Added cypress install command to avoid binary missing
Feb 13, 2020
dff6877
Drone not triggering on push
Feb 13, 2020
a86908d
Drone now triggering on push and added cypress install in step
Feb 13, 2020
cdf4d43
Issuing cypress install step
Feb 13, 2020
5c1dfd6
fix cypress install issue
Feb 13, 2020
1bf0565
Checking if Drone error libXtst.so.6 is being solved
Feb 13, 2020
16e5d6b
Using cypress docker image
Feb 13, 2020
a3ff850
set environment variables for test environment
Feb 13, 2020
2717914
removed cross-env in script for e2e
Feb 13, 2020
4f6a3fc
additional script fixing in package.json
Feb 13, 2020
59cdb5f
start-server-and-test added
Feb 13, 2020
c4c1dfe
Fixing and adding cy scripts to be run local and e2e
Feb 14, 2020
599043d
Merge branch 'master' into test2
Feb 14, 2020
233fb73
Instructions for how to run Cypress have been added to readme
Feb 14, 2020
984db25
Merge branch 'master' into test2
Feb 21, 2020
c0c538e
Update package-lock.json
Feb 21, 2020
4afb54e
commenting out drone pipeline for Cypress test
Feb 21, 2020
5e81bbf
Fixes paths to localhost, fixes whitespace from eslint
Glenruben Feb 21, 2020
1ac405d
Comment pipeline separator bc valid yaml is a good idea
Glenruben Feb 21, 2020
e296b75
Uncomments just the test step, no build or deploy here
Glenruben Feb 21, 2020
8be7308
It seems we have to install cypress.
Glenruben Feb 21, 2020
43f3261
We try putting the test before the commented code.
Glenruben Feb 21, 2020
7a1d5b1
Maybe we don't need to install Cypress specifically if we just run th…
Glenruben Feb 21, 2020
cf78d45
Adding test-env specific config file with the right urls and such.
Glenruben Feb 24, 2020
b26c5b4
Adds QA specific test config as well.
Glenruben Feb 24, 2020
1a78b60
Kommenterer ut kjøring av Cypress på Drone
Glenruben Mar 6, 2020
bfd76b2
Merge branch 'develop' into end-to-end-testing-with-Cypress
Glenruben Feb 22, 2024
84c4d80
fix package-lock
Glenruben Feb 22, 2024
7c2b890
Upgrade Cypress to latest version
Glenruben Feb 22, 2024
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 .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
# MABL_ENV_ID_TEST:
# from_secret: mabl-env-test
# commands:
# - npm install -g @mablhq/mabl-cli
# - npm install -g @mablhq/mabl-cli
# - mabl deployments create --api-key $MABL_API_KEY --application-id $MABL_APP_ID --labels MIMIR_SMOKE --environment-id $MABL_ENV_ID_TEST --revision $DRONE_COMMIT_SHA --await-completion
# ---
# kind: pipeline
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ nashorn_code_cache
.enonic
.DS_Store
.project
cypress/screenshots
.dccache
14 changes: 14 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { defineConfig } from 'cypress'

export default defineConfig({
video: false,
responseTimeout: 180000,
e2e: {
// We've imported your old cypress plugins here.
// You may want to clean this up later by importing these.
setupNodeEvents(on, config) {
return require('./cypress/plugins/index.js')(on, config)
},
baseUrl: 'http://localhost:8080',
},
})
5 changes: 5 additions & 0 deletions cypress/cypress.qa.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"baseUrl": "https://www.qa.ssb.no",
"video": false,
"responseTimeout": 180000
}
5 changes: 5 additions & 0 deletions cypress/cypress.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"baseUrl": "https://www.test.ssb.no",
"video": false,
"responseTimeout": 180000
}
Binary file added cypress/downloads/downloads.html
Binary file not shown.
15 changes: 15 additions & 0 deletions cypress/e2e/e2e/homepage.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
describe('Request https://www.test.ssb.no/', () => {
beforeEach(() => {})

it('Check if site is up', () => {
cy.request('https://www.test.ssb.no/')
})
it('Request municipality fact page', () => {
cy.request('https://www.test.ssb.no/kommunefakta')
})
it('Request specific municipality', () => {
cy.request('https://www.test.ssb.no/kommunefakta/ski')
})

// Add more tests here
})
10 changes: 10 additions & 0 deletions cypress/e2e/localhost/a-first-run.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
context('A-warm-up localhost:8080/kommunefakta', () => {
beforeEach(() => {})

it('Run first to see if municipality is working', () => {
cy.request('http://localhost:8080/kommunefakta', {
failOnStatusCode: false,
retryOnNetworkFailure: true
})
})
})
91 changes: 91 additions & 0 deletions cypress/e2e/localhost/kommunefakta.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
describe('Municipality fact page', () => {
before(() => {
cy.visit('/kommunefakta/oslo')
})

it('Get the current url', () => {
cy.url().should('eq', 'http://localhost:8080/kommunefakta/oslo')
})

const getMunicipality = () => {
return cy.request('/kommunefakta/_/service/mimir/municipality?postalCode=0301')
.its('body')
}

it('Get municipality body', () => {
getMunicipality()
.should('deep.equal', {
'municipality': {
'code': '0301',
'displayName': 'Oslo',
'county': {
'name': 'Oslo'
},
'path': '/oslo'
}
})
})

it('Request municipality page Oslo', () => {
cy.request('/kommunefakta/_/service/mimir/municipality?postalCode=0301')
.then((response) => {
expect(response.status).to.eq(200)
expect(response.body).to.have.property('municipality')
expect(response.body).to.not.be.null
})
})
it('Seksjonstitler på kommunefakta', () => {
cy.get('h2')
.should('contain', 'Befolkning')
.should('contain', 'Bolig')
.should('contain', 'Arbeid og utdanning')
.should('contain', 'Kultur')
.should('contain', 'Helse')
.should('contain', 'Kommunens økonomi')
})

it('Befolkning: Check source links', () => {
cy.get('a[href*="08425"]').should('have.attr', 'href', 'https://www.ssb.no/statbank/table/08425')
cy.get('a[href*="folkemengde"]').should('have.attr', 'href', 'https://www.ssb.no/folkemengde')
cy.get('a[href*="07459"]').should('have.attr', 'href', 'https://www.ssb.no/statbank/table/07459')
cy.get('a[href*="01222"]').should('have.attr', 'href', 'https://www.ssb.no/statbank/table/01222')
cy.get('a[href*="04231"]').should('have.attr', 'href', 'https://www.ssb.no/statbank/table/04231')
cy.get('a[href*="09588"]').should('have.attr', 'href', 'https://www.ssb.no/statbank/table/09588')
cy.get('a[href*="01222"]').should('have.attr', 'href', 'https://www.ssb.no/statbank/table/01222')
cy.get('a[href*="11668"]').should('have.attr', 'href', 'https://www.ssb.no/statbank/table/11668')
})

it('Bolig: Check source links', () => {
cy.get('a[href*="06265"]').should('have.attr', 'href', 'https://www.ssb.no/statbank/table/06265/')
cy.get('a[href*="05467"]').should('have.attr', 'href', 'https://www.ssb.no/statbank/table/05467/')
cy.get('a[href*="06520"]').should('have.attr', 'href', 'https://www.ssb.no/statbank/table/06520/')
cy.get('a[href*="09747"]').should('have.attr', 'href', 'https://www.ssb.no/statbank/table/09747')
cy.get('a[href*="01222"]').should('have.attr', 'href', 'https://www.ssb.no/statbank/table/01222')
cy.get('a[href*="11046"]').should('have.attr', 'href', 'https://www.ssb.no/statbank/table/11046/')
})

it('Arbeid og utdanning: Check source links', () => {
cy.get('a[href*="11761"]').should('have.attr', 'href', 'https://www.ssb.no/statbank/table/11761')
cy.get('a[href*="12025"]').should('have.attr', 'href', 'https://www.ssb.no/statbank/table/12025')
})

it('Kultur: Check source links', () => {
cy.get('a[href*="12061"]').should('have.attr', 'href', 'https://www.ssb.no/statbank/table/12061')
cy.get('a[href*="12060"]').should('have.attr', 'href', 'https://www.ssb.no/statbank/table/12060')
cy.get('a[href*="kultur_kostra"]').should('have.attr', 'href', 'https://www.ssb.no/kultur_kostra')
})

it('Helse: Check source links', () => {
cy.get('a[href*="12005"]').should('have.attr', 'href', 'https://www.ssb.no/statbank/table/12005')
cy.get('a[href*="11996"]').should('have.attr', 'href', 'https://www.ssb.no/statbank/table/11996')
cy.get('a[href*="12003"]').should('have.attr', 'href', 'https://www.ssb.no/statbank/table/12003')
cy.get('a[href*="12292"]').should('have.attr', 'href', 'https://www.ssb.no/statbank/table/12292')
cy.get('a[href*="11875"]').should('have.attr', 'href', 'https://www.ssb.no/statbank/table/11875')
cy.get('a[href*="12209"]').should('have.attr', 'href', 'https://www.ssb.no/statbank/table/12209')
})

it('Kommunens Økonomi: Check source links', () => {
cy.get('a[href*="12134"]').should('have.attr', 'href', 'https://www.ssb.no/statbank/table/12134')
cy.get('a[href*="12137"]').should('have.attr', 'href', 'https://www.ssb.no/statbank/table/12137')
})
})
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": "[email protected]",
"body": "Fixtures are a great way to mock data for responses to routes"
}
21 changes: 21 additions & 0 deletions cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/// <reference types="cypress" />
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************

// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)

/**
* @type {Cypress.PluginConfig}
*/
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
}
25 changes: 25 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// ***********************************************
// This example commands.js 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) => { ... })
20 changes: 20 additions & 0 deletions cypress/support/e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/index.js 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')
Loading
Loading