-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include Playwright, move some videos and some fixes (#464)
We can now make a build without signing E2E draft tests using playwright Move videos to static folder within renderer Fix error when cancelling flashing Initial not very clever USB tests to check how Electron behaves on testing env.
- Loading branch information
1 parent
631378d
commit f3a9aa5
Showing
22 changed files
with
725 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
name: E2E Tests | ||
on: | ||
push: | ||
branches: | ||
- "*" | ||
- "!main" | ||
- "!development" | ||
pull_request: | ||
branches: | ||
- "*" | ||
- "!main" | ||
- "!development" | ||
jobs: | ||
e2e_test: | ||
timeout-minutes: 60 | ||
runs-on: ${{ matrix.os }} | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
include: | ||
- os: macos-12 | ||
- os: windows-2019 | ||
- os: ubuntu-20.04 | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18 | ||
- run: npm install -g yarn | ||
- if: runner.os == 'Linux' | ||
run: sudo apt update && sudo apt install libudev-dev | ||
- name: Cache node_modules | ||
id: cache-node-modules | ||
uses: actions/cache@v3 | ||
with: | ||
path: node_modules | ||
key: ${{ runner.os }}-${{ hashFiles('package.json', 'yarn.lock') }} | ||
- name: Install node_modules | ||
if: steps.cache-node-modules.outputs.cache-hit != 'true' | ||
run: yarn install --frozen-lockfile --network-timeout 300000 # sometimes yarn takes time, therefore, we increase the timeout | ||
- name: Run Playwright tests | ||
run: yarn playwright test | ||
- uses: actions/upload-artifact@v3 | ||
if: always() | ||
with: | ||
name: playwright-report | ||
path: playwright-report/ | ||
retention-days: 30 |
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 |
---|---|---|
|
@@ -99,4 +99,7 @@ dist | |
|
||
#editor's configuration | ||
.vscode | ||
.idea | ||
.idea | ||
/test-results/ | ||
/playwright-report/ | ||
/playwright/.cache/ |
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,79 @@ | ||
import { _electron as electron, ElectronApplication, test, Page, expect } from "@playwright/test"; | ||
import { findLatestBuild, parseElectronApp } from "electron-playwright-helpers"; | ||
|
||
// this test does not work yet because we need to do something in firmware to avoid having to hold ESC key | ||
test.describe("Testing Bazecor E2E", async () => { | ||
let electronApp: ElectronApplication; | ||
let page: Page; | ||
const outputFolder = "test-results"; | ||
|
||
test.beforeAll(async () => { | ||
const latestBuild = findLatestBuild(); | ||
const appInfo = parseElectronApp(latestBuild); | ||
|
||
electronApp = await electron.launch({ | ||
args: [appInfo.main], | ||
executablePath: appInfo.executable, | ||
}); | ||
|
||
electronApp.on("window", async initialPage => { | ||
const filename = initialPage.url()?.split("/").pop(); | ||
console.log(`Window opened: ${filename}`); | ||
|
||
initialPage.on("pageerror", error => { | ||
console.error(error); | ||
}); | ||
|
||
initialPage.on("console", msg => { | ||
console.log(msg.text()); | ||
}); | ||
}); | ||
}); | ||
|
||
test("renders landing page", async () => { | ||
page = await electronApp.firstWindow(); | ||
await page.screenshot({ path: `${outputFolder}/landing.png` }); | ||
}); | ||
|
||
test("flashing keyboard", async () => { | ||
page = await electronApp.firstWindow(); | ||
const connectButton = page.getByRole("button", { name: "Connect" }); | ||
|
||
expect(connectButton).not.toBe(undefined); | ||
if (connectButton) { | ||
console.log(connectButton); | ||
await connectButton.click(); | ||
await page.screenshot({ path: `${outputFolder}/connected.png` }); | ||
} | ||
|
||
const firmwareMenuButton = page.getByRole("link", { name: "Firmware Update" }); | ||
expect(firmwareMenuButton).not.toBe(undefined); | ||
if (firmwareMenuButton) { | ||
console.log(firmwareMenuButton); | ||
await firmwareMenuButton.click(); | ||
await page.screenshot({ path: `${outputFolder}/firmwareUpdateSection.png` }); | ||
} | ||
|
||
const updateButton = page.getByRole("button", { name: "Update now" }); | ||
expect(updateButton).not.toBe(undefined); | ||
if (updateButton) { | ||
console.log(updateButton); | ||
await updateButton.click(); | ||
await page.waitForTimeout(1000); | ||
await page.screenshot({ path: `${outputFolder}/updateStart.png` }); | ||
} | ||
|
||
// we start flashing procedure | ||
await page.waitForSelector("text=/Press and hold/"); | ||
await page.keyboard.down("Escape"); | ||
await page.waitForSelector("text=/Updating/"); | ||
await page.keyboard.up("Escape"); | ||
await page.screenshot({ path: `${outputFolder}/flashing.png` }); | ||
await page.waitForSelector("text=/Firmware update!/"); | ||
await page.screenshot({ path: `${outputFolder}/flashCompleted.png` }); | ||
}); | ||
|
||
test.afterAll(async () => { | ||
await electronApp.close(); | ||
}); | ||
}); |
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,67 @@ | ||
import { defineConfig, devices } from "@playwright/test"; | ||
|
||
/** | ||
* Read environment variables from file. | ||
* https://github.com/motdotla/dotenv | ||
*/ | ||
// require('dotenv').config(); | ||
|
||
/** | ||
* See https://playwright.dev/docs/test-configuration. | ||
*/ | ||
export default defineConfig({ | ||
testDir: "./e2e_tests", | ||
/* Run tests in files in parallel */ | ||
fullyParallel: true, | ||
/* Fail the build on CI if you accidentally left test.only in the source code. */ | ||
forbidOnly: !!process.env.CI, | ||
/* Retry on CI only */ | ||
retries: process.env.CI ? 2 : 0, | ||
/* Opt out of parallel tests on CI. */ | ||
workers: process.env.CI ? 1 : undefined, | ||
/* Reporter to use. See https://playwright.dev/docs/test-reporters */ | ||
reporter: "html", | ||
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ | ||
use: { | ||
/* Base URL to use in actions like `await page.goto('/')`. */ | ||
// baseURL: 'http://127.0.0.1:3000', | ||
|
||
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ | ||
trace: "on-first-retry", | ||
}, | ||
|
||
/* Configure projects for major browsers */ | ||
projects: [ | ||
{ | ||
name: "chromium", | ||
use: { ...devices["Desktop Chrome"] }, | ||
}, | ||
|
||
/* Test against mobile viewports. */ | ||
// { | ||
// name: 'Mobile Chrome', | ||
// use: { ...devices['Pixel 5'] }, | ||
// }, | ||
// { | ||
// name: 'Mobile Safari', | ||
// use: { ...devices['iPhone 12'] }, | ||
// }, | ||
|
||
/* Test against branded browsers. */ | ||
// { | ||
// name: 'Microsoft Edge', | ||
// use: { ...devices['Desktop Edge'], channel: 'msedge' }, | ||
// }, | ||
// { | ||
// name: 'Google Chrome', | ||
// use: { ...devices['Desktop Chrome'], channel: 'chrome' }, | ||
// }, | ||
], | ||
|
||
/* Run your local dev server before starting the tests */ | ||
// webServer: { | ||
// command: 'npm run start', | ||
// url: 'http://127.0.0.1:3000', | ||
// reuseExistingServer: !process.env.CI, | ||
// }, | ||
}); |
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,18 @@ | ||
import { test, vi, expect } from "vitest"; | ||
import { configureUSB, getDevices } from "../setup/configureUSB"; | ||
|
||
test("get list of USB devices", async () => { | ||
vi.mock("electron", async () => { | ||
const mockIpcMain = { | ||
handle: vi.fn().mockReturnThis(), | ||
}; | ||
return { | ||
ipcMain: mockIpcMain, | ||
}; | ||
}); | ||
await configureUSB(); | ||
const devices = getDevices(); | ||
if (!process.env.GITHUB_ACTIONS) { | ||
expect(devices.length).toBeGreaterThan(0); | ||
} | ||
}); |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.