Skip to content

Commit

Permalink
Merge pull request #292 from projectEndings/headless_testing
Browse files Browse the repository at this point in the history
Headless testing (resolves #204)
  • Loading branch information
martindholmes committed Mar 20, 2024
2 parents c180a56 + aa305de commit 4eeaa92
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 3 deletions.
36 changes: 35 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,38 @@ jobs:

# Build everything
- name: Run test
run: ant -f ${{ github.workspace }}/build.xml test
run: ant -f ${{ github.workspace }}/build.xml test

browser:
name: Browser Test
runs-on: ubuntu-latest
steps:
# First checkout this repo
- name: Self checkout
uses: actions/checkout@v4

- name: Setup node
uses: actions/setup-node@v4

- name: Install Playwright
run: npm install @playwright/test @types/node

- name: Install Browsers
run: npx playwright install --with-deps chromium

# Build everything
- name: Run test
run: ant -f ${{ github.workspace }}/build.xml test

- name: Run Playwright Tests
run: npx playwright test --config ${{ github.workspace }}/ci/playwright.config.js

- name: Save test results
uses: actions/upload-artifact@v4
if: always()
with:
name: test-results
path: ${{ github.workspace }}/ci/test-results
retention-days: 30


42 changes: 42 additions & 0 deletions ci/playwright.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { defineConfig, devices } from "@playwright/test";

/**
* @see https://playwright.dev/docs/test-configuration
*/
module.exports = defineConfig({
testDir: "tests",
outputDir: "test-results",
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: true,
retries: 0,
workers: 1,
reporter: "list",
use: {
screenshot: {
mode: "on",
fullPage: true,
},
baseURL: "http://127.0.0.1:8080",
},
webServer: {
command: "npx -y http-server ../",
url: "http://127.0.0.1:8080",
reuseExistingServer: false,
},
/* Configure projects for major browsers */
projects: [
{
name: "chromium",
use: { ...devices["Desktop Chrome"] },
},
// {
// name: "firefox",
// use: { ...devices["Desktop Firefox"] },
// },

// {
// name: "webkit",
// use: { ...devices["Desktop Safari"] },
// },
],
});
24 changes: 24 additions & 0 deletions ci/tests/tests.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { test, expect } from "@playwright/test";

test("search page exists", async ({ page }) => {
const response = await page.goto("./test/search.html");
expect(response.status()).toEqual(200);
});

test("search debug exists", async ({ page }) => {
const response = await page.goto("./test/search-debug.html");
expect(response.status()).toEqual(200);
});

test("manual search debug exists", async ({ page }) => {
const response = await page.goto("./test/search-manual-debug.html");
expect(response.status()).toEqual(200);
});

test("tests are successful", async ({ page }) => {
await page.goto("./test/search.html");
const result = page.locator(".complete");
await result.waitFor();
const classList = await result.getAttribute("class");
expect(classList).toContain("success");
});
4 changes: 2 additions & 2 deletions test/testJs/testJs.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,12 +420,12 @@ function runTests() {

function reportResults(msg, succeed) {
let timeSoFar = performance.now() - startTime;
reportDiv.innerHTML = '<p class="' + (succeed ? 'success': 'failure') + '"> Test #' + (currTestNum + 1) + ': ' + msg + '. Time so far: ' + timeSoFar + '.</p>' + reportDiv.innerHTML;
reportDiv.innerHTML = '<p class="' + (succeed ? 'success': 'failure complete') + '"> Test #' + (currTestNum + 1) + ': ' + msg + '. Time so far: ' + timeSoFar + '.</p>' + reportDiv.innerHTML;
if (succeed) {
Sch.clearSearchForm();
currTestNum++;
if (currTestNum >= tests.length) {
reportDiv.innerHTML = '<p class="success">Done! Total time: ' + (performance.now() - startTime) + '.</p>' + reportDiv.innerHTML;
reportDiv.innerHTML = '<p class="success complete">Done! Total time: ' + (performance.now() - startTime) + '.</p>' + reportDiv.innerHTML;
Sch.searchFinishedHook = function () {
};
//Set this back, so we can do other testing manually.
Expand Down

0 comments on commit 4eeaa92

Please sign in to comment.