Skip to content

Commit

Permalink
Merge pull request #1170 from OWASP/feature-mochatest-update
Browse files Browse the repository at this point in the history
fix reporting for mochatests
  • Loading branch information
commjoen authored Dec 25, 2023
2 parents 2f4ba7d + 40ac281 commit dab84a5
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
if: success() || failure()
with:
name: e2e results
path: target/test-classes/e2e/cypress/reports/
path: target/test-classes/e2e/cypress/
- name: Publish Test Report
if: success() || failure()
uses: scacap/action-surefire-report@v1
2 changes: 1 addition & 1 deletion src/test/e2e/cypress/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Go to `CypressIntegrationTest` and run it as a normal unit test in IntelliJ. Thi
a `SpringBootTest` which uses Testcontainers to start running the Cypress tests.
The test then gathers all the output from the Cypress tests and displays them as normal unit test output in IntelliJ.

The reporting of the tests themselves will be located in `target/test-classes/e2e/cypress/reports`.
The reporting of the tests themselves will be located in `target/test-classes/e2e/cypress/reports/mochawesome`.

Please note that cypress requires the templates to have been build first.

Expand Down
1 change: 1 addition & 0 deletions src/test/e2e/cypress/integration/challenges.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ describe('Challenge Tests', () => {
cy.dataCy(ChallengesPage.SUBMIT_TEXTBOX_BTN).click()
cy.dataCy(ChallengesPage.SUCCESS_ALERT).should('contain', 'Your answer is correct!')
cy.dataCy(ChallengesPage.PROGRESS_BAR).should('be.visible').should('not.have.attr', 'aria-valuenow', '0')
cy.screenshot()
})

it('Submitting right answer gives visual cue on homepage that the challenge is successfully solved', () => {
Expand Down
11 changes: 10 additions & 1 deletion src/test/e2e/cypress/integration/themeSwitch.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,21 @@ describe('Theme Switching Tests', () => {
it('Light mode persists on each page', () => {
cy.visit('/')
cy.dataCy(ThemeSwitchPage.LIGHT_MODE_RADIO).click()
cy.screenshot()
cy.wrap(['', 'challenge/challenge-0', 'stats', 'about']).each((endpoint) => {
cy.visit(`/${endpoint}`)
cy.get(ThemeSwitchPage.DARK_MODE).should('not.exist')
})
})

it('Dark mode persists on each page', () => {
cy.visit('/')
cy.dataCy(ThemeSwitchPage.DARK_MODE_RADIO).click()
cy.screenshot()
cy.wrap(['', 'challenge/challenge-0', 'stats', 'about']).each((endpoint) => {
cy.visit(`/${endpoint}`)
cy.get(ThemeSwitchPage.DARK_MODE).should('exist')
})
})
it('A user can switch theme to dark and back to light on each page', () => {
cy.wrap(['', 'challenge/challenge-0', 'stats', 'about']).each((endpoint) => {
cy.visit(`/${endpoint}`)
Expand Down
11 changes: 11 additions & 0 deletions src/test/e2e/cypress/support/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@

// Import commands.js using ES2015 syntax:
import './commands'
import addContext from 'mochawesome/addContext'
import fs from 'fs'

Cypress.on('test:after:run', (test, runnable) => {
const screenshot = `../screenshots/${Cypress.spec.name}/${runnable.parent.title} -- ${test.title}.png`
if (fs.existsSync(screenshot)) {
addContext({ test }, screenshot)
} else {
console.log(screenshot + 'not found')
}
})

// Alternatively you can use CommonJS syntax:
// require('./commands')
5 changes: 4 additions & 1 deletion src/test/e2e/reporter-config.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{
"reporterEnabled": "spec, mochawesome",
"mochawesomeReporterOptions": {
"screenshotOnRunFailure": true,
"video": true,
"videoCompression": true,
"reportDir": "cypress/reports/mochawesome",
"overwrite": false,
"html": false,
"html": true,
"json": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.github.wimdeblauwe.testcontainers.cypress.CypressTestResults;
import io.github.wimdeblauwe.testcontainers.cypress.CypressTestSuite;
import java.io.IOException;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeoutException;
Expand Down Expand Up @@ -54,6 +55,8 @@ List<DynamicContainer> runCypressTests()
Testcontainers.exposeHostPorts(port);

try (CypressContainer container = new CypressContainer().withLocalServerPort(port)) {
container.withMaximumTotalTestDuration(Duration.ofMinutes(15));

container.start();
CypressTestResults testResults = container.getTestResults();

Expand Down

0 comments on commit dab84a5

Please sign in to comment.