rich-mechanic-52238
01/10/2023, 8:30 PMmodern-dawn-86006
01/10/2023, 8:31 PMrich-mechanic-52238
01/10/2023, 8:34 PMmodern-dawn-86006
01/10/2023, 8:37 PMmodern-dawn-86006
01/10/2023, 8:52 PMrhythmic-lizard-86607
01/11/2023, 12:09 AMbland-machine-99046
01/11/2023, 7:50 AMbland-machine-99046
01/11/2023, 8:22 AMbland-machine-99046
01/11/2023, 8:23 AMbland-machine-99046
01/11/2023, 8:24 AMimportant-room-45301
01/11/2023, 10:02 AMlemon-oxygen-25956
01/11/2023, 10:47 AMdry-portugal-25841
01/11/2023, 11:42 AMcypress/fixtures/
, you probably should refactor your project structure, check the docs or examples on githubhappy-baker-38999
01/11/2023, 1:59 PMgreen-controller-97889
01/11/2023, 2:33 PMjs
Cypress.Commands.add("checkMenu", (currentPageTitle) => {
cy.get("[data-cy='_select']").should("exist");
cy.get("[data-cy='_select']").then((menu) => {
console.log(menu);
cy.log("Check if menu renders with the proper active page title");
menu.should("exist");
menu.contains(currentPageTitle);
menu.children().should("have.length", 2);
cy.log("Check if dropdown is visible after click");
menu.trigger("click");
menu.find("_dropdown").should("be.visible");
debugger;
});
});
but it doesn't work saying that menu.should("exist");
is not a function.
So cy.get("[data-cy='_select']").should("exist");
works.
But when inside cy.get("[data-cy='_select']").then((menu) => {}
the menu.should("exist");
returns the error mentioned above.
How come ?
It is a basic and fairly simple test.stale-optician-85950
01/11/2023, 3:07 PMcy.wrap(menu).should("exist");
https://docs.cypress.io/api/commands/wrapgray-kilobyte-89541
01/11/2023, 3:17 PMgreen-controller-97889
01/11/2023, 3:31 PMcy.get("[data-cy='_select']").should("exist");
.
Maybe I didn't have to use `.then()`;
@stale-optician-85950 @gray-kilobyte-89541 I still don't understand why it didn't work though. There is no explanation.
Why does wrap()
exist if we have get()
?
Why doesn't cy.get("[data-cy='_select']").then((menu) => {
give me the menu
as it should ?gray-kilobyte-89541
01/11/2023, 4:15 PMshould
and the same for .then
So there is no "should" method on jQuery object. You can use built-in Chai-jQuery assertion then(menu => expect (menu).to.exist)
BUT the existence assertion is already built into cy.get
command, so that is unnecessary. Your code snippet would be something like
js
cy.get('...menu selector')
.within(() => {
cy.get('children selector').should('have.length', 2)
cy.contains(title)
cy.log('opening ...')
})
.click()
cy.get('opened element selector').should('be.visible')
Note I did not attach cy.get
at the end after the ".click" to avoid DOM detached error, since the menu might re-render completelyripe-pilot-34121
01/11/2023, 4:56 PMsome-keyboard-52751
01/11/2023, 5:20 PMmodern-dawn-86006
01/11/2023, 6:17 PMmodern-dawn-86006
01/11/2023, 6:19 PMripe-pilot-34121
01/11/2023, 6:20 PMripe-pilot-34121
01/11/2023, 6:21 PMmodern-dawn-86006
01/11/2023, 6:30 PMagreeable-refrigerator-17485
01/11/2023, 7:52 PMmagnificent-finland-58048
01/11/2023, 8:04 PMagreeable-refrigerator-17485
01/11/2023, 8:07 PMmysterious-psychiatrist-29678
01/11/2023, 9:09 PMcy.get('.fxc-dropdown-input')
.should(($dropdown) => {
expect($dropdown).not.have.text('Loading...')
cy.contains('.fxc-dropdown-filter', 'Resource group')
.find('.fxc-dropdown-input')
.click()
.then(() => {
cy.contains('[role="treeitem"]', groupToSelect, {timeout: 10000})
.should('be.visible')
.click()
})
thanks so much.