acceptable-solstice-90676
06/16/2022, 3:35 PMcy.clearCookie('sessionID')
works in the before
or beforeEach
hooks?
I have this in the e2e
file:
Cypress.Cookies.defaults({
preserve: 'sessionID'
})
However, there are some spec.js file where I do not want to use the sessionID
red-toddler-79937
06/16/2022, 5:20 PMnutritious-honey-65632
06/16/2022, 6:23 PMcy.wrap(response).as('someResponse')
gray-kilobyte-89541
06/16/2022, 6:56 PMred-toddler-79937
06/16/2022, 10:29 PMred-toddler-79937
06/16/2022, 10:29 PMgray-kilobyte-89541
06/16/2022, 10:55 PMcy.then
. See for example https://slides.com/bahmutov/flexible-cypress-datared-toddler-79937
06/16/2022, 11:01 PMred-toddler-79937
06/16/2022, 11:01 PMred-toddler-79937
06/16/2022, 11:12 PMcy.get('@loginResponse').its('response.body.data').then((token) => {
setToggleState(1, token);
})
I did thisred-toddler-79937
06/16/2022, 11:12 PMred-toddler-79937
06/16/2022, 11:15 PMcy.get('@loginResponse').its('response.body.data').as('token');
I also tried this but I cannot access the value outside of the methodnutritious-honey-65632
06/16/2022, 11:20 PMcy.get('@token')
should yield data obj then you need then
again to pass it to some functionred-toddler-79937
06/16/2022, 11:30 PMred-toddler-79937
06/16/2022, 11:30 PMred-toddler-79937
06/16/2022, 11:30 PMred-toddler-79937
06/16/2022, 11:39 PMred-toddler-79937
06/16/2022, 11:40 PMred-toddler-79937
06/16/2022, 11:40 PMnutritious-honey-65632
06/16/2022, 11:46 PMbefore
should run once before all tests in the describe and beforeEach
should run before each testred-toddler-79937
06/16/2022, 11:47 PMnutritious-honey-65632
06/16/2022, 11:49 PMbefore
will run then beforeEeach
then test1
then beforeEach
then test2
then beforeEach
then test3
red-toddler-79937
06/16/2022, 11:51 PMred-toddler-79937
06/16/2022, 11:52 PMcy.get('@token')
disappear from memory or something? Because I tried to access it again and the 2nd time it returned: ``cy.get() could not find a registered alias for: @token.`nutritious-honey-65632
06/16/2022, 11:58 PMintercept
only once and cy.get
how many times you want. If you intercept
twice it will search for second request which never happens in your casered-toddler-79937
06/17/2022, 12:00 AMred-toddler-79937
06/17/2022, 12:00 AMts
function login() {
cy.intercept({
method: 'POST',
url: '/api/auth/login',
}).as('loginResponse');
cy.visitPage('login', 'auth-template');
cy.fillField('email', 'email@email.com');
cy.fillField('password', 'password');
cy.clickButton('submit');
cy.wait('@loginResponse').its('response.statusCode').should('equal', 200);
cy.get('@loginResponse').its('response.body.data').as('token');
}
red-toddler-79937
06/17/2022, 12:00 AMnutritious-honey-65632
06/17/2022, 12:09 AMAll intercepts are automatically cleared before every test.
you should test how it works, not sure what this means if it is called in before for examplered-toddler-79937
06/17/2022, 12:19 AMts
function setToggleState(productId: number, state: boolean) {
cy.get('@token').then((token) => {
cy.request({
method: "PUT",
url:`/api/products/${productId}/update-availability`,
headers: { Authorization: `Bearer ${token}` },
body: { isAvailable: state }
});
});
}
Uhm, the second time i trigger this function i get the error:
> "cy.get() could not find a registered alias for: @token. You have not aliased anything yet."