✅ Switch to Playwright for e2e tests

Possible fix for #4558
This commit is contained in:
Gina Häußge committed 2023-01-31 20:48:28 +01:00
1 parent 1d0a2287f8
commit 45d612fecc
30 files changed
+626 -4221

No files matched your search

-11
View File
@@ -9,14 +9,3 @@ overrides:
browser: true
jquery: true
es6: true
- files:
- "tests/cypress/**"
env:
node: true
es6: true
cypress/globals: true
extends:
- "plugin:cypress/recommended"
plugins:
- cypress
+6 -2
View File
@@ -4,10 +4,14 @@ devel:
enableRateLimiter: false
enableCsrfProtection: false
plugins:
virtual_printer:
enabled: true
softwareupdate:
checks:
octoprint:
disabled: true
tracking:
enabled: false
virtual_printer:
enabled: true
server:
firstRun: false
onlineCheck:
+38 -22
View File
@@ -110,7 +110,6 @@ jobs:
name: 🧪 E2E tests
needs: build
runs-on: ubuntu-latest
continue-on-error: true
steps:
- name: ⬇ Checkout code
uses: actions/checkout@v3
@@ -120,11 +119,13 @@ jobs:
with:
name: dist
path: dist
- name: 🏗 Set up Python 3.7
uses: actions/setup-python@v4
with:
python-version: 3.7
- name: 🚀 Install wheel
- name: 🏗 Install OctoPrint build
run: |
pip install dist/OctoPrint-*-py2.py3-none-any.whl
@@ -133,30 +134,45 @@ jobs:
mkdir e2econfig
cp -r .github/fixtures/with_acl/* e2econfig
- name: 🚀 Run Cypress
uses: cypress-io/github-action@v4.2.0
with:
working-directory: tests/cypress
browser: chrome
start: "octoprint -b ${{ github.workspace }}/e2econfig serve --host 127.0.0.1 --port 5000"
wait-on: "http://127.0.0.1:5000/online.txt"
env:
CYPRESS_DEPLOYSENTINEL_ENABLED: "true"
CYPRESS_DEPLOYSENTINEL_UPLOAD_ON_PASSES: "true"
CYPRESS_DEPLOYSENTINEL_KEY: ${{ secrets.DEPLOYSENTINEL_APIKEY }}
- name: 🏗 Prepare Playwright env
working-directory: ./tests/playwright
run: |
npm ci
PLAYWRIGHT_VERSION=$(npm ls --json @playwright/test | jq --raw-output '.dependencies["@playwright/test"].version')
echo "PLAYWRIGHT_VERSION=$PLAYWRIGHT_VERSION" >> $GITHUB_ENV
- name: ⬆ Upload screenshots
uses: actions/upload-artifact@v3
if: failure()
- name: 🧰 Cache Playwright browser binaries
uses: actions/cache@v3
id: playwright-cache
with:
name: cypress-screenshots
path: tests/cypress/screenshots
- name: ⬆ Upload videos
uses: actions/upload-artifact@v1
path: "~/.cache/ms-playwright"
key: "${{ runner.os }}-playwright-${{ env.PLAYWRIGHT_VERSION }}"
restore-keys: |
${{ runner.os }}-playwright-
- name: 🏗 Install Playwright browser binaries & OS dependencies
if: steps.playwright-cache.outputs.cache-hit != 'true'
working-directory: ./tests/playwright
run: |
npx playwright install --with-deps
- name: 🏗 Install Playwright OS dependencies
if: steps.playwright-cache.outputs.cache-hit == 'true'
working-directory: ./tests/playwright
run: |
npx playwright install-deps
- name: 🚀 Run Playwright
working-directory: ./tests/playwright
run: |
OCTOPRINT_SERVER_BASE=${{ github.workspace }}/e2econfig npx playwright test
- name: ⬆ Upload report
uses: actions/upload-artifact@v3
if: always()
with:
name: cypress-videos
path: tests/cypress/videos
name: playwright-report
path: tests/playwright/playwright-report
publish-on-testpypi:
name: 📦 Publish on TestPyPI
-4
View File
@@ -41,7 +41,3 @@ pypy
venv*
testconf*
node_modules
tests/cypress/screenshots
tests/cypress/videos
-1
View File
@@ -67,7 +67,6 @@ repos:
- id: eslint
additional_dependencies:
- eslint@7.19.0
- eslint-plugin-cypress@2.11.2
files: \.js$
exclude: ^(src/octoprint/vendor/|tests/static/js/lib|tests/util/_files|docs/|scripts/|translations/)
- repo: https://github.com/codespell-project/codespell
-12
View File
@@ -1,12 +0,0 @@
{
"baseUrl": "http://127.0.0.1:5000",
"fixturesFolder": "fixtures",
"integrationFolder": "integration",
"pluginsFile": "plugins/index.js",
"supportFile": "support/index.js",
"screenshotsFolder": "screenshots",
"videosFolder": "videos",
"modifyObstructiveCode": false,
"retries": 5
}
-3
View File
@@ -1,3 +0,0 @@
M117 I'm just a test upload during E2E
G28 X0 Y0
M117 That is all folks!
-5
View File
@@ -1,5 +0,0 @@
{
"name": "Using fixtures to represent data",
"email": "hello@cypress.io",
"body": "Fixtures are a great way to mock data for responses to routes"
}
-49
View File
@@ -1,49 +0,0 @@
import {prepare_server, login, disconnect, await_coreui} from "../util/util";
context("Connection test against virtual printer", () => {
const username = "admin";
const password = "test";
beforeEach(() => {
prepare_server();
// login
login(username, password);
// ensure we are disconnected
disconnect();
cy.visit("/");
await_coreui();
});
it("connect & disconnect", () => {
cy.get("[data-test-id=state-string]", {timeout: 10000}).should(
"contain",
"Offline"
);
cy.get("[data-test-id=connection-printer-profiles]").should(
"have.length.greaterThan",
0
);
cy.get("[data-test-id=connection-ports]").select("VIRTUAL");
cy.get("[data-test-id=connection-baudrates]").select("AUTO");
cy.get("[data-test-id=connection-connect]").should("contain", "Connect").click();
cy.wait(["@connectionCommand", "@connectionDetails"]);
cy.get("[data-test-id=sidebar-connection-content]", {timeout: 10000}).should(
"not.be.visible"
);
cy.get("[data-test-id=state-string]").should("contain", "Operational");
cy.get("[data-test-id=sidebar-connection-toggle]").click();
cy.get("[data-test-id=connection-connect]")
.should("be.visible")
.should("contain", "Disconnect")
.click();
cy.wait(["@connectionCommand", "@connectionDetails"]);
cy.get("[data-test-id=state-string]").should("contain", "Offline");
});
});
-116
View File
@@ -1,116 +0,0 @@
import {
prepare_server,
await_coreui,
await_loginui,
login,
get_cookie_name,
get_full_url
} from "../util/util";
context("Login tests", () => {
const username = "admin";
const password = "test";
beforeEach(() => {
prepare_server();
});
context("Successful login", () => {
beforeEach(() => {
cy.visit("/?l10n=en");
await_loginui();
cy.location().should((loc) => {
expect(loc.pathname).to.eq(get_full_url("/login/"));
});
});
it("logs in", () => {
cy.get("[data-test-id=login-username]").type(username);
cy.get("[data-test-id=login-password]").type(password);
cy.get("[data-test-id=login-submit]").click({force: true});
cy.wait("@login");
await_coreui();
cy.get("[data-test-id=login-menu-title]").should("contain", username);
cy.getCookie(get_cookie_name("session")).should("exist");
cy.getCookie(get_cookie_name("remember_token")).should("not.exist");
cy.location().should((loc) => {
expect(loc.hash).to.eq("#temp");
});
});
it("logs in with remember me", () => {
cy.get("[data-test-id=login-username]").type(username);
cy.get("[data-test-id=login-password]").type(password);
cy.get("[data-test-id=login-remember-me]").click();
cy.get("[data-test-id=login-submit]").click({force: true});
cy.wait("@login");
await_coreui();
cy.get("[data-test-id=login-menu-title]").should("contain", username);
cy.getCookie(get_cookie_name("session")).should("exist");
cy.getCookie(get_cookie_name("remember_token")).should(($cookie) => {
expect($cookie).to.have.property("value");
expect($cookie.value).to.match(new RegExp("^" + username + "|"));
});
cy.location().should((loc) => {
expect(loc.hash).to.eq("#temp");
});
});
});
context("Successful logout", () => {
it("logs out", () => {
// login
login(username, password);
cy.visit("/?l10n=en");
await_coreui();
cy.get("[data-test-id=login-menu]").click();
cy.get("[data-test-id=logout-submit]").click();
cy.wait("@logout");
await_loginui();
cy.location().should((loc) => {
expect(loc.pathname).to.eq(get_full_url("/login/"));
});
});
});
context("Unauthorized login attempts", () => {
beforeEach(() => {
cy.visit("/?l10n=en");
await_loginui();
cy.location().should((loc) => {
expect(loc.pathname).to.eq(get_full_url("/login/"));
});
});
it("uses wrong user name", () => {
cy.get("[data-test-id=login-username]").type("idonotexist");
cy.get("[data-test-id=login-password]").type("test");
cy.get("[data-test-id=login-submit]").click();
});
it("uses wrong password", () => {
cy.get("[data-test-id=login-username]").type("admin");
cy.get("[data-test-id=login-password]").type("wrongpassword");
cy.get("[data-test-id=login-submit]").click();
});
afterEach(() => {
cy.get("[data-test-id=login-title]")
.should("be.visible")
.should("contain", "Please log in");
cy.get("[data-test-id=login-error]")
.should("be.visible")
.should("contain", "Incorrect username or password");
});
});
});
-29
View File
@@ -1,29 +0,0 @@
import {prepare_server, login, await_coreui} from "../util/util";
context("Error free page load", () => {
let spy;
Cypress.on("uncaught:exception", (err, runnable) => {
console.error(err);
return false;
});
Cypress.on("window:before:load", (win) => {
spy = cy.spy(win.console, "error");
});
const username = "admin";
const password = "test";
beforeEach(() => {
prepare_server();
login(username, password);
cy.visit("/");
await_coreui();
});
it("loads without error", () => {
expect(spy).not.to.be.called;
});
});
-52
View File
@@ -1,52 +0,0 @@
import {prepare_server, login, disconnect, await_coreui} from "../util/util";
context("Test settings dialog opens and closes", () => {
const username = "admin";
const password = "test";
beforeEach(() => {
prepare_server();
// login
login(username, password);
cy.visit("/");
await_coreui();
});
it("opens settings", () => {
cy.get("[data-test-id=settings-open]").click();
cy.get("[data-test-id=settings-dialog]").should("be.visible");
});
describe("close settings", () => {
beforeEach(() => {
cy.get("[data-test-id=settings-open]").click();
cy.get("[data-test-id=settings-dialog]").should("be.visible");
});
it("closes settings via button", () => {
cy.get("[data-test-id=settings-close-button").click();
});
it("closes settings via x", () => {
cy.get("[data-test-id=settings-close-x").click({force: true});
});
it.skip("closes settings via click outside", () => {
cy.get("body").click();
});
it.skip("closes settings via ESC", () => {
cy.get("[data-test-id=settings-dialog]").trigger("keydown", {
key: "Escape",
which: 27,
code: "Escape"
});
});
afterEach(() => {
cy.get("[data-test-id=settings-dialog]").should("not.be.visible");
});
});
});
-26
View File
@@ -1,26 +0,0 @@
import {prepare_server, login, ensure_file_unknown, await_coreui} from "../util/util";
context("Upload tests", () => {
const username = "admin";
const password = "test";
const upload = "e2e-test.gcode";
beforeEach(() => {
prepare_server();
// login
login(username, password);
// clean up file if needed
ensure_file_unknown("local", upload);
cy.visit("/");
await_coreui();
});
it("uploads file to local via button", () => {
cy.get("[data-test-id=upload-local]").attachFile(upload);
cy.wait("@files");
cy.get("[data-test-id=files-list]").contains(upload);
});
});
-3701
View File
File diff suppressed because it is too large. Load diff
-30
View File
@@ -1,30 +0,0 @@
{
"name": "octoprint-cypress",
"version": "1.0.0",
"description": "Cypress setup for E2E testing OctoPrint",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/OctoPrint/OctoPrint.git"
},
"author": "Gina Häußge",
"license": "AGPL-3.0",
"bugs": {
"url": "https://github.com/OctoPrint/OctoPrint/issues"
},
"homepage": "https://octoprint.org",
"dependencies": {
"cypress": "^9.4.1",
"cypress-commands": "^1.1.0",
"cypress-file-upload": "^4.0.7",
"cypress-terminal-report": "^1.4.1",
"cypress-wait-until": "^1.7.1",
"ini": "^2.0.0"
},
"devDependencies": {
"@deploysentinel/cypress-debugger": "^0.2.18"
}
}
-23
View File
@@ -1,23 +0,0 @@
/// <reference types="cypress" />
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************
// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)
/**
* @type {Cypress.PluginConfig}
*/
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
require("cypress-terminal-report/src/installLogsPrinter")(on);
require("@deploysentinel/cypress-debugger/plugin")(on, config);
};
-2
View File
@@ -1,2 +0,0 @@
import "cypress-wait-until";
import "cypress-file-upload";
-24
View File
@@ -1,24 +0,0 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************
// Import commands.js using ES2015 syntax:
import "@deploysentinel/cypress-debugger/support";
import "./commands";
// Alternatively you can use CommonJS syntax:
// require('./commands')
require("cypress-terminal-report/src/installLogsCollector")();
require("cypress-commands");
-109
View File
@@ -1,109 +0,0 @@
export const prepare_server = () => {
cy.intercept("POST", get_full_url("/api/login")).as("login");
cy.intercept("POST", get_full_url("/api/logout")).as("logout");
cy.intercept("GET", get_full_url("/api/settings")).as("settings");
cy.intercept("GET", get_full_url("/api/files?recursive=true")).as("files");
cy.intercept("GET", get_full_url("/plugin/softwareupdate/check")).as(
"softwareupdate"
);
cy.intercept("GET", get_full_url("/plugin/pluginmanager/plugins")).as(
"pluginmanager"
);
cy.intercept("POST", get_full_url("/api/connection")).as("connectionCommand");
cy.intercept("GET", get_full_url("/api/connection")).as("connectionDetails");
};
export const await_loginui = () => {
cy.get("[data-test-id=login-title]")
.should("be.visible")
.should("contain", "Please log in");
cy.window().its("OctoPrint.loginui.startedUp", {timeout: 30000}).should("be.true");
};
export const await_coreui = () => {
cy.wait(["@login", "@settings", "@files", "@softwareupdate", "@pluginmanager"]);
cy.window().its("OctoPrint.coreui.startedUp", {timeout: 30000}).should("be.true");
};
export const login = (username, password) => {
cy.request({
method: "POST",
url: get_full_url("/api/login"),
body: {
user: username,
pass: password
}
});
};
export const logout = () => {
cy.request({
method: "POST",
url: get_full_url("/api/logout")
});
};
export const connect = (port, baudrate) => {
port = port || "AUTO";
baudrate = baudrate || 0;
cy.request({
method: "POST",
url: get_full_url("/api/connection"),
body: {
command: "connect",
port: port,
baudrate: baudrate
}
});
};
export const disconnect = () => {
cy.request({
method: "POST",
url: get_full_url("/api/connection"),
body: {
command: "disconnect"
}
});
};
export const ensure_file_unknown = (location, name) => {
cy.request({
method: "DELETE",
url: get_full_url(`/api/files/${location}/${name}`),
failOnStatusCode: false
});
};
export const get_cookie_name = (cookie) => {
const url = new URL(Cypress.config("baseUrl"));
const port = url.port || (url.protocol === "https:" ? 443 : 80);
if (url.pathname && url.pathname !== "/") {
let path = url.pathname;
if (path.endsWith("/")) {
path = path.substring(0, path.length - 1);
}
return `${cookie}_P${port}_R${path.replace(/\//, "|")}`;
} else {
return `${cookie}_P${port}`;
}
};
export const get_full_url = (url) => {
const parsed = new URL(Cypress.config("baseUrl"));
let path = "";
if (parsed.pathname) {
path = parsed.pathname;
}
if (path.endsWith("/")) {
path = path.substring(0, path.length - 1);
}
let url2 = url;
if (url2.startsWith("/")) {
url2 = url2.substring(1);
}
return path + "/" + url2;
};
+2
View File
@@ -0,0 +1,2 @@
parserOptions:
ecmaVersion: 2021
+4
View File
@@ -0,0 +1,4 @@
node_modules/
/test-results/
/playwright-report/
/playwright/.cache/
+188
View File
@@ -0,0 +1,188 @@
const base = require("@playwright/test");
const credentials = {
username: process.env.OCTOPRINT_USERNAME || "admin",
password: process.env.OCTOPRINT_PASSWORD || "test"
};
const expect = base.expect;
exports.test = base.test.extend({
loginApi: async ({context}, use) => {
const loginApi = {
login: async (username, password) => {
return await context.request.post("/api/login", {
data: {
user: username,
pass: password
}
});
},
logout: async () => {
return await context.request.post("/api/logout");
},
loginDefault: async () => {
const response = await loginApi.login(
credentials.username,
credentials.password
);
await expect(response.ok()).toBeTruthy();
return response;
}
};
await use(loginApi);
},
connectionApi: async ({context}, use) => {
const connectionApi = {
connect: async (port, baudrate) => {
port = port || "AUTO";
baudrate = baudrate || 0;
return await context.request.post("/api/connection", {
data: {
command: "connect",
port: port,
baudrate: baudrate
}
});
},
disconnect: async () => {
return await context.request.post("/api/connection", {
data: {
command: "disconnect"
}
});
}
};
await use(connectionApi);
},
filesApi: async ({context}, use) => {
const filesApi = {
ensureFileUnknown: async (location, name) => {
return await context.request.delete(`/api/files/${location}/${name}`);
}
};
await use(filesApi);
},
credentials: async ({}, use) => {
await use(credentials);
},
ui: async ({page, util, loginApi}, use) => {
const ui = {
gotoLogin: async () => {
await page.goto("/?l10n=en");
await ui.loginHasLoaded();
},
gotoLoggedInCore: async () => {
await loginApi.loginDefault();
await page.goto("/?l10n=en");
await ui.coreHasLoaded();
},
coreIsLoading: async () => {
await expect(page).toHaveURL(util.getFullUrlRegExp("/"), {
timeout: 15_000
});
},
coreHasLoaded: async () => {
await ui.coreIsLoading();
await page.waitForFunction(
() =>
window.OctoPrint &&
window.OctoPrint.coreui &&
window.OctoPrint.coreui.startedUp,
{timeout: 10_000}
);
},
loggedInCoreHasLoaded: async (username) => {
username = username || credentials.username;
await ui.coreHasLoaded();
await expect(page.getByTestId("login-menu-title")).toContainText(
username
);
},
loginIsLoading: async () => {
await expect(page).toHaveURL(util.getFullUrlRegExp("/login/"), {
timeout: 15_000
});
},
loginHasLoaded: async () => {
await ui.loginIsLoading();
await page.waitForFunction(
() =>
window.OctoPrint &&
window.OctoPrint.loginui &&
window.OctoPrint.loginui.startedUp,
{timeout: 10_000}
);
const loginTitle = await page.getByTestId("login-title");
await expect(loginTitle).toBeVisible();
await expect(loginTitle).toContainText("Please log in");
}
};
await use(ui);
},
util: async ({context, baseURL}, use) => {
const util = {
loginCookiesWithoutRememberMe: async () => {
const cookies = await context.cookies();
const sessionCookie = util.getCookieName("session", baseURL);
const rememberMeCookie = util.getCookieName("remember_token", baseURL);
await expect(
cookies.find((element) => element.name == sessionCookie)
).toBeTruthy();
await expect(
cookies.find((element) => element.name == rememberMeCookie)
).toBeFalsy();
},
loginCookiesWithRememberMe: async () => {
const cookies = await context.cookies();
const sessionCookie = util.getCookieName("session", baseURL);
const rememberMeCookie = util.getCookieName("remember_token", baseURL);
await expect(
cookies.find((element) => element.name == sessionCookie)
).toBeTruthy();
await expect(
cookies.find((element) => element.name == rememberMeCookie)
).toBeTruthy();
},
getCookieName: (cookie) => {
const url = new URL(baseURL);
const port = url.port || (url.protocol === "https:" ? 443 : 80);
if (url.pathname && url.pathname !== "/") {
let path = url.pathname;
if (path.endsWith("/")) {
path = path.substring(0, path.length - 1);
}
return `${cookie}_P${port}_R${path.replace(/\//, "|")}`;
} else {
return `${cookie}_P${port}`;
}
},
getFullUrlRegExp: (path) => {
const fullUrl = baseURL + path;
const escaped = fullUrl.replace(/[/\-\\^$*+?.()|[\]{}]/g, "\\$&");
return new RegExp("^" + escaped + "(\\?.*)?(#.*)?$");
}
};
await use(util);
}
});
exports.expect = expect;
+74
View File
@@ -0,0 +1,74 @@
{
"name": "octoprint-playwright-tests",
"version": "1.0.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "octoprint-playwright-tests",
"version": "1.0.0",
"license": "MIT",
"devDependencies": {
"@playwright/test": "^1.30.0"
}
},
"node_modules/@playwright/test": {
"version": "1.30.0",
"resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.30.0.tgz",
"integrity": "sha512-SVxkQw1xvn/Wk/EvBnqWIq6NLo1AppwbYOjNLmyU0R1RoQ3rLEBtmjTnElcnz8VEtn11fptj1ECxK0tgURhajw==",
"dev": true,
"dependencies": {
"@types/node": "*",
"playwright-core": "1.30.0"
},
"bin": {
"playwright": "cli.js"
},
"engines": {
"node": ">=14"
}
},
"node_modules/@types/node": {
"version": "18.11.18",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.18.tgz",
"integrity": "sha512-DHQpWGjyQKSHj3ebjFI/wRKcqQcdR+MoFBygntYOZytCqNfkd2ZC4ARDJ2DQqhjH5p85Nnd3jhUJIXrszFX/JA==",
"dev": true
},
"node_modules/playwright-core": {
"version": "1.30.0",
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.30.0.tgz",
"integrity": "sha512-7AnRmTCf+GVYhHbLJsGUtskWTE33SwMZkybJ0v6rqR1boxq2x36U7p1vDRV7HO2IwTZgmycracLxPEJI49wu4g==",
"dev": true,
"bin": {
"playwright": "cli.js"
},
"engines": {
"node": ">=14"
}
}
},
"dependencies": {
"@playwright/test": {
"version": "1.30.0",
"resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.30.0.tgz",
"integrity": "sha512-SVxkQw1xvn/Wk/EvBnqWIq6NLo1AppwbYOjNLmyU0R1RoQ3rLEBtmjTnElcnz8VEtn11fptj1ECxK0tgURhajw==",
"dev": true,
"requires": {
"@types/node": "*",
"playwright-core": "1.30.0"
}
},
"@types/node": {
"version": "18.11.18",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.18.tgz",
"integrity": "sha512-DHQpWGjyQKSHj3ebjFI/wRKcqQcdR+MoFBygntYOZytCqNfkd2ZC4ARDJ2DQqhjH5p85Nnd3jhUJIXrszFX/JA==",
"dev": true
},
"playwright-core": {
"version": "1.30.0",
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.30.0.tgz",
"integrity": "sha512-7AnRmTCf+GVYhHbLJsGUtskWTE33SwMZkybJ0v6rqR1boxq2x36U7p1vDRV7HO2IwTZgmycracLxPEJI49wu4g==",
"dev": true
}
}
}
+13
View File
@@ -0,0 +1,13 @@
{
"name": "octoprint-playwright-tests",
"version": "1.0.0",
"description": "OctoPrint's E2E tests with Playwright",
"main": "index.js",
"scripts": {},
"keywords": [],
"author": "Gina Häußge",
"license": "MIT",
"devDependencies": {
"@playwright/test": "^1.30.0"
}
}
+83
View File
@@ -0,0 +1,83 @@
// @ts-check
const {devices} = require("@playwright/test");
const config = {
testDir: "./specs",
timeout: 60_000,
expect: {
timeout: 10_000
},
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? 2 : undefined,
reportSlowTests: {
max: 30_000,
threshold: 50_000
},
reporter: "html",
use: {
actionTimeout: 0,
baseURL: process.env.PLAYWRIGHT_BASEURL || "http://localhost:5000",
testIdAttribute: "data-test-id",
trace: "on",
video: "on",
viewport: {width: 1280, height: 720}
},
projects: [
{
name: "chromium",
use: {
...devices["Desktop Chrome"]
}
},
{
name: "firefox",
use: {
...devices["Desktop Firefox"]
}
}
/* 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: {
// channel: 'msedge',
// },
// },
// {
// name: 'Google Chrome',
// use: {
// channel: 'chrome',
// },
// },
]
};
if (!process.env.NO_SERVER) {
const octoprintServerOpts = process.env.OCTOPRINT_SERVER_BASE
? `-b ${process.env.OCTOPRINT_SERVER_BASE}`
: "";
config.webServer = {
command: `octoprint ${octoprintServerOpts} serve --host 127.0.0.1 --port 5000`,
url: "http://127.0.0.1:5000/online.txt",
reuseExistingServer: !process.env.CI
};
}
module.exports = config;
+51
View File
@@ -0,0 +1,51 @@
// @ts-check
const {test, expect} = require("../fixtures");
test.describe("Printer connection", () => {
test.beforeEach(async ({ui, connectionApi}) => {
await ui.gotoLoggedInCore();
const response = await connectionApi.disconnect();
await expect(response.ok()).toBeTruthy();
});
test("connect & disconnect against virtual printer", async ({page}) => {
await expect(page.getByTestId("state-string")).toHaveText("Offline");
// Connect
await page.getByTestId("connection-ports").selectOption("VIRTUAL");
await page.getByTestId("connection-baudrates").selectOption("AUTO");
await page.getByTestId("connection-printer-profiles").selectOption("Default");
await expect(page.getByTestId("connection-connect")).toHaveText("Connect");
await page.getByTestId("connection-connect").click();
// State should change to Operational
await expect(page.getByTestId("state-string")).toHaveText("Operational", {
timeout: 15_000
});
// Connection panel should roll up
await page.waitForFunction(
() => {
const element = document.querySelector(
"[data-test-id=sidebar-connection-content]"
);
if (!element) {
return false;
}
const parent = element.parentElement;
return parent && parent.getBoundingClientRect().height === 0;
},
{timeout: 15_000}
);
// Disconnect
await page.getByTestId("sidebar-connection-toggle").click();
await expect(page.getByTestId("connection-connect")).toBeVisible();
await expect(page.getByTestId("connection-connect")).toHaveText("Disconnect");
await page.getByTestId("connection-connect").click();
await expect(page.getByTestId("state-string")).toHaveText("Offline");
});
});
+90
View File
@@ -0,0 +1,90 @@
// @ts-check
const {test, expect} = require("../fixtures");
test.describe.parallel("Successful login", async () => {
test.beforeEach(async ({ui}) => {
await ui.gotoLogin();
});
test("basic", async ({page, ui, util, credentials}) => {
await page.getByTestId("login-username").fill(credentials.username);
await page.getByTestId("login-password").fill(credentials.password);
await page.getByTestId("login-submit").click();
await ui.coreIsLoading();
await util.loginCookiesWithoutRememberMe();
});
test("with remember me", async ({page, ui, util, credentials}) => {
await page.getByTestId("login-username").fill(credentials.username);
await page.getByTestId("login-password").fill(credentials.password);
await page.getByTestId("login-remember-me").check();
await page.getByTestId("login-submit").click();
await ui.coreIsLoading();
await util.loginCookiesWithRememberMe();
});
test.fixme("by keyboard", async ({page, ui, util, credentials}) => {
// TODO: this doesn't work yet
await expect(page.getByTestId("login-username")).toBeFocused();
await page.getByTestId("login-username").type(credentials.username);
await page.getByTestId("login-username").press("Tab");
await expect(page.getByTestId("login-password")).toBeFocused();
await page.getByTestId("login-password").type(credentials.password);
await page.getByTestId("login-password").press("Tab");
await expect(page.getByTestId("login-remember-me")).toBeFocused();
await page.getByTestId("login-remember-me").press("Space");
await page.getByTestId("login-remember-me").press("Tab");
await expect(page.getByTestId("login-submit")).toBeFocused();
await page.getByTestId("login-submit").press("Enter");
await ui.coreIsLoading();
await util.loginCookiesWithRememberMe();
});
});
test.describe.parallel("Failed login", async () => {
test.beforeEach(async ({ui}) => {
await ui.gotoLogin();
});
test("wrong user name", async ({page, credentials}) => {
await page.getByTestId("login-username").fill("idonotexist");
await page.getByTestId("login-password").fill(credentials.password);
await page.getByTestId("login-submit").click();
});
test("wrong password", async ({page, credentials}) => {
await page.getByTestId("login-username").fill(credentials.username);
await page.getByTestId("login-password").fill("wrongpassword");
await page.getByTestId("login-submit").click();
});
test.afterEach(async ({page, ui}) => {
await ui.loginHasLoaded();
const loginTitle = page.getByTestId("login-title");
await expect(loginTitle).toBeVisible();
await expect(loginTitle).toContainText("Please log in");
const loginError = page.getByTestId("login-error");
await expect(loginError).toBeVisible();
await expect(loginError).toContainText("Incorrect username or password");
});
});
test("Successful logout", async ({page, ui, credentials}) => {
await ui.gotoLoggedInCore();
await expect(page.getByTestId("login-menu")).toContainText(credentials.username);
await page.getByTestId("login-menu").click();
await expect(page.getByTestId("logout-submit")).toBeVisible();
await page.getByTestId("logout-submit").click();
await ui.loginIsLoading();
});
+17
View File
@@ -0,0 +1,17 @@
const {test, expect} = require("../fixtures");
test("Error free page load", async ({page, ui}) => {
const errors = [];
page.on("pageerror", (error) => {
errors.push(`[${error.name}] ${error.message}`);
});
page.on("console", (msg) => {
if (msg.type() === "error") {
errors.push(`[${msg.type()}] ${msg.text()}`);
}
});
await ui.gotoLoggedInCore();
await expect(errors).toStrictEqual([]);
});
+42
View File
@@ -0,0 +1,42 @@
// @ts-check
const {test, expect} = require("../fixtures");
test("Open settings", async ({page, ui}) => {
await ui.gotoLoggedInCore();
// open settings dialog
await page.getByTestId("settings-open").click();
// verify it's open
await expect(page.getByTestId("settings-dialog")).toBeVisible();
});
test.describe.parallel("Close settings", () => {
test.beforeEach(async ({page, ui}) => {
await ui.gotoLoggedInCore();
await page.getByTestId("settings-open").click();
await expect(page.getByTestId("settings-dialog")).toBeVisible();
});
test("via button", async ({page}) => {
await page.getByTestId("settings-close-button").click();
});
test("via x", async ({page}) => {
await page.getByTestId("settings-close-x").click();
});
test("via ESC", async ({page}) => {
await page.getByTestId("settings-dialog").press("Escape");
});
test.fixme("via click outside", async ({page}) => {
// TODO: this doesn't work yet
await page.locator(".modal-scrollable").click();
});
test.afterEach(async ({page}) => {
// verify it's closed
await expect(page.getByTestId("settings-dialog")).not.toBeVisible();
});
});
+18
View File
@@ -0,0 +1,18 @@
const {test, expect} = require("../fixtures");
const gcodeName = "e2e-test.gcode";
const gcodeContent =
"M117 I'm just a test upload during E2E\nG28 X0 Y0\nM117 That is all folks!";
test("Successful upload", async ({page, ui, filesApi}) => {
await ui.gotoLoggedInCore();
await filesApi.ensureFileUnknown("local", gcodeName);
await page.getByTestId("upload-local").setInputFiles({
name: gcodeName,
mimeType: "text/plain",
buffer: Buffer.from(gcodeContent)
});
await expect(page.getByTestId("files-list")).toContainText(gcodeName);
});