Skip to content

Commit 55d5f69

Browse files
committed
Add cypress test
1 parent 9e0702e commit 55d5f69

15 files changed

Lines changed: 1299 additions & 17 deletions

File tree

.github/workflows/cypress.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Cypress Tests
2+
on: [push]
3+
jobs:
4+
cypress-run:
5+
runs-on: ubuntu-latest
6+
# Runs tests in parallel with matrix strategy https://docs.cypress.io/guides/guides/parallelization
7+
# https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs
8+
# Also see warning here https://github.com/cypress-io/github-action#parallel
9+
strategy:
10+
fail-fast: false # https://github.com/cypress-io/github-action/issues/48
11+
matrix:
12+
containers: [1, 2] # Uses 2 parallel instances
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
- name: Cypress run
17+
# Uses the official Cypress GitHub action https://github.com/cypress-io/github-action
18+
uses: cypress-io/github-action@v6
19+
with:
20+
# Starts web server for E2E tests - replace with your own server invocation
21+
# https://docs.cypress.io/guides/continuous-integration/introduction#Boot-your-server
22+
start: npm start
23+
wait-on: "http://localhost:3000" # Waits for above
24+
# Records to Cypress Cloud
25+
# https://docs.cypress.io/guides/cloud/projects#Set-up-a-project-to-record
26+
record: true
27+
parallel: true # Runs test in parallel using settings above
28+
env:
29+
# For recording and parallelization to work you must set your CYPRESS_RECORD_KEY
30+
# in GitHub repo → Settings → Secrets → Actions
31+
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
32+
# Creating a token https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token
33+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

react_frontend/cypress.config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { defineConfig } from "cypress";
2+
3+
export default defineConfig({
4+
projectId: "3v23eo",
5+
allowCypressEnv: false,
6+
7+
e2e: {
8+
setupNodeEvents(on, config) {
9+
// implement node event listeners here
10+
},
11+
},
12+
});
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/// <reference types="cypress" />
2+
3+
// const sizes = ["macbook-11", "macbook-13", "macbook-15", "macbook-16"];
4+
const sizes = ["macbook-16"];
5+
const exercises2 = [
6+
{ id: "follow_line", webGui: true },
7+
{ id: "vacuum_cleaner", webGui: true },
8+
{ id: "autoparking", webGui: true },
9+
{ id: "follow_person", webGui: true },
10+
{ id: "vacuum_cleaner_loc", webGui: true },
11+
{ id: "global_navigation", webGui: true },
12+
{ id: "rescue_people", webGui: true },
13+
{ id: "obstacle_avoidance", webGui: true },
14+
{ id: "3d_reconstruction", webGui: true },
15+
{ id: "amazon_warehouse", webGui: true },
16+
{ id: "montecarlo_laser_loc", webGui: true },
17+
{ id: "montecarlo_visual_loc", webGui: true },
18+
{ id: "marker_visual_loc", webGui: true },
19+
{ id: "laser_mapping", webGui: true },
20+
{ id: "basic_computer_vision", webGui: true },
21+
{ id: "follow_road", webGui: true },
22+
{ id: "pick_place", webGui: false },
23+
{ id: "image_classification", webGui: true },
24+
{ id: "object_detection", webGui: true },
25+
{ id: "drone_gymkhana", webGui: true },
26+
{ id: "power_tower_inspection", webGui: true },
27+
{ id: "end_to_end_visual_control", webGui: true },
28+
{ id: "digital_image_processing", webGui: true },
29+
{ id: "car_junction", webGui: true },
30+
{ id: "machine_vision", webGui: false },
31+
{ id: "labyrinth_escape", webGui: true },
32+
];
33+
const exercises = [{ id: "follow_line", webGui: true }];
34+
35+
context("Exercises", () => {
36+
beforeEach(() => {
37+
cy.visit("http://127.0.0.1:7164/academy/");
38+
// Cypress.on("uncaught:exception", (err, runnable) => {
39+
// // returning false here prevents Cypress from
40+
// // failing the test
41+
// return false;
42+
// });
43+
});
44+
45+
afterEach(() => {
46+
cy.get("#return-academy").click();
47+
});
48+
49+
sizes.forEach((size) => {
50+
exercises.forEach((exercise) => {
51+
it(`Exercise: ${exercise.id}`, () => {
52+
cy.viewport(size);
53+
cy.get(`#${exercise.id}`).click();
54+
cy.contains("academy.py", { timeout: 1000 });
55+
if (exercise.webGui) {
56+
cy.get(`#webgui-container`, { timeout: 1000 });
57+
}
58+
59+
// Test docs
60+
cy.window().then((win) => {
61+
cy.stub(win, "open").as("windowOpen");
62+
});
63+
cy.get("#theory-button").click();
64+
cy.get("@windowOpen").should("have.been.called");
65+
66+
cy.get("@windowOpen")
67+
.its("lastCall.args.0")
68+
.then((newWindowUrl) => {
69+
expect(newWindowUrl.href).to.equal(
70+
"https://jderobot.github.io/RoboticsAcademy/exercises/AutonomousCars/follow_line/"
71+
);
72+
});
73+
74+
cy.get("#info-button").click();
75+
cy.get("@windowOpen").should("have.been.called");
76+
77+
cy.get("@windowOpen")
78+
.its("lastCall.args.0")
79+
.then((newWindowUrl) => {
80+
expect(newWindowUrl.href).to.equal(
81+
"https://jderobot.github.io/RoboticsAcademy/user_guide/"
82+
);
83+
});
84+
85+
cy.get("#forum-button").click();
86+
cy.get("@windowOpen").should("have.been.called");
87+
88+
cy.get("@windowOpen")
89+
.its("lastCall.args.0")
90+
.then((newWindowUrl) => {
91+
expect(newWindowUrl.href).to.equal(
92+
"https://github.com/JdeRobot/RoboticsAcademy/discussions"
93+
);
94+
});
95+
96+
// cy.get("#connect-with-rb").click();
97+
// cy.get("#robotics-backend-state", { timeout: 2000 }).contains(
98+
// "tools_ready",
99+
// { timeout: 10000 }
100+
// );
101+
});
102+
});
103+
});
104+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/// <reference types="cypress" />
2+
3+
context('Loading', () => {
4+
it('Load Home', () => {
5+
cy.visit('http://127.0.0.1:7164/academy/')
6+
})
7+
})
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/// <reference types="cypress" />
2+
3+
context('Themes', () => {
4+
beforeEach(() => {
5+
cy.visit('http://127.0.0.1:7164/academy/')
6+
})
7+
8+
it('Switch Theme', () => {
9+
cy.get('#theme-button').click()
10+
cy.get('#theme-button').children().filter('[data-testid=DarkModeRoundedIcon]')
11+
// cy.get('#theme-button').children().should('have.data-testid', "DarkModeRoundedIcon")
12+
})
13+
})
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "Using fixtures to represent data",
3+
"email": "hello@cypress.io",
4+
"body": "Fixtures are a great way to mock data for responses to routes"
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"id": 8739,
3+
"name": "Jane",
4+
"email": "jane@example.com"
5+
}

0 commit comments

Comments
 (0)