white-raincoat-83199
08/18/2022, 11:14 AM// test.cy.ts
beforeEach(() => {
cy.wait(300);
});
afterEach(() => {
cy.wait(100);
});
describe('Test ', () => {
it('Go to homepage ', () => {
cy.visit('/');
});
it('Login ', () => {
login();
});
it('Profile ', () => {
profile();
});
})
After finish test with error, I check cookie that save logged user info, it isn't exsistblue-battery-71202
08/18/2022, 11:16 AMts
beforeEach(() => {
cy.wait(300);
cy.session('login', () => {
login();
});
});
afterEach(() => {
cy.wait(100);
});
describe('Test ', () => {
it('Go to homepage ', () => {
cy.visit('/');
});
it('Profile ', () => {
profile();
});
})
blue-battery-71202
08/18/2022, 11:17 AM'login'
is an ID for that particular session. Every time you call cy.session with the same ID you have to have the same content inside of it, but don't worry, it won't call twice, only once in the cypress lifetime.
So first time it will login properly (clicking, anything u have there) then it just restores the cookies, and storage from that session, and by that it imitates a "login"red-toothbrush-22589
08/18/2022, 11:21 AMblue-battery-71202
08/18/2022, 11:23 AMcy.url
will yield the current URL. then you can check with .contains()microscopic-crowd-9149
08/18/2022, 12:30 PMpurple-receptionist-35308
08/18/2022, 12:39 PMsparse-piano-30763
08/18/2022, 2:35 PMfancy-dog-10840
08/18/2022, 3:02 PMflaky-beach-50459
08/18/2022, 5:16 PMbrief-restaurant-78755
08/18/2022, 8:39 PMfresh-nail-30646
08/18/2022, 8:51 PMcommands.js
and add them as custom commands? I thought I had done it, but I keep getting errors.fast-artist-45202
08/18/2022, 9:21 PMfast-napkin-28259
08/19/2022, 8:00 AMcy.get('div').then((el) => el.index())
returns a Chainable<number>
, but how can I extract the number?high-restaurant-93761
08/19/2022, 8:22 AMCypressError: Timed out retrying after 4000ms: `cy.its()` errored because the property: `$nuxt` does not exist on your subject.
high-restaurant-93761
08/19/2022, 8:23 AMpolite-animal-57579
08/19/2022, 10:26 AMacceptable-hamburger-48790
08/19/2022, 11:13 AMlemon-toothbrush-55306
08/19/2022, 11:18 AMjs
<Tooltip label={t('words.unlink')} hasArrow>
<IconButton
data-test-id={`unlink-token-${tokenId}`}
icon={<BiTrash />}
size="sm"
colorScheme="red"
variant="outline"
onClick={openRemove}
/>
</Tooltip>
And my test:
js
it('Disassociate FT', () => {
cy.contains(accountId).click({ force: true });
cy.get('[placeholder="Escribe tu contraseña"]').type(defaultPass);
cy.contains('Continuar', { timeout: 12000 }).click();
cy.getBySel('unlink-token-0.0.2276691').click({force:true});
cy.getBySel('button-portal-footer-right', { timeout: 4000 }).click();
});
When I inspect the element has the correct property but Cypress is telling me:
js
Syntax error, unrecognized expression: [data-test-id=unlink-token-0.0.2276691]
lemon-toothbrush-55306
08/19/2022, 11:18 AMacceptable-hamburger-48790
08/19/2022, 11:22 AMlemon-toothbrush-55306
08/19/2022, 11:28 AMjs
Cypress.Commands.add('getBySel', (selector, ...args) => {
return cy.get(`[data-test-id=${selector}]`, ...args);
});
acceptable-hamburger-48790
08/19/2022, 12:24 PMglamorous-country-57678
08/19/2022, 1:52 PMcy.intercept()
. The full intercept is here:
cy.intercept(`${ethProvider}*`, (req) => {
// conditonal logic to return different responses based on the request url
console.log(req.body)
const { method, params, id } = req.body
if (method === 'eth_chainId') {
req.reply({
body: {
id: 1,
jsonrpc: '2.0',
result: '0x111111',
},
})
} else if (
method === 'eth_call' &&
params[0]?.data === '0x79502c55'
) {
req.reply({
body: {
id,
jsonrpc: '2.0',
result:
'0x' +
Array(10 * 64)
.fill(0)
.map((_, i) => (i % 64 === 63 ? 1 : 0))
.join(''),
},
})
} else if (method === 'eth_call') {
// other uint256 retrievals
req.reply({
body: {
id,
jsonrpc: '2.0',
result: '0x0000000000000000000000000000000000000000000000000000000000000001',
},
})
} else {
req.reply({
body: { test: 'test' },
})
}
}).as('ethProvider')
I did read the docs on Conditional Testing (https://docs.cypress.io/guides/core-concepts/conditional-testing#:~:text=The%20problem%20is,overcome%20these%20problems...) but want to know if this is the reason requests are thrown like this.magnificent-finland-58048
08/19/2022, 2:22 PMmagnificent-finland-58048
08/19/2022, 2:22 PMshy-accountant-52090
08/19/2022, 3:53 PMimportant-nest-99734
08/19/2022, 4:08 PMstale-ambulance-12910
08/19/2022, 8:19 PMgetServerSideProps
? I found a guide, https://glebbahmutov.com/blog/mock-network-from-server/, but it seems to be outdated and not encouraged.little-france-10142
08/19/2022, 8:42 PMmessage
object returned from cy.mailosaurGetMessage
. I can't seem to tell TS that it's going to get an object. It seems hell bent on it being a string | undefined
. Can anyone help me with this?