-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #243 from UTDallasEPICS/experimental/cypress-integ…
…ration-tests Experimental/cypress integration tests
- Loading branch information
Showing
18 changed files
with
334 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const { defineConfig } = require('@badeball/cypress-cucumber-preprocessor'); | ||
|
||
module.exports = defineConfig({ | ||
stepDefinitions: 'cypress/support/step_definitions/**/*.{js,ts}', // Include both JS and TS files | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
async setupNodeEvents(on, config) { | ||
await addCucumberPreprocessorPlugin(on, config); | ||
|
||
on( | ||
'file:preprocessor', | ||
createBundler({ | ||
plugins: [createEsbuildPlugin(config)], | ||
}) | ||
); | ||
|
||
return config; | ||
}, | ||
specPattern: 'cypress/e2e/features/**/*.feature', // Path for feature files | ||
}, | ||
env: { | ||
AUTH0_USERNAME: process.env.CYPRESS_AUTH0_USERNAME, | ||
AUTH0_PASSWORD: process.env.CYPRESS_AUTH0_PASSWORD, | ||
POSTGRES_PRISMA_URL: process.env.POSTGRES_PRISMA_URL, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Gherkin Documentation | ||
[Gherkin Documentation](https://cucumber.io/docs/gherkin/reference/) | ||
|
||
# Cypress Wiki | ||
[Cypress E2E Testing](https://docs.cypress.io/app/end-to-end-testing/writing-your-first-end-to-end-test) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Feature: Homepage Load | ||
|
||
Scenario: User logs in successfully | ||
Given I am on the homepage | ||
When the user clicks the login button | ||
Then the user should be redirected to the Auth0 login page | ||
And the user logs in with valid credentials | ||
Then the user is authenticated and redirected back to the dashboard | ||
|
||
Scenario: User logs out successfully | ||
Given the user is logged in | ||
When the user clicks the logout button | ||
Then the user should be logged out and see the login button | ||
And the user should not be able to access the dashboard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
export class AuthPage { | ||
static enterUsername(username) { | ||
cy.origin( | ||
'https://dev-5qwmxmrqa1bl88h4.us.auth0.com', | ||
{ args: { username } }, | ||
({ username }) => { | ||
cy.get('input[name="username"]').type(username); | ||
} | ||
); | ||
} | ||
|
||
static enterPassword(password) { | ||
cy.origin( | ||
'https://dev-5qwmxmrqa1bl88h4.us.auth0.com', | ||
{ args: { password } }, | ||
({ password }) => { | ||
cy.get('input[name="password"]').type(password); | ||
} | ||
); | ||
} | ||
|
||
static submit() { | ||
cy.origin('https://dev-5qwmxmrqa1bl88h4.us.auth0.com', () => { | ||
cy.get('button[type="submit"]').click(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export class HomePage { | ||
static visit() { | ||
cy.visit('/'); | ||
} | ||
|
||
static verifyTitle() { | ||
cy.title().should('include', 'WCOA Rides'); | ||
} | ||
|
||
static clickLogin() { | ||
cy.contains('button', 'Log In').click(); | ||
} | ||
|
||
static clickLogout() { | ||
cy.contains('button', 'Log Out').click(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/// <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> | ||
// } | ||
// } | ||
// } | ||
|
||
Cypress.Commands.add('login', () => { | ||
const username = Cypress.env('AUTH0_USERNAME'); | ||
const password = Cypress.env('AUTH0_PASSWORD'); | ||
|
||
cy.session('authSession', () => { | ||
cy.visit('/'); | ||
cy.wait(1000); | ||
cy.contains('button', 'Log In').click(); | ||
cy.origin('https://dev-5qwmxmrqa1bl88h4.us.auth0.com', () => { | ||
cy.url().should('include', 'auth0'); | ||
}); | ||
cy.origin( | ||
'https://dev-5qwmxmrqa1bl88h4.us.auth0.com', | ||
{ args: { username, password } }, | ||
({ username, password }) => { | ||
cy.get('input[name="username"]').type(username); | ||
cy.get('input[name="password"]').type(password); | ||
cy.get('button[type="submit"]').click(); | ||
} | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/// <reference types="cypress" /> | ||
|
||
declare global { | ||
// eslint-disable-next-line no-unused-vars | ||
namespace Cypress { | ||
interface Chainable { | ||
login(): Chainable<void>; | ||
} | ||
} | ||
} | ||
|
||
export {}; // This is important to avoid issues with module augmentation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { Given, When, Then } from '@badeball/cypress-cucumber-preprocessor'; | ||
import HomePage from '../../pages/homePage'; | ||
import AuthPage from '../../pages/authPage'; | ||
|
||
const username = Cypress.env('AUTH0_USERNAME'); | ||
const password = Cypress.env('AUTH0_PASSWORD'); | ||
|
||
Given('I am on the homepage', () => { | ||
HomePage.visit(); | ||
}); | ||
|
||
When('the user clicks the login button', () => { | ||
cy.wait(1000); | ||
HomePage.clickLogin(); | ||
}); | ||
|
||
Then('the user should be redirected to the Auth0 login page', () => { | ||
cy.origin('https://dev-5qwmxmrqa1bl88h4.us.auth0.com', () => { | ||
cy.url().should('include', 'auth0'); | ||
}); | ||
}); | ||
|
||
Then('the user logs in with valid credentials', () => { | ||
AuthPage.enterUsername(username); | ||
AuthPage.enterPassword(password); | ||
AuthPage.submit(); | ||
}); | ||
|
||
Then('the user is authenticated and redirected back to the dashboard', () => { | ||
cy.wait(1000); | ||
HomePage.verifyTitle(); | ||
cy.url().should('include', 'dashboard'); | ||
}); | ||
|
||
Given('the user is logged in', () => { | ||
cy.login(); | ||
}); | ||
|
||
When('the user clicks the logout button', () => { | ||
HomePage.visit(); | ||
cy.wait(1000); | ||
HomePage.clickLogout(); | ||
}); | ||
|
||
Then('the user should be logged out and see the login button', () => { | ||
HomePage.verifyTitle(); | ||
cy.contains('button', 'Log In'); | ||
}); | ||
|
||
Then('the user should not be able to access the dashboard', () => { | ||
cy.visit('/dashboardEmployee'); | ||
cy.origin('https://dev-5qwmxmrqa1bl88h4.us.auth0.com', () => { | ||
cy.url().should('include', 'auth0'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
version: '3.8' | ||
services: | ||
e2e_postgres: | ||
image: postgres:latest | ||
container_name: e2e_postgres_db | ||
ports: | ||
- "5433:5432" | ||
environment: | ||
POSTGRES_USER: postgres | ||
POSTGRES_PASSWORD: postgres | ||
POSTGRES_DB: e2e_test_db | ||
volumes: | ||
- e2e_postgres_data:/var/lib/postgresql/data | ||
e2e_websockify: | ||
image: kamehb/websockify | ||
restart: unless-stopped | ||
command: "0.0.0.0:6433 e2e_postgres:5433" | ||
ports: | ||
- "6433:6432" | ||
depends_on: | ||
- e2e_postgres | ||
volumes: | ||
- e2e-websockify-data:/opt/websockify/data | ||
- e2e-websockify-config:/opt/websockify/config | ||
|
||
volumes: | ||
e2e_postgres_data: | ||
driver: local | ||
e2e-websockify-data: | ||
driver: local | ||
e2e-websockify-config: | ||
driver: local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const { PrismaClient } = require('@prisma/client'); | ||
const prisma = new PrismaClient(); | ||
|
||
async function main() { | ||
await prisma.admin.create({ | ||
data: { | ||
email: "[email protected]", | ||
firstName: "E2E", | ||
lastName: "TEST", | ||
phone: "0000000000", | ||
}, | ||
}); | ||
|
||
// Other Seed Data goes here | ||
} | ||
|
||
main() | ||
.catch((e) => { | ||
console.error(e); | ||
process.exit(1); | ||
}) | ||
.finally(async () => { | ||
await prisma.$disconnect(); | ||
}); |
Oops, something went wrong.