question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`viewport` not getting recognized in CI

See original GitHub issue

Current behavior

packages:

"cypress": "^8.4.1",
"@cypress/vite-dev-server": "^2.1.0",
"@cypress/vue": "^2.2.3",
"@testing-library/cypress": "^8.0.1",

node version: 14.17.6

We setup Cypress Testing for e2e. Locally the viewportHeight and viewportWidth in the cypress.json is getting recognized and it works like a charm. => Tests are passing.

When we push to Github our GithubAction will execute yarn test:e2e which is described in the package.json as the following:

yarn build && concurrently --success=first -k "yarn serve" "cypress run --headless --config-file=cypress.json"

The weird behavior is that sometimes the tests are passing (probably the viewport option is getting recognized) and sometimes not. The test actually logs in a user and clicks a logout button in the sidebar navigation which is not visible in Mobile. (collapsed sidebar)

We tried a lot and also the solutions described in: https://github.com/cypress-io/cypress/issues/2102 but it did not work as well.

The behavior is flacky sometimes it fails sometimes it works.

CleanShot 2021-09-24 at 10 32 12@2x

First commit (passing) from screenshot above: CleanShot 2021-09-24 at 10 33 20@2x

Second commit (failing) from screenshot above: CleanShot 2021-09-24 at 10 34 04@2x

The Test which is failing caused by the invisible Logout Button collapsed in the sidebar. CleanShot 2021-09-24 at 10 34 40@2x

The code from the test which fails:

  it('User can log out', () => {
    cy.login()

    cy.get('button')
      .contains('Ausloggen')
      .click()

    cy.location().should((loc) => {
      expect(loc.pathname).to.eq('/login')
    })
  })

Desired behavior

No response

Test code to reproduce

Create a Github Action with the following:

# ...
    tests:
        name: "Tests"

        runs-on: "ubuntu-latest"

        strategy:
            matrix:
                node-version:
                    - "14.17.6"

        steps:
            -   if: github.actor != 'dependabot[bot]'
                name: "Checkout"
                uses: "actions/checkout@v2.3.4"
                with:
                  ref: "${{ github.head_ref }}"
                  token: "${{ secrets.DATANA_BOT_TOKEN }}"

            -   if: github.actor == 'dependabot[bot]'
                name: "Checkout"
                uses: "actions/checkout@v2.3.4"
                with:
                    ref: "${{ github.head_ref }}"

            -
                name: "Install Node.js"
                uses: "actions/setup-node@v2.4.0"
                with:
                    node-version: "${{ matrix.node-version }}"

            -
                name: "Determine yarn cache directory"
                id: "determine-yarn-cache-directory"
                run: "echo \"::set-output name=directory::$(yarn cache dir)\""

            -
                name: "Cache dependencies installed with yarn"
                uses: "actions/cache@v2.1.6"
                with:
                    path: "${{ steps.determine-yarn-cache-directory.outputs.directory }}"
                    key: "node-${{ matrix.node-version }}-yarn-${{ hashFiles('frontend/yarn.lock') }}"
                    restore-keys: "node-${{ matrix.node-version }}-yarn-"

            -
                name: "Install dependencies with yarn"
                run: "yarn install"

            -
                name: "Cypress End to end tests"
                run: "yarn test:e2e"

package.json

{
  "name": "frontend-datapool",
  "license": "UNLICENSED",
  "version": "0.0.0",
  "scripts": {
    "dev": "vite --mode dev",
    "build": "vite build",
    "serve": "vite preview",
    "api": "json-server --watch db.json --port 3004 --delay 450",
    "lint:script": "eslint \"src/**/*.{ts,vue}\"",
    "lint:tsc": "vue-tsc --noEmit",
    "lint": "concurrently 'yarn lint:tsc' 'yarn lint:script'",
    "test:e2e": "yarn build && concurrently --success=first -k \"yarn serve\" \"cypress run --headless --config-file=cypress.json\"",
    "cypress:open": "./node_modules/.bin/cypress open"
  },
  "dependencies": {
    "@headlessui/vue": "^1.4.0",
    "@heroicons/vue": "^1.0.4",
    "@intlify/vite-plugin-vue-i18n": "^2.4.0",
    "@tailwindcss/forms": "^0.3.3",
    "axios": "^0.21.1",
    "vue": "^3.2.6",
    "vue-debounce": "^3.0.1",
    "vue-i18n": "^9.1.7",
    "vue-router": "4",
    "vuex": "^4.0.2"
  },
  "devDependencies": {
    "@cypress/vite-dev-server": "^2.1.0",
    "@cypress/vue": "^2.2.3",
    "@testing-library/cypress": "^8.0.1",
    "@types/node": "^16.7.6",
    "@typescript-eslint/eslint-plugin": "^4.31.1",
    "@typescript-eslint/parser": "^4.31.1",
    "@vitejs/plugin-vue": "^1.6.1",
    "@vue/compiler-sfc": "^3.2.6",
    "autoprefixer": "^10.3.1",
    "concurrently": "^6.2.1",
    "cypress": "^8.4.1",
    "eslint": "^7.32.0",
    "eslint-config-prettier": "^8.3.0",
    "eslint-config-standard-with-typescript": "^20.0.0",
    "eslint-plugin-cypress": "^2.12.1",
    "eslint-plugin-import": "^2.24.0",
    "eslint-plugin-node": "^11.1.0",
    "eslint-plugin-promise": "^4.3.1",
    "eslint-plugin-vue": "^7.16.0",
    "json-server": "^0.16.3",
    "postcss": "^8.3.6",
    "tailwindcss": "^2.2.7",
    "typescript": "^4.3.2",
    "vite": "^2.5.4",
    "vue-tsc": "^0.2.2"
  }
}

cypress.json

{
  "testFiles": "**/*.spec.ts",
  "componentFolder": "src",
  "video":false,
  "baseUrl": "http://127.0.0.1:5000",
  "viewportWidth": 1440,
  "viewportHeight": 900
}

Cypress Version

8.4.1

Other

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
jennifer-shehanecommented, Sep 24, 2021

The viewportHeight and viewportWidth have nothing to do with the height and width passed to the launchOptions args. The height and width passed to the launchOptions changes the screen size when testing headlessly, so this would affect the video and screenshot sizes. The viewportHeight and viewportWidth change the size of the application under test within the iframe that Cypress is running - the thing to the right of the reporter.

The application under test in your case will render at a size of 1440x900, if you want to override that for any test, like making your app render at a mobile size, you could set cy.viewport() to do this or set viewportHeight and viewportWidth in any config overrides during the test.

Let me know if this helps.

1reaction
silasjoistencommented, Oct 1, 2021

We fixed it. By calling on every test case we wrote cy.viewport(). But this can’t be the real solution if we want to have tests for desktop size global. Is there a Flobal option?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Viewport is not visible and cannot be selected or adjusted ...
Solution: · On the command line type QSELECT. · Select 'Viewports' from the drop down list and click 'Ok'. · Move viewport to...
Read more >
Error: UnsupportedOperationError: pointer movements ...
This is a known issue with Selenium and is being tracked through Not correctly move pointer to the position inside of element in...
Read more >
Secret AutoCAD Command for Faster Viewports - YouTube
You know, creating a viewport, getting inside my viewport to arrange my drawing, picking a drawing scale, assigning a layer to my viewp ......
Read more >
Correct viewport | webhint documentation
Correct viewport ( meta-viewport ) meta-viewport warns against not having a single viewport meta tag in the <head> with the proper value.
Read more >
Parallelization | Cypress Documentation
If you have not set up your project yet, check out our Continuous Integration guide. ... Upon receiving requests from a CI machine,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found