Merge branch 'maintenance' into devel

This commit is contained in:
Gina Häußge committed 2023-02-13 11:08:54 +01:00
commit ae62e85f0d
47 files changed
+769 -4251

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
+7
View File
@@ -0,0 +1,7 @@
version: 2
updates:
# Check for updates to GitHub Actions every week
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
+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:
+3
View File
@@ -15,7 +15,10 @@ meta:
ci/cd:
- ".github/fixtures/**/*"
- ".github/workflows/*"
- ".github/dependabot.yml"
- ".github/issue-validation.yml"
- ".github/labeler.yml"
- ".github/pr-validation.yml"
docker:
- ".github/workflows/trigger_docker.yml"
+57 -23
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,63 @@ 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
- name: 🧰 Cache Playwright browser binaries
uses: actions/cache@v3
id: playwright-cache
with:
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: |
npx playwright test
env:
OCTOPRINT_SERVER_BASE: ${{ github.workspace }}/e2econfig
- name: 🔎 Check octoprint.log for errors
run: |
log=${{ github.workspace }}/e2econfig/logs/octoprint.log
if grep "\- ERROR \-" $log; then
echo "::error::Errors were logged to octoprint.log"
grep -Pazo '(?m)^\N+\- ERROR \-\N*\n(^\N*?\n)*?(?=\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2},\d{3} \- )' $log
exit 1
fi
- name: ⬆ Upload Playwright report
uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report
path: tests/playwright/playwright-report
- name: ⬆ Upload OctoPrint logs
uses: actions/upload-artifact@v3
if: failure()
with:
name: cypress-screenshots
path: tests/cypress/screenshots
- name: ⬆ Upload videos
uses: actions/upload-artifact@v1
if: always()
with:
name: cypress-videos
path: tests/cypress/videos
name: octoprint-logs
path: ${{ github.workspace }}/e2econfig/logs
publish-on-testpypi:
name: 📦 Publish on TestPyPI
@@ -208,7 +242,7 @@ jobs:
OCTOPRINT_VERSION=$(echo $GITHUB_REF | cut -d/ -f3)
echo "OCTOPRINT_VERSION=$OCTOPRINT_VERSION" >> $GITHUB_ENV
- name: 🚀 Repository Dispatch
uses: peter-evans/repository-dispatch@v1
uses: peter-evans/repository-dispatch@v2
with:
token: ${{ secrets.REPODISPATCH_TOKEN }}
repository: OctoPrint/OctoPi-UpToDate
+4 -4
View File
@@ -10,11 +10,11 @@ jobs:
name: 🔒 Lock issues & PRs closed over a year
runs-on: ubuntu-latest
steps:
- uses: dessant/lock-threads@v2
- uses: dessant/lock-threads@v4
with:
github-token: ${{ github.token }}
issue-lock-comment: ""
pr-lock-comment: ""
issue-comment: ""
pr-comment: ""
cleanup:
name: 🧹 Close issues marked as incomplete & older than 14 days
@@ -22,7 +22,7 @@ jobs:
steps:
- id: date
run: |
echo "::set-output name=CUTOFF::`date --date='14 days ago' +'%Y-%m-%d'`"
echo "CUTOFF=`date --date='14 days ago' +'%Y-%m-%d'`" >> $GITHUB_OUTPUT
- uses: OctoPrint/actions/close-by-query@main
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
+4 -4
View File
@@ -15,7 +15,7 @@ jobs:
fetch-depth: 0
- name: 🔀 Merge master into maintenance
uses: robotology/gh-action-nightly-merge@v1.3.3
uses: robotology/gh-action-nightly-merge@v1.4.0
with:
stable_branch: "master"
development_branch: "maintenance"
@@ -24,7 +24,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: 🔀 Merge staging/bugfix into maintenance
uses: robotology/gh-action-nightly-merge@v1.3.3
uses: robotology/gh-action-nightly-merge@v1.4.0
with:
stable_branch: "staging/bugfix"
development_branch: "maintenance"
@@ -33,7 +33,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: 🔀 Merge staging/maintenance into maintenance
uses: robotology/gh-action-nightly-merge@v1.3.3
uses: robotology/gh-action-nightly-merge@v1.4.0
with:
stable_branch: "staging/bugfix"
development_branch: "maintenance"
@@ -42,7 +42,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: 🔀 Merge maintenance into devel
uses: robotology/gh-action-nightly-merge@v1.3.3
uses: robotology/gh-action-nightly-merge@v1.4.0
with:
stable_branch: "maintenance"
development_branch: "devel"
+1 -1
View File
@@ -8,7 +8,7 @@ jobs:
pr-automation:
runs-on: ubuntu-latest
steps:
- uses: actions/labeler@v3
- uses: actions/labeler@v4
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
+3 -3
View File
@@ -15,7 +15,7 @@ jobs:
if: github.repository == 'OctoPrint/OctoPrint' && github.event_name != 'push'
steps:
- name: 🚀 Repository Dispatch
uses: peter-evans/repository-dispatch@v1
uses: peter-evans/repository-dispatch@v2
with:
token: ${{ secrets.DOCKER_ACCESS_TOKEN }}
repository: ${{ github.repository_owner }}/octoprint-docker
@@ -27,7 +27,7 @@ jobs:
if: github.repository == 'OctoPrint/OctoPrint' && github.event_name == 'push' && github.ref == 'refs/heads/maintenance'
steps:
- name: 🚀 Repository Dispatch
uses: peter-evans/repository-dispatch@v1
uses: peter-evans/repository-dispatch@v2
with:
token: ${{ secrets.DOCKER_ACCESS_TOKEN }}
repository: ${{ github.repository_owner }}/octoprint-docker
@@ -39,7 +39,7 @@ jobs:
if: github.repository == 'OctoPrint/OctoPrint' && github.event_name == 'push' && github.ref == 'refs/heads/devel'
steps:
- name: 🚀 Repository Dispatch
uses: peter-evans/repository-dispatch@v1
uses: peter-evans/repository-dispatch@v2
with:
token: ${{ secrets.DOCKER_ACCESS_TOKEN }}
repository: ${{ github.repository_owner }}/octoprint-docker
+5 -1
View File
@@ -1,6 +1,10 @@
name: Trigger doc build
on:
push:
branches:
- master
- maintenance
- devel
release:
types:
- released
@@ -12,7 +16,7 @@ jobs:
if: github.repository == 'OctoPrint/OctoPrint'
steps:
- name: 🚀 Repository Dispatch
uses: peter-evans/repository-dispatch@v1
uses: peter-evans/repository-dispatch@v2
with:
token: ${{ secrets.REPODISPATCH_TOKEN }}
repository: OctoPrint/docs.octoprint.org
-4
View File
@@ -40,7 +40,3 @@ pypy
venv*
testconf*
node_modules
tests/cypress/screenshots
tests/cypress/videos
+1 -1
View File
@@ -67,10 +67,10 @@ 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
rev: v2.1.0
hooks:
- id: codespell
exclude: ^(src/octoprint/vendor/|tests/static/js/lib|tests/util/_files|tests/playwright|scripts/)
+2
View File
@@ -322,6 +322,7 @@ def init_logging(
"class": "octoprint.logging.handlers.TornadoLogHandler",
"level": "DEBUG",
"formatter": "tornado",
"when": "D",
"backupCount": 1,
"filename": os.path.join(
settings.getBaseFolder("logs"), "tornado.log"
@@ -331,6 +332,7 @@ def init_logging(
"class": "octoprint.logging.handlers.AuthLogHandler",
"level": "DEBUG",
"formatter": "auth",
"when": "D",
"backupCount": 1,
"filename": os.path.join(settings.getBaseFolder("logs"), "auth.log"),
},
@@ -1,6 +1,6 @@
<div id="classicwebcam_container">
<!-- Init style with display none to hide the content while we are binding -->
<div "id="webcam_video_container" tabindex="0" data-bind="visible: webcamWebRTCEnabled() || webcamHlsEnabled(), css: { webcam_rotated: settings.rotate90(), webcam_unrotated: !settings.rotate90() }" style="display: none;">
<div id="webcam_video_container" tabindex="0" data-bind="visible: webcamWebRTCEnabled() || webcamHlsEnabled(), css: { webcam_rotated: settings.rotate90(), webcam_unrotated: !settings.rotate90() }" style="display: none;">
<div class="video-controls btn-group action-buttons">
<div class="btn btn-mini" data-bind="click: function(data, event) { $root.launchWebcamFullscreen() }"><i class="fas fa-expand"></i></div>
<div class="btn btn-mini" data-bind="visible: document.pictureInPictureEnabled, click: function(data, event) { $root.launchWebcamPictureInPicture() }"><i class="fas fa-images"></i></div>
+15 -12
View File
@@ -257,11 +257,13 @@ class PrinterProfileManager:
def __init__(self):
self._current = None
self._folder = settings().getBaseFolder("printerProfiles")
self._logger = logging.getLogger(__name__)
fresh = settings().checkBaseFolder("printerProfiles")
self._folder = settings().getBaseFolder("printerProfiles")
self._migrate_old_default_profile()
self._verify_default_available()
self._verify_default_available(fresh=fresh)
def _migrate_old_default_profile(self):
default_overrides = settings().get(["printerProfiles", "defaultProfile"])
@@ -291,23 +293,24 @@ class PrinterProfileManager:
)
)
def _verify_default_available(self):
def _verify_default_available(self, fresh=False):
default_id = settings().get(["printerProfiles", "default"])
if default_id is None:
default_id = "_default"
if not self.exists(default_id):
if not self.exists("_default"):
if default_id == "_default":
self._logger.error(
"Profile _default does not exist, creating _default again and setting it as default"
)
else:
self._logger.error(
"Selected default profile {} and _default do not exist, creating _default again and setting it as default".format(
default_id
if not fresh:
if default_id == "_default":
self._logger.error(
"Profile _default does not exist, creating _default again and setting it as default"
)
else:
self._logger.error(
"Selected default profile {} and _default do not exist, creating _default again and setting it as default".format(
default_id
)
)
)
self.save(self.__class__.default, allow_overwrite=True, make_default=True)
else:
self._logger.error(
+6 -1
View File
@@ -1491,12 +1491,17 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
if self._comm is not None:
self._comm = None
with self._selectedFileMutex:
if self._selectedFile is not None:
eventManager().fire(Events.FILE_DESELECTED)
self._setJobData(None, None, None)
self._updateProgressData()
self._setCurrentZ(None)
self._setJobData(None, None, None)
self._setOffsets(None)
self._addTemperatureData()
self._printerProfileManager.deselect()
eventManager().fire(Events.DISCONNECTED)
self._setState(state, state_string=state_string, error_string=error_string)
+1 -1
View File
@@ -1196,7 +1196,7 @@ class Server:
nonlocal autorefresh
if autorefresh is not None:
autorefresh.stop()
autorefresh.cancel()
autorefresh = None
autorefresh = octoprint.util.RepeatedTimer(
+1
View File
@@ -1762,6 +1762,7 @@ def collect_core_assets(preferred_stylesheet="css"):
assets["js"] = [
"js/app/bindings/allowbindings.js",
"js/app/bindings/contextmenu.js",
"js/app/bindings/gettext.js",
"js/app/bindings/invisible.js",
"js/app/bindings/popover.js",
"js/app/bindings/qrcode.js",
+13
View File
@@ -1761,6 +1761,19 @@ class Settings:
return value.lower() in valid_boolean_trues
return value is not None
def checkBaseFolder(self, type):
if type != "base" and type not in default_settings["folder"]:
return False
if type == "base":
return os.path.exists(self._basedir)
folder = self.get(["folder", type])
default_folder = self._get_default_folder(type)
if folder is None:
folder = default_folder
return os.path.exists(folder)
def getBaseFolder(
self,
type,
@@ -0,0 +1,16 @@
ko.bindingHandlers.gettext = {
init: function () {
// Prevent binding on the dynamically-injected text node (as developers are unlikely to expect that, and it has security implications).
// It should also make things faster, as we no longer have to consider whether the text node might be bindable.
return {controlsDescendantBindings: true};
},
update: function (element, valueAccessor) {
var gt =
gettext ||
function (text) {
return text;
};
ko.utils.setTextContent(element, gt(valueAccessor()));
}
};
ko.virtualElements.allowedBindings["gettext"] = true;
@@ -391,6 +391,18 @@ $(function () {
}
});
self.webcamCompat = {
webcam_streamUrl: "streamUrl",
webcam_streamRatio: "streamRatio",
webcam_streamTimeout: "streamTimeout",
webcam_streamWebrtcIceServers: "webrtcIceServers",
webcam_snapshotUrl: "snapshotUrl",
webcam_flipH: "flipH",
webcam_flipV: "flipV",
webcam_rotate90: "rotate90",
webcam_cacheBuster: "cacheBuster"
};
self.addTemperatureProfile = function () {
self.temperature_profiles.push({
name: "New",
@@ -1140,6 +1152,31 @@ $(function () {
}
};
// set up webcam compat layer if not yet done
_.each(self.webcamCompat, (mapped, key) => {
if (self.settings.hasOwnProperty(key)) return;
if (!self.settings.webcam.hasOwnProperty(mapped)) return;
const message =
"Please use the webcam system introduced with 1.9.0, the " +
key +
" config setting is deprecated and will be removed in a future release. Stacktrace:";
self[key] = ko.pureComputed({
read: () => {
const exc = new Error();
log.warn(message, exc.stack || exc.stacktrace || "<n/a>");
return self.settings.webcam[mapped]();
},
write: (value) => {
const exc = new Error();
log.warn(message, exc.stack || exc.stacktrace || "<n/a>");
self.settings.webcam[mapped](value);
},
owner: self
});
});
var mapToObservables = function (data, mapping, local, keyPrefix) {
if (!_.isPlainObject(data)) {
return;
@@ -1157,6 +1194,11 @@ $(function () {
return;
}
if (self.webcamCompat.hasOwnProperty(observable)) {
// webcam compat layer, skip
return;
}
var haveLocalVersion = local && local.hasOwnProperty(key);
if (
@@ -6,7 +6,7 @@
<td class="settings_accesscontrol_permissions_list_checkbox"><input type="checkbox" data-bind="checkedValue: key, checked: $parents[1].editor.permissions, enable: $parents[1].editor.permissionSelectable($data)"></td>
<td class="settings_accesscontrol_permissions_list_name" style="cursor: pointer" data-bind="click: function() { if ($parents[1].editor.permissionSelectable($data)) { $parents[1].editor.togglePermission($data.key) } }, attr: {title: description}">
<span class="name" data-bind="text: name, style: { fontWeight: ($parents[1].editor.permissionSelected($data.key)) ? 'bold' : 'normal' }"></span> <span class="label label-info" data-bind="visible: typeof(plugin) !== 'undefined'">{{ _('Plugin') }}</span> <span class="label label-important" data-bind="visible: dangerous">{{ _('Dangerous') }}</span><br>
<small class="description muted" data-bind="text: description"></small>
<small class="description muted" data-bind="gettext: description"></small>
</td>
</tr>
</tbody>
-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: [["list"], ["html"], ...(process.env.CI ? [["github"]] : [])],
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");
});
});
+89
View File
@@ -0,0 +1,89 @@
// @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("by keyboard", async ({page, ui, util, credentials}) => {
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([]);
});
+41
View File
@@ -0,0 +1,41 @@
// @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("via click outside", async ({page}) => {
await page.locator(".modal-scrollable").click({position: {x: 10, y: 10}});
});
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);
});