https://cypress.io logo
Join Discord
Powered by
# help
  • b

    bland-pharmacist-88362

    06/23/2022, 9:26 AM
    I need to iterate over every element until i find a specific button. How can achieve this in cypress?
    Copy code
    let found =  false;
        cy.get('mat-panel-title').should('be.visible').each(($el, index) => {
          cy.wrap($el).click();
          cy.get('body').then(($body) => {
            if ($body.find('.startButton').filter(':visible').length) {
              console.log($body.find('.startButton').filter(':visible'));
              found = true;
            }
          console.log(found);
          if (found) return false;
          })
          // need to find button with class startButton
        });
  • b

    bland-pharmacist-88362

    06/23/2022, 9:28 AM
    and I want to stop the each once i find it.
  • b

    bland-pharmacist-88362

    06/23/2022, 9:28 AM
    so basically i need to get something like if button.exists return false
  • b

    bland-pharmacist-88362

    06/23/2022, 9:28 AM
    but i cannot think of a way to do this in cypress
  • a

    ancient-park-71356

    06/23/2022, 10:24 AM
    Hi guys! I'm trying to add personal certificate in config - for me it's .p12 file but after running cypress I have an error: "Failed to load client certificates for clientCertificates[0]: Unable to extract subject from PFX file: Cannot read properties of null (reading 'subject')". Do you maybe know how can I solve it?
  • f

    fresh-doctor-14925

    06/23/2022, 10:24 AM
    Could you explain why it's necessary to iterate like this? If it's just a case of finding
    .startButton
    , there are simpler ways to approach this
  • b

    bland-pharmacist-88362

    06/23/2022, 10:33 AM
    yes there are accordions that i need to first open in order to see if there is a button available there So the workflow is like that click on the accordion > it opens > check if there is button > if not go next/ if there is stop iterating
  • g

    gray-kilobyte-89541

    06/23/2022, 10:34 AM
    cypress-recurse plugin is your friend, but this conditional testing is an anti-pattern
  • b

    bland-pharmacist-88362

    06/23/2022, 10:37 AM
    so how would you test this type of feature if i might ask?
  • f

    fresh-doctor-14925

    06/23/2022, 10:40 AM
    I'd place test ids on the accordions and have more of a concrete idea of where I want the test to click. I'm also not a fan of the conditional approach
  • g

    gray-kilobyte-89541

    06/23/2022, 10:57 AM
    Can you set up HTML codespace showing the app you are trying to test? I don't want to spend time setting it up incorrectly
  • b

    bland-pharmacist-88362

    06/23/2022, 10:59 AM
    https://codebeautify.org/htmlviewer/y22bf94fb
  • b

    bland-pharmacist-88362

    06/23/2022, 10:59 AM
    it looks and works almost like this
  • b

    bland-pharmacist-88362

    06/23/2022, 11:00 AM
    so it should open section 1, there is no button so it should look for it in the next section which is section 2 and as you can see there is a button so it should stop looking for button
  • b

    bland-pharmacist-88362

    06/23/2022, 11:01 AM
    and the count of accordions can be different
  • b

    bland-pharmacist-88362

    06/23/2022, 11:01 AM
    so right now i can have 3 but tomorrow i can have 43
  • d

    dry-night-91027

    06/23/2022, 11:41 AM
    Hey! I have recently upgraded to Cypress version 10. I am using Cucumber for my tests. I have updated the library @freezing-piano-2792/cypress-cucumber-preprocessor as per version10 and did the relevant changes. For me, when I try to execute my code it give me the error as below: Error: You installed esbuild on another platform than the one you're currently using. This won't work because esbuild is written with native code and needs to install a platform-specific binary executable. Specifically the "esbuild-darwin-arm64" package is present but this platform needs the "esbuild-darwin-64" package instead. People often get into this situation by installing esbuild on Windows or macOS and copying "node_modules" into a Docker image that runs Linux, or by copying "node_modules" between Windows and WSL environments. If you are installing with npm, you can try not copying the "node_modules" directory when you copy the files over, and running "npm ci" or "npm install" on the destination platform after the copy. Or you could consider using yarn instead which has built-in support for installing a package on multiple platforms simultaneously. If you are installing with yarn, you can try listing both this platform and the other platform in your ".yarnrc.yml" file using the "supportedArchitectures" feature: https://yarnpkg.com/configuration/yarnrc/#supportedArchitectures Keep in mind that this means multiple copies of esbuild will be present. Another alternative is to use the "esbuild-wasm" package instead, which works the same way on all platforms. But it comes with a heavy performance cost and can sometimes be 10x slower than the "esbuild" package, so you may also not want to do that.` I am using macOS having M1 chip, so esbuild-darwin-arm64 package is installed instead of esbuild-darwin-64. Please suggest how to resolve this issue. Thanks!
  • g

    gray-kilobyte-89541

    06/23/2022, 12:09 PM
    please do not tag individual people in generic questions @dry-night-91027
  • g

    gray-kilobyte-89541

    06/23/2022, 12:13 PM
    is the markup static? I mean is the button already in the markup like in your code example, or is it added / rendered into the DOM on the accordion click? If it is static, you can use
    :has
    selector
  • p

    prehistoric-fireman-62402

    06/23/2022, 12:47 PM
    Thanks for the update! I think my problem is the new window looks for opener.document (originating window), which contains the button to open this new window, but cannot see or find it... seems Cypress detaches the new window in some way? So my new window will not function as expected due to undefined error, where the app itself cannot find an element from the initialiser.
  • q

    quaint-airplane-96634

    06/23/2022, 1:00 PM
    Hello everyone, I am facing issue, when my tests opens a new tab/window from a link and want switch to the new window, Tests opens a new tab after clicking the link, I get error in the console :
    expected open to have been called at least once, but it was never called
    . (Screenshot is attached), Link is dynamic in nature, I also tried to fetch the
    href
    of it , but its bind with javascript:
    javascript void(0)
    . Can someone help to achieve this?
  • g

    gray-kilobyte-89541

    06/23/2022, 2:23 PM
    Here is my first solution, without iteration: https://glebbahmutov.com/cypress-examples/9.7.0/recipes/find-and-click-accordion-button.html and

    https://youtu.be/U6oqiu12rfg▾

  • l

    limited-room-30929

    06/23/2022, 3:00 PM
    https://giphy.com/gifs/SVT-midsummer-midsommar-lasse-berg-QVhHqBGDGCAwZZey2W
  • l

    limited-room-30929

    06/23/2022, 3:00 PM
    found the accordion 😄
  • f

    flaky-airport-12178

    06/23/2022, 3:06 PM
    Hi team, Do you know how to config the total timeout for each cypress test script without using the configuration for each timeout (defaultCommandTimeout... etc)? For example, if the test takes more 2 minutes, stop this test case.
  • a

    agreeable-painting-90494

    06/23/2022, 3:15 PM
    Hi Folks, anyone having issues with Cy10 on CI?
  • a

    agreeable-painting-90494

    06/23/2022, 3:16 PM
    We are getting: -
  • a

    agreeable-painting-90494

    06/23/2022, 3:16 PM
    Copy code
    libva error: va_getDriverName() failed with unknown libva error,driver_name=(null)
    [491:0623/144443.249266:ERROR:sandbox_linux.cc(377)] InitializeSandbox() called with multiple threads in process gpu-process.
    [491:0623/144443.251818:ERROR:gpu_memory_buffer_support_x11.cc(44)] dri3 extension not supported.
  • a

    agreeable-painting-90494

    06/23/2022, 3:17 PM
    It was working ok with the same docker image on v9
  • a

    agreeable-painting-90494

    06/23/2022, 3:17 PM
    I have debug output if that helps any
1...949596...252Latest