Skip to content

Commit

Permalink
Merge pull request #239 from signadot/cypress-e2e-tests
Browse files Browse the repository at this point in the history
Cypress E2E Tests
  • Loading branch information
daniel-de-vera authored Jun 10, 2024
2 parents cbe836b + 2caab8a commit 6142a19
Show file tree
Hide file tree
Showing 8 changed files with 2,115 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .signadot/ict/cypress-runner.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: cypress
spec:
cluster: "@{cluster}"
labels:
env: "@{env}"
namespace: signadot-tests
image: cypress/included:latest
jobTimeout: 30m
scaling:
manual:
desiredPods: 1
37 changes: 37 additions & 0 deletions .signadot/ict/e2e-tests-job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
spec:
namePrefix: hotrod-cypress-e2e
runnerGroup: cypress
script: |
#!/bin/bash
set -e
# Clone the git repo
echo "Cloning signadot repo"
git clone --single-branch -b $TARGET_BRANCH \
https://github.com/signadot/hotrod.git
# Run the cypress e2e tests
cd hotrod
export CYPRESS_HOTROD_NAMESPACE=$HOTROD_NAMESPACE
export CYPRESS_FRONTEND_SANDBOX_NAME=$FRONTEND_SANDBOX_NAME
export CYPRESS_LOCATION_SANDBOX_NAME=$LOCATION_SANDBOX_NAME
export CYPRESS_ROUTE_SANDBOX_NAME=$ROUTE_SANDBOX_NAME
export CYPRESS_DRIVER_SANDBOX_NAME=$DRIVER_SANDBOX_NAME
npx cypress run
env:
- name: TARGET_BRANCH
value: "@{branch}"
- name: HOTROD_NAMESPACE
value: "@{namespace}"
- name: FRONTEND_SANDBOX_NAME
value: "@{frontend_sandbox_name}"
- name: LOCATION_SANDBOX_NAME
value: "@{location_sandbox_name}"
- name: ROUTE_SANDBOX_NAME
value: "@{route_sandbox_name}"
- name: DRIVER_SANDBOX_NAME
value: "@{driver_sandbox_name}"
routingContext:
sandbox: "@{sandbox}"
uploadArtifact:
- path: hotrod/cypress/videos/hotrod.cy.js.mp4
19 changes: 19 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const { defineConfig } = require("cypress");

module.exports = defineConfig({
e2e: {
video: true,
experimentalStudio: true,
env: {
HOTROD_NAMESPACE: 'hotrod',
SIGNADOT_ROUTING_KEY: '',
FRONTEND_SANDBOX_NAME: '',
LOCATION_SANDBOX_NAME: '',
ROUTE_SANDBOX_NAME: '',
DRIVER_SANDBOX_NAME: '',
},
setupNodeEvents(on, config) {
// implement node event listeners here
},
},
});
42 changes: 42 additions & 0 deletions cypress/e2e/hotrod.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
describe('hotrod spec', () => {
it('request ride',
() => {
var frontendURL = 'http://frontend.' + Cypress.env('HOTROD_NAMESPACE') + ':8080';
// inject routing key
cy.intercept(frontendURL + '/*', (req) => {
req.headers['baggage'] += ',sd-routing-key=' + Cypress.env('SIGNADOT_ROUTING_KEY');
})

cy.visit(frontendURL);
cy.get('#requestRide').click();
cy.get(':nth-child(1) > .col').click();
cy.get(':nth-child(7) > .col > .text-success').click();
cy.get(':nth-child(7) > .col > .text-success').contains(/Driver (.*) arriving in (.*)./);

// check routing context
var frontendSandboxName = Cypress.env('FRONTEND_SANDBOX_NAME');
if (frontendSandboxName === "") {
cy.get(':nth-child(3) > .col > .frontend').should('have.text', 'frontend (baseline)');
} else {
cy.get(':nth-child(3) > .col > .frontend').should('have.text', 'frontend (sandbox=' + frontendSandboxName + ')');
}
var locationSandboxName = Cypress.env('LOCATION_SANDBOX_NAME');
if (locationSandboxName === "") {
cy.get(':nth-child(4) > .col > .location').should('have.text', 'location (baseline)');
} else {
cy.get(':nth-child(4) > .col > .location').should('have.text', 'location (sandbox=' + locationSandboxName + ')');
}
var routeSandboxName = Cypress.env('ROUTE_SANDBOX_NAME');
if (routeSandboxName === "") {
cy.get(':nth-child(6) > .col > .route').should('have.text', 'route (baseline)');
} else {
cy.get(':nth-child(6) > .col > .route').should('have.text', 'route (sandbox=' + routeSandboxName + ')');
}
var driverSandboxName = Cypress.env('DRIVER_SANDBOX_NAME');
if (driverSandboxName === "") {
cy.get(':nth-child(7) > .col > .driver').should('have.text', 'driver (baseline)');
} else {
cy.get(':nth-child(7) > .col > .driver').should('have.text', 'driver (sandbox=' + driverSandboxName + ')');
}
});
})
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/e2e.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

0 comments on commit 6142a19

Please sign in to comment.