Cypress fixes

This commit is contained in:
Jamie Curnow 2020-08-06 12:47:24 +10:00
parent 9ce4c3fe2f
commit bf2f13443f
9 changed files with 721 additions and 566 deletions

3
test/.gitignore vendored
View File

@ -1,3 +1,4 @@
.vscode
node_modules
results
cypress/videos

View File

@ -1,15 +1,12 @@
{
"requestTimeout": 30000,
"defaultCommandTimeout": 20000,
"reporter": "mocha-junit-reporter",
"reporter": "cypress-multi-reporters",
"reporterOptions": {
"jenkinsMode": true,
"rootSuiteTitle": "Cypress",
"jenkinsClassnamePrefix": "Cypress.",
"mochaFile": "/results/junit/my-test-output-[hash].xml"
"configFile": "multi-reporter.json"
},
"videosFolder": "/results/videos",
"screenshotsFolder": "/results/screenshots",
"videosFolder": "results/videos",
"screenshotsFolder": "results/screenshots",
"env": {
"swaggerBase": "{{baseUrl}}/api/schema",
"RETRIES": 4

View File

@ -1,13 +1,14 @@
{
"requestTimeout": 30000,
"defaultCommandTimeout": 20000,
"reporter": "junit",
"reporter": "cypress-multi-reporters",
"reporterOptions": {
"mochaFile": "results/junit/my-test-output-[hash].xml"
"configFile": "multi-reporter.json"
},
"video": false,
"screenshotsFolder": "cypress/results/screenshots",
"videos": false,
"screenshotsFolder": "results/screenshots",
"env": {
"swaggerBase": "{{baseUrl}}/api/schema"
"swaggerBase": "{{baseUrl}}/api/schema",
"RETRIES": 0
}
}

View File

@ -2,17 +2,15 @@
describe('Basic API checks', () => {
it('Should return a valid health payload', function () {
cy.wait(2000);
cy.task('backendApiGet', {
path: '/api/',
}).then((data) => {
// Check the swagger schema:
cy.validateSwaggerSchema('get', '/', data);
cy.validateSwaggerSchema('get', 200, '/', data);
});
});
it('Should return a valid schema payload', function () {
cy.wait(2000);
cy.task('backendApiGet', {
path: '/api/schema',
}).then((data) => {

View File

@ -26,7 +26,6 @@ describe('Users endpoints', () => {
path: '/api/users'
}).then((data) => {
cy.validateSwaggerSchema('get', 200, '/users', data);
expect(typeof data).to.be.equal('array');
expect(data.length).to.be.greaterThan(0);
});
});

View File

@ -13,15 +13,16 @@
* Check the swagger schema:
*
* @param {string} method API Method in swagger doc, "get", "put", "post", "delete"
* @param {number} statusCode API status code in swagger doc
* @param {string} path Swagger doc endpoint path, exactly as defined in swagger doc
* @param {*} data The API response data to check against the swagger schema
*/
Cypress.Commands.add('validateSwaggerSchema', (method, path, data) => {
Cypress.Commands.add('validateSwaggerSchema', (method, statusCode, path, data) => {
cy.task('validateSwaggerSchema', {
file: Cypress.env('swaggerBase'),
endpoint: path,
method: method,
statusCode: 200,
statusCode: statusCode,
responseSchema: data,
verbose: true
}).should('equal', null);
@ -32,10 +33,10 @@ Cypress.Commands.add('getToken', () => {
cy.task('backendApiPost', {
path: '/api/tokens',
data: {
identity: "admin@example.com",
secret: "changeme"
identity: 'admin@example.com',
secret: 'changeme'
}
}).then(res => {
cy.wrap(res.result.token);
cy.wrap(res.token);
});
});

9
test/multi-reporter.json Normal file
View File

@ -0,0 +1,9 @@
{
"reporterEnabled": "spec, mocha-junit-reporter",
"mochaJunitReporterReporterOptions": {
"jenkinsMode": true,
"rootSuiteTitle": "Cypress.npm",
"jenkinsClassnamePrefix": "Cypress.npm.",
"mochaFile": "results/junit/cypress.npm.[hash].xml"
}
}

View File

@ -8,6 +8,7 @@
"@jc21/restler": "^3.4.0",
"chalk": "^4.1.0",
"cypress": "^4.12.1",
"cypress-multi-reporters": "^1.4.0",
"cypress-plugin-retries": "^1.5.2",
"eslint": "^7.6.0",
"eslint-plugin-align-assignments": "^1.1.2",
@ -18,7 +19,8 @@
"mocha-junit-reporter": "^2.0.0"
},
"scripts": {
"cypress": "cypress open --config-file=cypress/config/dev.json --config baseUrl=http://127.0.0.1:3081"
"cypress": "cypress open --config-file=cypress/config/dev.json --config baseUrl=${BASE_URL:-http://127.0.0.1:3081}",
"cypress:headless": "cypress run --config-file=cypress/config/dev.json --config baseUrl=${BASE_URL:-http://127.0.0.1:3081}"
},
"author": "",
"license": "ISC"

File diff suppressed because it is too large Load Diff