https://cypress.io logo
Join Discord
Powered by
# i-need-help
  • Cypress Tests fails sometimes but only in headless mode
    i

    incalculable-caravan-20607

    01/30/2023, 9:34 PM
    I'm using cypress v11 to run e2e tests in a React application, but in my machine, a few tests (specifically 3) are failing when all is tested. Things became weird when I run those tests alone, it passes. I tried to use the cypress browser to understand the issues, therefore this only occurs in headless mode. The pipeline of the project is running fine with all the tests in a Linux Ubuntu environment. I have a Macbook with M1 Pro, but I'm not sure if something is correlated. Does anyone has any idea?
  • List of failed test cases
    g

    great-oil-15113

    01/30/2023, 10:16 PM
    I know there must be many ways to do this, but is there an easy way to get a full list of all failed tests across all spec files? e.g. in the console / terminal output, show Failed tests: Test1 - XXXX Test2 - XXXX Test3 - XXXX ... Currently cypress run shows all information in terminal output including error messages. Sometimes it is too long to extract only failed test names. Cypress open shows all tests in test run, but there doesn't seem to be a filter to quickly get failed tests. Also it only shows one spec at a time. Is there a better way? Thanks
    b
    • 2
    • 2
  • ES Modules cannot be stubbed
    b

    breezy-plastic-64948

    01/30/2023, 10:41 PM
    Hello, In my Component Test I need to stub the
    useHistory
    hook of
    react-router-dom
    which is being imported and used by the component I am testing. This is what i am trying to do without success:
    Copy code
    import * as RRDom from 'react-router-dom';
    
    describe('My test', () => {
      it.only('test', () => {
        cy.stub(RRDom, 'useHistory').returns({
          push: () => {
            console.log('push stubbed!');
          },
        });
        cy.mount(<MyComp />);
        cy.contains('Click me').click();
      });
    })
    And here the simple Component
    Copy code
    import { useHistory } from 'react-router-dom';
    
    const MyComp = () => {
       const history = useHistory();
    
       return (
         <div onClick={() => history.push('/somewhere')}>
           Click me
         </div>
    }
    This code throw an error when running the test:
    ES Modules cannot be stubbed
    . We are currently using Vite. I don't want to touch the existing Component implementation by changing imports or whatsoever. We have choosen Cypress Component Testing instead of React Testing Library but this limitation that seems unsolvable is a main concern, please let me know
    • 1
    • 1
  • Intercept 2 network calls at the same time
    s

    straight-pencil-91170

    01/31/2023, 8:20 AM
    I got a button that when I click on, it sends 2 network calls with the same endpoint, and when I intercept 1 of them, it detects both of them, but I need only the 2nd call, how can I intercept only the 2nd call?
    n
    m
    g
    • 4
    • 13
  • @cypress/code-coverage : can't exclude *cy.ts from coverage report
    b

    billowy-pharmacist-61146

    01/31/2023, 10:02 AM
    I'm trying to collect the code coverage from
    *.cy.ts
    with
    @cypress/code-coverage
    and
    Istanbul
    . The problem is that I can't exclude the
    *.cy.ts
    files from coverage report. Here is my configuration : package.json :
    Copy code
    "devDependencies": {
        ...
        "@cypress/code-coverage": "3.10.0",
        "@istanbuljs/nyc-config-typescript": "1.0.2",
        "cypress": "12.4.1",
        "vite-plugin-istanbul": "4.0.0",
        ...
      },
    cypress.config.ts :
    Copy code
    import { defineConfig } from 'cypress'
    import registerCodeCoverageTasks from '@cypress/code-coverage/task'
    
    export default defineConfig({
      env: {
        codeCoverage: {
          exclude: ['cypress/**/*.*', 'src/**/*.cy.ts'],
        },
      },
      component: {
        devServer: {
          framework: 'vue',
          bundler: 'vite',
        },
        setupNodeEvents(on, config) {
          registerCodeCoverageTasks(on, config)
    
          return config
        },
      },
    })
    .nycrc.json :
    Copy code
    {
      "all": true,
      "extends": "@istanbuljs/nyc-config-typescript",
      "check-coverage": true,
      "include": [
        "src/**/*.ts",
        "src/**/*.vue"
      ],
      "exclude": [
        "src/**/*.cy.ts",
        "cypress/**/*.*",
        "**/*.d.ts",
        "**/*.cy.ts"
      ],
      "report-dir": "./coverage-cypress"
    }
    Anything I'm missing ? Thanks for your help !
    • 1
    • 1
  • Testing gRPC APIs with Cypress
    f

    future-piano-88787

    01/31/2023, 11:34 AM
    So guys, I'm using
    gRPC services
    for API and
    Cypress
    for e2e testing, and looks like Cypress doesn't have a way or plugin to testing this. Do we have some tricks or another way to testing gRPC APIs with Cypress. thanks.
    g
    e
    • 3
    • 5
  • Can I run Chrome in a separate container?
    o

    orange-alarm-20012

    01/31/2023, 3:07 PM
    With Selenium (via Laravel Dusk), I can run Chrome in a separate container or VM. The Selenium driver (in PHP in my case) talks to Chrome over an API. Can Cypress do the same or does Chrome need to be available in the same container / VM as NodeJS, where cypress is run from? Let me know if I can clarify any details there!
  • Cypress CLI hanging when clicking any element
    s

    stocky-insurance-27750

    01/31/2023, 3:58 PM
    I thought I'd fixed this after reading about
    element.trigger('click')
    but it was a mistake. We're using storybook to display the page. I'm using the 'full screen' mode so it's not iframe related. Very simple test
    Copy code
    cy.get('element').click()
    cy.url().should('include', '/stores')
    I've tried using
    .wait(5000).click()
    -
    focus().click()
    -
    click({force:true})
    and variations with `trigger('click')`too If I use the cypress ui - the test closes as soon as the click event is finished, it won't wait or anything, so I can't debug it. If I use the CLI in any way, the test hangs on the
    click()
    and doesn't do anything. If I use the
    trigger('click')
    the test runs but fails because the url doesn't change. Which makes me think the click isn't working there, either. Any ideas anyone? I've been trying this for a few hours now.
    w
    • 2
    • 9
  • Can I import faker plugin globally rather than in each spec?
    t

    thousands-house-85089

    01/31/2023, 4:17 PM
    Currently we're using faker package: https://www.npmjs.com/package/@faker-js/faker Following their instructions, we are using this code at the top of each spec.cy.js file which allows us to use faker in that one spec:
    Copy code
    js
    import { faker } from '@faker-js/faker';
    Is it possible to import this globally without needing to put it on every spec file? I've tried adding it to the e2e.js but it doesn't seem to work. Thanks
    s
    • 2
    • 6
  • Cypress freezes inside docker containers
    a

    aloof-airport-25580

    01/31/2023, 5:25 PM
    Hello! Starting from version included:10.8.0 found cypress freezes inside docker containers. Now I'm working on version included:12.4.1 the problem is relevant. Right now I'm running 8 containers distributing tests with --spec. Hangups happen randomly. From 0 to 6 containers per run. Hangups occur when transitioning to a test, or during a test, or after the end of a test. The hang occurs without any errors in the terminal. I am attaching screenshots of the modules used along with Cypress. How can I turn on the logs and understand in more detail what the problem is? Has anyone encountered a similar problem?
    b
    e
    +3
    • 6
    • 33
  • Dynamic Test Runner
    f

    fresh-sandwich-8289

    01/31/2023, 5:42 PM
    Hello Community, I'm building a dynamic test runner that reads fixtures and creates tests for each of the items of the fixtures. The system under test is a REST API. Each fixture is an array of "test cases", one fixture per endpoint. For example, we have one actions.json fixture containing a list of cases. Each fixture looks like this:
    Copy code
    [
      {
        "name": "Should get 2 actions",
        "type": "case",
        "test_config": {
          "method": "GET",
          "endpoint": "/actions",
          "query_parameters": {
            "limit": 2
          }
        },
        "expected": {
          "status_code": 200
        }
      },
      ...
    ]
    Then, a fixture called cases.json specifies which fixtures are needed to run:
    Copy code
    ["actions", "users", etc]
    All of this is to allow teams to only write fixtures for their endpoints, and our CI process compiles the required parts and executes the desired test cases. I'm struggling to find a proper strategy to load the fixtures. Using the cy.fixture command ties me to run it inside an it() block and that is complicating things and leading me to nasty
    let
    workarounds... Do you have any suggestion? Should I load the json files from the FS using cy.task? Thanks in advance
    g
    • 2
    • 2
  • I am running cypress on gitlab
    a

    acceptable-fall-11897

    01/31/2023, 6:36 PM
    I am running cypress on gitlab but get binary not found error
    e
    • 2
    • 1
  • Best practices for adding API tests to existing UI tests
    s

    silly-student-97216

    01/31/2023, 9:18 PM
    Hello again, I added my first API test to existing E2E UI tests. Is there any github repo or video with API and UI tests in one E2E test? I would like to see best practices and ideas. Thanks.
    b
    e
    • 3
    • 3
  • cy.visit() - first login session is taking too long
    f

    faint-xylophone-59151

    01/31/2023, 9:23 PM
    I use cy.session to cache the session and improve the login timing but it is taking too long the first time to login, also in headless mode is not considering the session, a test that last 30s is taking 1.30min to finish
    e
    • 2
    • 2
  • How to find the price?
    p

    powerful-answer-5604

    01/31/2023, 10:09 PM
    https://discord.com/channels/755913899261296641/1069764584770117682/1069764584770117682
  • How did they do it?
    s

    square-ability-8372

    01/31/2023, 11:22 PM
    Hello everyone, I was just curious on how did cypress track the number of dependent repositories (not packages) mentioned in their home page. Did they by any chance mine all those repositories, and can I get the list of repositories using cypress?
  • How can I get code coverage for all files when using vite with Istanbul ?
    a

    abundant-rose-56989

    02/01/2023, 9:36 AM
    Hi everyone ! I'm trying to get code coverage for component testing. I'm using Vue 3 with vite 4. I'm also using vite-plugin-istanbul. The issue I'm meeting, is that component testing uses vite internally with tree shaking, which makes my coverage only take care of imported files. So in the end, I can only get coverage for the tested files ^^'. Is there a way to tell cypress to include all files and avoid tree shaking ? Thanks for your help !
  • Time travel debugging doesn't work, every step says that elements aren't visible but app runs fine
    b

    busy-flower-19102

    02/01/2023, 10:40 AM
    Hello, I am trying to learn Cypress with its official guide and I have followed every step of it: https://learn.cypress.io/testing-your-first-application/installing-cypress-and-writing-your-first-test I have installed the app and it's running on localhost:3000. But when I run tests they are green so probably successful but I can't see any step of the tests, the app preview is always blank/white and Test Runner says that all the elements are not visible. You can see it in the picture I have attached. And yeah, the app preview on its own shows the page, but when I hover or click on any step that says the elements are not visible, the app preview is blank/white. But when I try to let's say visit Google page and get then it highlights the page in app preview and elements are visible. So it's probably a problem with the app?
    s
    c
    +2
    • 5
    • 7
  • Cypress local host will not launch
    b

    best-window-49967

    02/01/2023, 10:50 AM
    I am trying to setup cypress on my work laptop but for some reason i am unable to open the local host to run cypress, can you please advise if i am missing some thing in settings, i think it has some thing to do with firewall settings but i have tried opening cypress with firewall settings off still dont work, can some one advise please.
    s
    e
    • 3
    • 7
  • What is the correct way to test a link opening in a new tab?
    b

    brash-plumber-67474

    02/01/2023, 12:26 PM
    Suppose there is an anchor tag or a button in an application. Clicking on that anchor tag or button opens up a new application in a new tab. I want to test if that new app opened correctly after the click event. What should be the correct way of testing it in Cypress? How I am trying to test is, I am spying on the window.open function and then making an assertion if the window.open function was called with an expected URL argument. Below is a sample test for this same scenario: describe('Global Navigation', () => { it(
    should open app in new tab
    , () => { cy.mount(); cy.spy(window, 'open').as('windowOpen'); const uniqueAppName = 'Sample App'; const expectedURL = 'http://localhost/sampleapp'; cy.contains(uniqueAppName).should('be.visible').click(); cy.get('@windowOpen').should('have.been.calledWith', expectedURL, '_blank'); }); }); But the problem is the URL that opens up in new tab return 404 error and I know that it will return 404 because it is a dummy URL. I don't care whatever that new tab returns I just wanted to test if that URL was called by window.open function. While running the test in Cypress desktop app (using cypress open command) the test shows it passed and runs all the other tests as well. But when running the test using
    cypress run
    command (in headless mode), the CLI passes the current test then throws error 404 and exits out and does not run rest of the tests. Is there a way to just ignore that error because I am anyway expecting it? I have attached the error message. If you think this is an incorrect approach to test a link in new tab, please do suggest what should be the right approach? Another query: If I am expecting an error that is known, like in above scenario I knew I will be getting a 404 error, is it a good practice to do error handling in a test environment like using try-catch blocks?
    g
    e
    t
    • 4
    • 4
  • stimulus.js controller unit testing
    b

    bitter-agent-2072

    02/01/2023, 6:13 PM
    Has anyone used cypress to unit test stimulus js controllers before?
  • APK support
    f

    famous-table-6116

    02/01/2023, 7:11 PM
    Hello. I work for a device detection company. I was wondering if it’s possible to use a specific version of a browser for testing, by means of an APK for example, to validate that our detection solution works across a variety of browsers/devices.
    e
    • 2
    • 1
  • How to specify test record message name on Cypress Cloud ?
    w

    wide-book-80078

    02/02/2023, 2:47 AM
    Hi, i'm currently integrate Lambdatest with Cypress Cloud. The point is when using the lambdatest, it only run the test suite from cypress, not from the source code, therefore, there are no commit message. So is there an available command to specify the message in "cypress run" so it can have more meaningful name for the record ?
  • Vue - Mount with v-model
    b

    billowy-pharmacist-61146

    02/02/2023, 10:56 AM
    Hello ! With
    cypress/vue
    , is there a way to mount a component and deal with v-model ?
  • Clicking Element takes it back to the cypress test runner list
    a

    able-thailand-97732

    02/02/2023, 11:00 AM
    Hello everyone, there was such a question, but I could not help. If anyone knows, can we help? Here are screenshots Questions: "After mouseover in the first picture, the place marked with red is clicked, but the page stays like this. When you run the test again, it either stays like this or back to cypress test runner list in the second picture."
  • Events - Environment Variables vs WriteFile
    b

    bored-bear-79292

    02/02/2023, 11:31 AM
    I'm trying to create a list of values during the tests execution adding them to an environment variable. After all the tests execute, I want to write those values into a file. If I use the event 'after: spec' on the file cypress.config.js, I can't access the environment variables but I can write into files using 'fs-extra' If I use the event 'test:after:run' on the commands.js, I can acess to the environment variables but I can't write into a file. Using cy.writeFile doesn't trigger any error but doesn't do anything. If I import fs-extra inside the file commands.js const fs = require('fs-extra') I get an error ---- When Cypress detects uncaught errors originating from your test code it will automatically fail the current test. Cypress could not associate this error to any specific test. We dynamically generated a new test to display this failure. node_modules/fs-extra/lib/fs/index.js:121:1 119 | 120 | // fs.realpath.native sometimes not available if fs is monkey-patched > 121 | if (typeof fs.realpath.native === 'function') { | ^ 122 | exports.realpath.native = u(fs.realpath.native) 123 | } else { 124 | process.emitWarning( So, I'm a little blocked
    g
    • 2
    • 5
  • Help identifying the Cypress code for changing HTML structure.
    c

    curved-air-49341

    02/02/2023, 12:18 PM
    The second screenshot shows that when the mouse hovers, the HTML structure changes and gives us 2 list items. However, the first screenshot shows that a three-structured HTML structure is visible when the mouse is not at the search bar. If you could help me with how to automate this problem.
  • Element not visible
    c

    cold-author-79999

    02/02/2023, 12:49 PM
    Hi, a 'td' element of a table is not visible in cypress view.So it cannot click that element.How do i solve this now?Appreciate your answers.
    l
    • 2
    • 1
  • When using type() first letter gets cut out
    b

    brash-tiger-52405

    02/02/2023, 1:28 PM
    Hello, when i try to type into a textfield thie first characters are missing. cy.get('[data-cy="textfield"]') .focus() .clear() .type("Hello World!", {timeout: 10000}) .should('have.value', 'Hello World!');
    e
    g
    s
    • 4
    • 4
  • Cy.origin with Custom Commands?
    e

    echoing-tent-95037

    02/02/2023, 5:17 PM
    Are we not able to do this? Im currently seeing errors when trying to implement this. Is there another way to achieve this?
    c
    • 2
    • 6
1...456...26Latest