https://cypress.io logo
Join Discord
Powered by
# e2e-testing
  • m

    mysterious-psychiatrist-29678

    12/12/2022, 2:15 PM
    hi. could you help me in clicking a dropdown. I want to click on the dropdown, pick an item, click it, then move forward. it should not be a problem but still not working whatever wait I put in the code
    Copy code
    cy.get('.fxc-dropdown-input', {timeout: 40000}).eq(1)
      .click()
      .contains('ab-selenium-test-do-not-delete', {timeout: 20000})
      .should('be.visible')
      .click() 
      cy.contains('Next').click()
    here is what Cypress says about the error. finding 'ab-selenium-test-do-not-delete' is obivously failing as the dropdown containing it didn't load. what would you suggest to try out as I've run out of ideas for now. thanks
  • t

    thousands-house-85089

    12/12/2022, 2:22 PM
    For dropdowns, cypress should allow you to simply use *cy.get(element) .select("value")* Does this not work?
  • t

    thousands-house-85089

    12/12/2022, 2:26 PM
    You may also need to call the element a 2nd time rather than chaining it all. This is my code for checking that a quantity drop-down defaults to value "1" then selecting value "6"
  • t

    thousands-house-85089

    12/12/2022, 2:27 PM
    I recall having to use .then and re-getting the element to select value.
  • m

    mysterious-psychiatrist-29678

    12/12/2022, 2:31 PM
    select() not working as I don't have select element
    Copy code
    cy.select() can only be called on a <select>. 
    Your subject is a: <div class="azc-formElementContainer">...</div>
  • t

    thousands-house-85089

    12/12/2022, 2:43 PM
    If you inspect the element does it show you a list of options like this?
  • t

    thousands-house-85089

    12/12/2022, 2:43 PM
    Sounds like you may be selecting the wrong element
  • v

    victorious-summer-2999

    12/12/2022, 2:48 PM
    Is there a way to call
    session
    without having it clearing everything? for instance in my app I need some cookies/LS etc. to run tests and when I call
    cy.session
    for login then I lose those setups. Is there a way to build a session on top of existing cookies/LS ? from the docs
    The page is cleared before setup when testIsolation is enabled and is not cleared when testIsolation is disabled.
    Is there a way to only specify this
    test isolation
    parameter at a function level? I'd not like to lose the
    test isolation
    globally. @gray-kilobyte-89541
  • m

    mysterious-psychiatrist-29678

    12/12/2022, 2:51 PM
    my frontend code is more complex, even not our code to be honest. but I have role='tree' and 'treeitem' elements
  • t

    thousands-house-85089

    12/12/2022, 3:07 PM
    Have you tried doing something like in my screenshot example using a nested then.() and re-getting the element? cy.get('.fxc-dropdown-input') .eq(1) .click() .then(() => { cy.get('.fxc-dropdown-input') .should('be.visible') .and('contain', 'ab-selenium-test-do-not-delete') .click() })
  • t

    thousands-house-85089

    12/12/2022, 3:07 PM
    Something like the above code
  • t

    thousands-house-85089

    12/12/2022, 3:08 PM
    Without seeing your actual web app it's hard to help further
  • m

    mysterious-psychiatrist-29678

    12/12/2022, 3:17 PM
    tried and not working, still the dropdown doesn't load. not sure how to share code with you. I'm testing Azure integration so the frontend comes from Microsoft not on us
  • t

    thousands-house-85089

    12/12/2022, 3:19 PM
    Well in your original code, it's not finding .contains('ab-selenium-test-do-not-delete' (doesn't exist in the element) because it probably wasn't there until after you did .click()
  • t

    thousands-house-85089

    12/12/2022, 3:19 PM
    So I suspect after your .click() you need to get the element again first before trying the .contains part
  • t

    thousands-house-85089

    12/12/2022, 3:20 PM
    IDK how MS developed the front-end you are using, not familiar with Azure integration, so maybe they didn't use a dropdown in the same way that select() can interact with
  • t

    thousands-house-85089

    12/12/2022, 3:22 PM
    what happens if you do this? *cy.get('.fxc-dropdown-input') .click() .within(() => { cy.contains('ab-selenium-test-do-not-delete') })*
  • t

    thousands-house-85089

    12/12/2022, 3:22 PM
    ^ does it still error trying to find 'ab-selenium-test-do-not-delete' ?
  • t

    thousands-house-85089

    12/12/2022, 3:28 PM
    (I am assuming that 'ab-selenium-test-do-not-delete' is a value in your drop-down list)
  • m

    mysterious-psychiatrist-29678

    12/12/2022, 3:29 PM
    appreciate your help @thousands-house-85089 in the meantime I sorted out if start with this way it fails
    cy.get('.fxc-dropdown-input', {timeout: 40000}).eq(1)
    but if I put implicite wait it succeeds
    Copy code
    cy.wait(37000)
    cy.get('.fxc-dropdown-input', {timeout: 40000}).eq(1)
    so meaning even the dropdown clickable the page still not loaded fully. I don't want to use implicite wait what other way I can do?
  • t

    thousands-house-85089

    12/12/2022, 3:30 PM
    Ok so the issue might be that your integration component isn't loaded when the page tells Cypress it has finished loading?
  • g

    gray-kilobyte-89541

    12/12/2022, 3:31 PM
    I don't use
    cy.session
    , instead I prefer https://github.com/bahmutov/cypress-data-session
  • t

    thousands-house-85089

    12/12/2022, 3:33 PM
    This is a tricky one, and I had similar problems working with SPA pages. Does the MS Azure component have a loading overlay or spinner until it's fully loaded on the page?
  • t

    thousands-house-85089

    12/12/2022, 3:34 PM
    If so you can find that element and get cypress to check it does not exist - which means it will wait until it goes away However this might be difficult without access to developers of the component who could tell you which element to call.
  • t

    thousands-house-85089

    12/12/2022, 3:35 PM
    ^ In this case .loading element is a spinner overlay on the SPA and I wait for it not to exist with this code before it continues the next part of the test (as it doesn't do a full page reload under SPA)
  • m

    mysterious-psychiatrist-29678

    12/12/2022, 4:00 PM
    no it's completely invisible if loading
  • m

    mysterious-psychiatrist-29678

    12/12/2022, 4:00 PM
    seems so
  • t

    thousands-house-85089

    12/12/2022, 4:02 PM
    Prob first thing in your test needs to be this then (with an element of either the main integration component, or some element within it) cy.get() .should('be.visible')
  • t

    thousands-house-85089

    12/12/2022, 4:02 PM
    so once you navigate to the page, this will wait on your global timeout for the element to appear before moving on to the rest of your dropdown tests
  • t

    thousands-house-85089

    12/12/2022, 4:04 PM
    Basic idea would be same as SPA, find the element that you want to test and wait for it to appear with a .should('be.visible') or .should('not.exist') etc.
1...166167168...192Latest