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

    thousands-house-85089

    01/17/2023, 11:40 AM
    not sure, new tabs/windows are one of the difficult things with Cypress. There's some docs about it but best practice is to rather navigate in the main window to the URL from the popup instead
  • l

    lively-balloon-98986

    01/17/2023, 11:41 AM
    ok
  • l

    lively-balloon-98986

    01/17/2023, 11:42 AM
    and is there a way to allow or block in electron?
  • t

    thousands-house-85089

    01/17/2023, 11:42 AM
    https://docs.cypress.io/guides/references/trade-offs#Multiple-tabs
  • l

    lively-balloon-98986

    01/17/2023, 11:43 AM
    yes saw this one - but in electron it open new window and not TAB
  • t

    thousands-house-85089

    01/17/2023, 11:44 AM
    It's a bespoke chromium-based browser meant to be performant for web app development, it's not a commercial browser and I don't know if it has specific settings you can change. If your test behaves differently in it, you are probably better off testing the 'real' browsers that users will have.
  • l

    lively-balloon-98986

    01/17/2023, 11:45 AM
    ok
  • t

    thousands-house-85089

    01/17/2023, 11:45 AM
    I mostly run my tests with Chrome, but sometimes electron is useful as it's very quick. It's likely just something that is bundled with Cypress to ensure there is at least 1 browser on the system running cypress open mode.
  • l

    lively-balloon-98986

    01/17/2023, 11:46 AM
    ok thanks a lot for your informative answer
  • t

    thousands-house-85089

    01/17/2023, 11:46 AM
    you're welcome, glad to help 🙂
  • p

    purple-afternoon-2408

    01/17/2023, 12:02 PM
    Hello team, how can I mix
    should
    with
    click
    ? based on the docs, I should use
    then
    (https://docs.cypress.io/api/commands/should#Whats-the-difference-between-then-and-shouldand), so it's not working, I tried:
    Copy code
    .should('not.have.attr', 'disabled')
            .then(($el) => {
              cy.wrap($el).click(); // also tried without the cy.wrap(), by using $el.click(); directly
            });
    and:
    Copy code
    .should('not.have.attr', 'disabled').then().click();
  • p

    purple-afternoon-2408

    01/17/2023, 12:06 PM
    I also tried creating a variable of the obtained element before disabled attribute is gone, and call that variable element, but it's not working either (assuming cuz the element changed?)
  • t

    thousands-house-85089

    01/17/2023, 12:24 PM
    I'm not sure the element from the .get() carries over as the subject after you do a .then() so you might need to get the element again within the .then() block e.g.
    Copy code
    js
    cy.get('#purchase_quantity')
                    .contains("1")
                    .then(() => {
                        cy.get('#purchase_quantity')
                          .select("6");
                    })
  • p

    purple-afternoon-2408

    01/17/2023, 12:25 PM
    Your example doesn't mix the
    should
    and
    click
  • t

    thousands-house-85089

    01/17/2023, 12:26 PM
    replace .select("6") with .click()
  • t

    thousands-house-85089

    01/17/2023, 12:26 PM
    Still the issue probably lies in having to re-get the element within the .then
  • p

    purple-afternoon-2408

    01/17/2023, 12:26 PM
    ahh, you mean re-query the element using
    get
  • t

    thousands-house-85089

    01/17/2023, 12:26 PM
    yeah
  • t

    thousands-house-85089

    01/17/2023, 12:26 PM
    get element, do something, then > get element again, do click
  • p

    purple-afternoon-2408

    01/17/2023, 12:27 PM
    Why should I use
    then
    ? I am currently doing:
    Copy code
    .should('not.have.attr', 'disabled');
    cy.get('...').click();
  • p

    purple-afternoon-2408

    01/17/2023, 12:27 PM
    I just don't like repeating code
  • t

    thousands-house-85089

    01/17/2023, 12:27 PM
    You only need to use it if there are async execution issues with the code running
  • t

    thousands-house-85089

    01/17/2023, 12:28 PM
    as it forces cypress to wait for the first bit before running the .then commands, instead of queueing it all up and running in a possibly weird order
  • p

    purple-afternoon-2408

    01/17/2023, 12:28 PM
    Which code? Application code or Cypress code?
  • t

    thousands-house-85089

    01/17/2023, 12:28 PM
    cypress
  • t

    thousands-house-85089

    01/17/2023, 12:29 PM
    there are some cases I have found when chaining commands like my above example where the test executes asynchronously and exhibits some weird behaviour (javascript wizardry I never understand). So chaining a .then() forces it to clear the previous code first and then move on to the code inside the .then() block. So in some cases I have found it solves the issue when writing my tests without it gives an error or unexpected results.
  • t

    thousands-house-85089

    01/17/2023, 12:30 PM
    But that code inside the then() isn't aware of the .get element from before
  • t

    thousands-house-85089

    01/17/2023, 12:31 PM
    I have this in my code which works fine
    Copy code
    js
    cy.get('.edit-delivery-options')
              .should('contain', "Mainland UK")
              .click()
  • t

    thousands-house-85089

    01/17/2023, 12:32 PM
    So I cannot say why it wouldn't chain in your case, the .should() and the .click() both work against the .get() element. Sometimes it just seems to depend on the app behaviour and how the test interacts with the browser under certain cases.
  • p

    purple-afternoon-2408

    01/17/2023, 12:32 PM
    Hmm, interesting
1...188189190191192Latest