mysterious-belgium-25713
12/08/2022, 8:16 PMsquare-honey-48197
12/08/2022, 8:55 PMassert
as well as expect
. From reading the cypress API, both should be valid assertion methods. All I'm wanting to do is make sure that startDate
and endDate
are equal, and have that assertion visible in the command log:
Typescript
// Validate custom date set is retained by checking
// if start and end date still match each other
export function validateCustomDateSelection() {
let startDate, endDate;
getCustomDateStartDateInput()
.invoke('val')
.then((date) => {
startDate = String(date).split('/')[1];
});
getCustomDateEndDateInput()
.invoke('val')
.then((date) => {
endDate = String(date).split('/')[1];
});
assert.equal(startDate, endDate);
// expect(startDate).to.eq(endDate);
}
gray-kilobyte-89541
12/08/2022, 9:31 PMsquare-honey-48197
12/08/2022, 9:35 PMcy.getDataCy('customDateStartDateInput');
gray-kilobyte-89541
12/08/2022, 9:37 PMstartDate
and endDate
before they get their values. See https://github.com/bahmutov/cypress-command-chainsquare-honey-48197
12/08/2022, 9:40 PMsquare-honey-48197
12/08/2022, 9:46 PMTypescript
getCustomDateStartDateInput().invoke('val').then(date => {
getCustomDateEndDateInput().should('have.value', date)
})
Ended up working well for megray-kilobyte-89541
12/08/2022, 9:49 PMsquare-honey-48197
12/08/2022, 9:50 PMpowerful-agency-55160
12/09/2022, 12:12 AMbillions-king-35651
12/09/2022, 12:35 AMcy.get('[data-cy="btc_coin_name"]')
but this will work:
cy.get('.children > .gap-y-10 > :nth-child(1) > .md\\:grid-cols-3 > :nth-child(1) > .justify-between.items-center > :nth-child(1) > .grid > [data-cy="btc_coin_name"]')
The layout of my code is basically something like:
// to show only element on big screen
<div class="hidden lg:block">
...code here
</div>
// to show only element on small screen
<div class="lg:hidden">
...code here
</div>
Please, what can I do as these class selectors are not maintable (because they can change anytime and the codebase is big). Thanksgreat-oil-15113
12/09/2022, 12:37 AMconst element = cy.get('[data-cy="btc_coin_name')
? it should be '[data-cy="btc_coin_name"]'
billions-king-35651
12/09/2022, 12:37 AMbillions-king-35651
12/09/2022, 12:40 AMbillions-king-35651
12/09/2022, 12:40 AMbillions-king-35651
12/09/2022, 12:41 AMgreat-oil-15113
12/09/2022, 12:43 AMbillions-king-35651
12/09/2022, 12:44 AMbillions-king-35651
12/09/2022, 12:45 AMbillions-king-35651
12/09/2022, 12:49 AMcy.get( '.max-w-7xl > .gap-y-10 > :nth-child(1) > .md\\:grid-cols-3 > :nth-child(1) > .justify-between.items-center > :nth-child(1) > .grid > [data-cy="btc_coin_name"]').should("be.visible");
The issue is that if any of the classes should change for any reason, the test will automatically fail, which I am trying to avoid. I have tried debugging this but no reasonable progressgreat-oil-15113
12/09/2022, 12:52 AMbillions-king-35651
12/09/2022, 12:53 AMbillions-king-35651
12/09/2022, 12:54 AM// to show only element on big screen
<div class="hidden lg:block" data-cy="desktop-layout-view">
...code here
</div>
// to show only element on small screen
<div class="lg:hidden" data-cy="mobile-layout-view">
...code here
</div>
billions-king-35651
12/09/2022, 12:56 AMgreat-oil-15113
12/09/2022, 12:58 AMcy.get('[data-cy=mobile-layout-view]').find('[data-cy=bit_coin_name]')
billions-king-35651
12/09/2022, 1:02 AMbillions-king-35651
12/09/2022, 1:02 AMgreat-oil-15113
12/09/2022, 1:04 AMdiv
and child span
?billions-king-35651
12/09/2022, 1:05 AMbillions-king-35651
12/09/2022, 1:05 AMspan
?