Skip to content

Commit 6393ecd

Browse files
committed
feat: Add Cypress tests with GitHub Actions and GitHub Pages setup
1 parent c286f80 commit 6393ecd

File tree

12 files changed

+95
-86
lines changed

12 files changed

+95
-86
lines changed

.github/workflows/cypress.yml

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- name: Checkout
14-
uses: actions/checkout@v3
14+
uses: actions/checkout@v4
1515

1616
- name: Setup Node.js
17-
uses: actions/setup-node@v3
17+
uses: actions/setup-node@v4
1818
with:
19-
node-version: '18'
19+
node-version: '20.x'
2020

2121
- name: Install dependencies
22-
run: npm install
22+
run: npm ci
2323

2424
- name: Create env file
2525
run: |
@@ -29,13 +29,24 @@ jobs:
2929
"password": "secret_sauce"
3030
}' > cypress.env.json
3131
32-
- name: Run Cypress tests
33-
run: npx cypress run
32+
- name: Cypress run
33+
uses: cypress-io/github-action@v6
34+
with:
35+
browser: chrome
36+
headless: true
3437

35-
- name: Deploy report to GitHub Pages
38+
- name: Upload test results
3639
if: always()
40+
uses: actions/upload-artifact@v4
41+
with:
42+
name: cypress-reports
43+
path: cypress/reports
44+
retention-days: 30
45+
46+
- name: Deploy to GitHub Pages
47+
if: success()
3748
uses: peaceiris/actions-gh-pages@v3
3849
with:
3950
github_token: ${{ secrets.GITHUB_TOKEN }}
4051
publish_dir: ./cypress/reports/html
41-
keep_files: true
52+
enable_jekyll: true

