From 01940bbb10cb6d0261f384302417902734a45a9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 13 Jul 2020 16:06:28 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=9A=20(Hopefully)=20fix=20&=20re-enabl?= =?UTF-8?q?e=20E2E=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We now wait for full app initialization (OctoPrint.coreui.startedUp & OctoPrint.loginui.startedUp) before trying to test against things. At least in local test runs that solved the flakiness. --- .github/workflows/build.yml | 94 +++++++++---------- .../plugins/loginui/static/js/main.js | 9 +- src/octoprint/static/js/app/main.js | 5 +- tests/cypress/integration/connect.js | 5 +- tests/cypress/integration/login.js | 32 +++++-- 5 files changed, 84 insertions(+), 61 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6e9a6b433..057d9d623 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -90,52 +90,52 @@ jobs: run: | pip install dist/OctoPrint-*.tar.gz - #test-e2e: - # name: ๐Ÿงช E2E tests - # needs: build - # runs-on: ubuntu-16.04 - # steps: - # - name: โฌ‡ Checkout code - # uses: actions/checkout@v2 - # - # - name: โฌ‡ Download build result - # uses: actions/download-artifact@v1 - # with: - # name: dist - # path: dist - # - name: ๐Ÿ— Set up Python 3.7 - # uses: actions/setup-python@v1 - # with: - # python-version: 3.7 - # - name: ๐Ÿš€ Install wheel - # run: | - # pip install dist/OctoPrint-*-py2.py3-none-any.whl - # - # - name: ๐Ÿ— Create base config for test server - # run: | - # mkdir e2econfig - # cp -r .github/fixtures/with_acl/* e2econfig - # - # - name: ๐Ÿš€ Run Cypress - # uses: cypress-io/github-action@v2 - # 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' - # - # - name: โฌ† Upload screenshots - # uses: actions/upload-artifact@v1 - # 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 + test-e2e: + name: ๐Ÿงช E2E tests + needs: build + runs-on: ubuntu-16.04 + steps: + - name: โฌ‡ Checkout code + uses: actions/checkout@v2 + + - name: โฌ‡ Download build result + uses: actions/download-artifact@v1 + with: + name: dist + path: dist + - name: ๐Ÿ— Set up Python 3.7 + uses: actions/setup-python@v1 + with: + python-version: 3.7 + - name: ๐Ÿš€ Install wheel + run: | + pip install dist/OctoPrint-*-py2.py3-none-any.whl + + - name: ๐Ÿ— Create base config for test server + run: | + mkdir e2econfig + cp -r .github/fixtures/with_acl/* e2econfig + + - name: ๐Ÿš€ Run Cypress + uses: cypress-io/github-action@v2 + 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' + + - name: โฌ† Upload screenshots + uses: actions/upload-artifact@v1 + 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 publish-on-testpypi: name: ๐Ÿ“ฆ Publish on TestPyPI @@ -143,7 +143,7 @@ jobs: needs: - test-unit - test-install - #- test-e2e + - test-e2e runs-on: ubuntu-latest steps: - name: โฌ‡ Download build result diff --git a/src/octoprint/plugins/loginui/static/js/main.js b/src/octoprint/plugins/loginui/static/js/main.js index b053fafa6..86caa0df8 100644 --- a/src/octoprint/plugins/loginui/static/js/main.js +++ b/src/octoprint/plugins/loginui/static/js/main.js @@ -4,6 +4,12 @@ */ $(function() { + var OctoPrint = window.OctoPrint; + + OctoPrint.loginui = { + startedUp: false + } + var overlayElement = $("#login-overlay"); var errorElement = $("#login-error"); var offlineElement = $("#login-offline"); @@ -37,8 +43,6 @@ $(function() { return false; }); - var OctoPrint = window.OctoPrint; - OctoPrint.options.baseurl = BASE_URL; OctoPrint.socket.onConnected = function() { @@ -56,4 +60,5 @@ $(function() { }); OctoPrint.socket.connect(); + OctoPrint.loginui.startedUp = true; }); diff --git a/src/octoprint/static/js/app/main.js b/src/octoprint/static/js/app/main.js index 01e339ce1..c3d425cff 100644 --- a/src/octoprint/static/js/app/main.js +++ b/src/octoprint/static/js/app/main.js @@ -39,7 +39,8 @@ $(function() { mobile: false, desktop: false }, - viewmodels: {} + viewmodels: {}, + startedUp: false }; var browserVisibilityCallbacks = []; @@ -734,6 +735,8 @@ $(function() { // Use bootstrap tabdrop for tabs and pills $('.nav-pills, .nav-tabs').tabdrop(); + + OctoPrint.coreui.startedUp = true; }; var fetchSettings = function() { diff --git a/tests/cypress/integration/connect.js b/tests/cypress/integration/connect.js index 6960597e0..49e89fec2 100644 --- a/tests/cypress/integration/connect.js +++ b/tests/cypress/integration/connect.js @@ -23,9 +23,8 @@ describe('Connection test against virtual printer', () => { }); cy.visit('/'); - - cy.get('#navbar', {timeout: 10000}) - .should('be.visible'); + cy.window({timeout: 10000}) + .should('have.nested.property', 'OctoPrint.coreui.startedUp', true); }); it('connect & disconnect', () => { diff --git a/tests/cypress/integration/login.js b/tests/cypress/integration/login.js index a1c2676f3..fefb33fd3 100644 --- a/tests/cypress/integration/login.js +++ b/tests/cypress/integration/login.js @@ -2,10 +2,13 @@ describe('Login tests', () => { const username = 'admin'; const password = 'test'; - describe.skip('Successful login', () => { + describe('Successful login', () => { it('logs in', () => { cy.visit('/'); + cy.window() + .should('have.nested.property', 'OctoPrint.loginui.startedUp', true); + cy.get('#login-user') .type(username); cy.get('#login-password') @@ -13,9 +16,9 @@ describe('Login tests', () => { cy.get('#login-button') .click(); + cy.window({timeout: 30000}) + .should('have.nested.property', 'OctoPrint.coreui.startedUp', true); - cy.get('#navbar', {timeout: 10000}) - .should('be.visible'); cy.get('#navbar_login a.dropdown-toggle span') .should('contain', username); cy.getCookie('session_P5000') @@ -28,18 +31,21 @@ describe('Login tests', () => { it('logs in with remember me', () => { cy.visit('/'); + cy.window() + .should('have.nested.property', 'OctoPrint.loginui.startedUp', true); + cy.get('#login-user') .type(username); cy.get('#login-password') .type(password); - cy.get('#login-remember') .click(); + cy.get('#login-button') .click(); + cy.window({timeout: 30000}) + .should('have.nested.property', 'OctoPrint.coreui.startedUp', true); - cy.get('#navbar', {timeout: 10000}) - .should('be.visible'); cy.get('#navbar_login a.dropdown-toggle span') .should('contain', username); cy.getCookie('session_P5000') @@ -55,6 +61,9 @@ describe('Login tests', () => { it('logs in and logs out again', () => { cy.visit('/'); + cy.window() + .should('have.nested.property', 'OctoPrint.loginui.startedUp', true); + cy.get('#login-user') .type(username); cy.get('#login-password') @@ -63,14 +72,17 @@ describe('Login tests', () => { cy.get('#login-button') .click(); - cy.get('#navbar', {timeout: 10000}) - .should('be.visible'); + cy.window({timeout: 30000}) + .should('have.nested.property', 'OctoPrint.coreui.startedUp', true); cy.get('#navbar_login a.dropdown-toggle') .click(); cy.get('#logout_button') .click(); + cy.window({timeout: 30000}) + .should('have.nested.property', 'OctoPrint.loginui.startedUp', true); + cy.get('h2.form-signin-heading') .should('be.visible') .should('contain', 'Please log in'); @@ -80,6 +92,8 @@ describe('Login tests', () => { context('Unauthorized login attempts', () => { it('uses wrong user name', () => { cy.visit('/'); + cy.window() + .should('have.nested.property', 'OctoPrint.loginui.startedUp', true); cy.get('#login-user') .type('idonotexist'); @@ -91,6 +105,8 @@ describe('Login tests', () => { it('uses wrong password', () => { cy.visit('/'); + cy.window() + .should('have.nested.property', 'OctoPrint.loginui.startedUp', true); cy.get('#login-user') .type('admin');