README.md

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ This project contains automated tests for the Sauce Demo website using Cypress w
1111
│ ├── pages/ # Page objects
1212
│ └── support/ # Support files and commands
1313
├── cypress.config.ts # Cypress configuration
14-
├── cypress.env.json # Environment variables (not in git)
15-
├── tsconfig.json # TypeScript configuration
16-
└── package.json # Project dependencies
14+
├── cypress.env.json # Environment variables (gitignored)
15+
├── package.json # Project dependencies
16+
└── tsconfig.json # TypeScript configuration
1717
```
1818

1919
## Prerequisites
@@ -41,17 +41,9 @@ This project contains automated tests for the Sauce Demo website using Cypress w
4141

4242
To run tests in headless mode:
4343
```bash
44-
npx cypress run
44+
npm run cy:run
4545
```
4646

47-
The test report will be generated in `cypress/reports/html/index.html`
47+
## Test Reports
4848

49-
## Features
50-
51-
- TypeScript support
52-
- Page Object Model pattern
53-
- Custom commands for common actions
54-
- Detailed logging using custom Cypress task
55-
- Mochawesome HTML reporter
56-
- GitHub Actions integration
57-
- GitHub Pages for test reports
49+
Test reports are generated using cypress-mochawesome-reporter and can be found in the `cypress/reports/html` directory after test execution.

cypress.config.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,22 @@ import { defineConfig } from 'cypress'
22

33
export default defineConfig({
44
reporter: 'cypress-mochawesome-reporter',
5-
reporterOptions: {
6-
charts: true,
7-
reportPageTitle: 'Sauce Demo Tests Report',
8-
embeddedScreenshots: true,
9-
inlineAssets: true,
10-
saveAllAttempts: false,
11-
},
125
e2e: {
136
setupNodeEvents(on, config) {
147
require('cypress-mochawesome-reporter/plugin')(on);
158

169
// Custom task for logging
1710
on('task', {
1811
log(message) {
19-
console.log(message);
20-
return null;
12+
console.log(message)
13+
return null
2114
},
22-
});
15+
})
2316
},
2417
baseUrl: 'https://www.saucedemo.com',
2518
supportFile: 'cypress/support/e2e.ts',
19+
specPattern: 'cypress/e2e/**/*.cy.ts',
20+
viewportWidth: 1280,
21+
viewportHeight: 720
2622
},
27-
});
23+
})

cypress/e2e/locked-out-user.cy.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { LoginPage } from '../pages/LoginPage'
2+
3+
describe('Locked Out User Test', () => {
4+
const loginPage = new LoginPage()
5+
6+
beforeEach(() => {
7+
loginPage.visit()
8+
})
9+
10+
it('should show error message for locked out user', () => {
11+
cy.task('log', '🔍 Testing locked out user scenario')
12+
cy.login(Cypress.env('lockedOutUser'), Cypress.env('password'))
13+
loginPage.getErrorMessage()
14+
.should('be.visible')
15+
.and('contain', 'Epic sadface: Sorry, this user has been locked out')
16+
})
17+
})

cypress/e2e/login.cy.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.

cypress/e2e/valid-login.cy.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { LoginPage } from '../pages/LoginPage'
2+
3+
describe('Valid Login Test', () => {
4+
const loginPage = new LoginPage()
5+
6+
beforeEach(() => {
7+
loginPage.visit()
8+
})
9+
10+
it('should login successfully with standard user', () => {
11+
cy.task('log', '🔍 Testing valid login scenario')
12+
cy.login(Cypress.env('standardUser'), Cypress.env('password'))
13+
cy.url().should('include', '/inventory.html')
14+
cy.logout()
15+
})
16+
})

cypress/pages/LoginPage.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ export class LoginPage {
44
password: '[data-test="password"]',
55
loginButton: '[data-test="login-button"]',
66
errorMessage: '[data-test="error"]'
7-
};
7+
}
88

99
visit() {
10-
cy.visit('/');
10+
cy.visit('/')
1111
}
1212

1313
getErrorMessage() {
14-
return cy.get(this.selectors.errorMessage);
14+
return cy.get(this.selectors.errorMessage)
1515
}
1616
}

cypress/support/commands.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/// <reference types="cypress" />
22

33
Cypress.Commands.add('login', (username: string, password: string) => {
4-
cy.task('log', `👤 Logging in with username: ${username}`);
5-
cy.get('[data-test="username"]').type(username);
6-
cy.get('[data-test="password"]').type(password);
7-
cy.get('[data-test="login-button"]').click();
8-
});
4+
cy.task('log', `👤 Logging in with username: ${username}`)
5+
cy.get('[data-test="username"]').type(username)
6+
cy.get('[data-test="password"]').type(password)
7+
cy.get('[data-test="login-button"]').click()
8+
})
99

1010
Cypress.Commands.add('logout', () => {
11-
cy.task('log', '👋 Logging out');
12-
cy.get('#react-burger-menu-btn').click();
13-
cy.get('#logout_sidebar_link').click();
14-
});
11+
cy.task('log', '👋 Logging out')
12+
cy.get('#react-burger-menu-btn').click()
13+
cy.get('#logout_sidebar_link').click()
14+
})
1515

1616
declare global {
1717
namespace Cypress {

cypress/support/e2e.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import './commands';
2-
import 'cypress-mochawesome-reporter/register';
1+
import './commands'
2+
import 'cypress-mochawesome-reporter/register'
33

44
beforeEach(() => {
5-
cy.task('log', '🚀 Starting test...');
6-
});
5+
cy.task('log', '🚀 Starting test...')
6+
})

notes/promptv4(working version with GH pages).txt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@ Scenario 2: Locked Out User
66
4.After both scenarios are executed and validated
77
5.Close the browser.
88
6. Allow the MCP Server to complete the code generation.
9-
7.Use the code found in the temp_codegen folder as a reference.
9+
7. Use the code found in the temp_codegen folder as a reference.
1010
8.Transpile the test code to a Cypress framework using TypeScript.
11-
9. Organize the Cypress project without running "cypress open" configure everything by yourself, create the tests(each one should be independent, no dependencies between them), Use the Page Object Model structure. Store reusable data in the fixtures folder(if they are credentials, put them in the cypress.env.json) like test data or expected results.
11+
9. Organize the Cypress project without running "cypress open" configure everything by yourself, create the tests(each one should be independent, no dependencies between them), Use the Page Object Model structure. Store reusable data in the fixtures folder like test data or expected results. if data are credentials, put them in the cypress.env.json
1212
10. In the root directory Create a .gitignore file that excludes node_modules and cypress.env.json.
1313
11. Create a cy task to get detail logs for the actions, and assertions in the terminal, implement it in the framework, just call the cy task to print console logs.
1414
12. Integrate the Cypress Plugin "cypress-mochawesome-reporter" and its latest version, make all the required configurations. Using the latest version there is only 1 dependency required.
1515
13. In the root directory Add a README.md file that documents how to run the tests and describes the project structure.
1616
14. Install dependencies and Run the framework in headless mode by CLI using cypress run. Check that Cypress and all the tests runs without issues. Failures are accepted, framework configuration issues are not.
17-
15. In the root directory Set up a GitHub Actions workflow to install dependencies and run the Cypress tests, The branch name is not main as usualy, it is master.
18-
16. Then, push the latest changes using the GitHub MCP Server root directory to the remote repository. The repo already exists.
19-
17. Using the GitHub MCP Server configure the repository to publish a github page based on on the /cypress/reports/html/index.html file.
17+
15. Check Cypress linting issues and fix them all.
18+
16. In the root directory Set up a GitHub Actions workflow to install dependencies and run the Cypress tests, The branch name is not main as usualy, it is master.
19+
17. Then, push the latest changes using the GitHub MCP Server root directory to the remote repository. The repo already exists.
20+
18. Using the GitHub MCP Server configure the repository to publish a github page based on on the /cypress/reports/html/index.html file.
2021

21-
In the chat post: "Run the 17 steps until all the process is completed."
22+
In the chat post: "Run the 18 steps until all the process is completed."

0 commit comments

Comments
 (0)