stale-optician-85950
08/24/2022, 1:29 PMfollowRedirect: false,
in your POST and ensuring you get a 302, and in a .then()
response make your next request, most likely a GET. Similar to these docs https://docs.cypress.io/api/commands/request#Request-a-page-while-disabling-auto-redirecthallowed-lighter-4305
08/24/2022, 2:02 PMicy-television-77938
08/24/2022, 2:09 PMicy-television-77938
08/24/2022, 2:09 PMstale-optician-85950
08/24/2022, 2:21 PM/fixtures/env-data.json
with json structure using an object for each environment, such as:
{
"environments": [
{
"dev": [
{
"username": "mrdev",
"password": "sjkdhdskfhaks$"
}
]
},
{
"qa": [
{
"username": "mrsqa",
"password": "ahsgdshgsa$"
}
]
},
{
"prod": [
{
"username": "misterprod",
"password": "asdiuayeg"
}
]
}
]
}
Depending on how you want to use the json data, there are different ways to require and import the json. But you can start with these docs https://docs.cypress.io/api/commands/fixture i.e. cy.fixture('env-data').as('data');
melodic-egg-83620
08/24/2022, 2:30 PMimport.meta.env
into process.env
when using Vite instead of webpack for your project bundler? I can't run any E2E tests because Cypress fails to read any import.meta.env
ENV variables and believes it's a syntax error.hallowed-lighter-4305
08/24/2022, 2:41 PMgentle-yacht-17399
08/24/2022, 3:22 PMfierce-intern-71272
08/24/2022, 4:19 PMfancy-match-96032
08/24/2022, 4:45 PMCypress.env
-- especially if you want to have production credentials
https://docs.cypress.io/api/cypress-api/env#Name
https://docs.cypress.io/guides/guides/environment-variableshallowed-lighter-4305
08/24/2022, 5:04 PMchilly-quill-34099
08/24/2022, 5:39 PMcy.loginWithApiCall()
-function is creating several items in the local storage, which than is being used by the website to authenticate the user.
The problem which I am facing is with sessions:
Currently I have to login for every test, which might lead to a lock down of the account (because of to many calls in a certain period). I would prefer to stay logged in, if that is possible, but have separate tests (it('test1'), ...
). Is that possible, or is it prevented by design to have isolated tests?
ts
/// <reference types="cypress" />
describe('Dashboard', () => {
it('login via RPOC works correctly', () => {
cy.session('mySession', () => {
cy.loginWithApiCall(); //👈call for each test
cy.visit('/').url().should('include', '/portal');
});
});
it('"Welcome" is visible', () => {
cy.session('mySession', () => {
cy.loginWithApiCall(); //👈call for each test
cy.visit('/portal').contains('Welcome');
});
});
});
The strange part is, that the cy.beforeEach()
function does not work as well (Is it because it is outside the session?).
I would think, that I could reuse a session with the same ID, but I guess this is isolated for each it()
function?melodic-ocean-83158
08/24/2022, 5:57 PMmelodic-ocean-83158
08/24/2022, 5:58 PM{
"user": {},
"environment": "prod",
"userProd": {
"username": "username",
"password": "XXXXXXX"
},
"userDev": {
"username": "username",
"password": "DEVpass"
},
"userQA": {
"username": "username",
"password": "QApass$"
}
}
hallowed-lighter-4305
08/24/2022, 6:09 PMfancy-match-96032
08/24/2022, 6:23 PMit()
-- the purpose of cy.session
is to avoid having to log in for every test. local storage should just get restored as long as you use the same id (in your case mySession
). can you paste your loginWithApiCall
code?chilly-quill-34099
08/24/2022, 6:42 PMUiTestAutomation.Cypress/cypress/support/auth.js
there you can find the login()
-function which is basically my function loginWithApiCall()
with all its dependencies.chilly-quill-34099
08/24/2022, 6:46 PMcy.loginWithApiCall()
-call (in Welcome is visible)should be unnecessary, but if I delete the statement, the visit is not working, because of missing authentication. The local storage is cleared as well.melodic-ocean-83158
08/24/2022, 7:12 PMmelodic-ocean-83158
08/24/2022, 7:17 PMhallowed-lighter-4305
08/24/2022, 8:04 PMpurple-shampoo-89307
08/24/2022, 11:54 PMimportant-fireman-17295
08/25/2022, 1:33 AMcy.visit('accounts.google.com')
cy.get('input[id="identifierId"]').type('my_email@gmail.com')
cy.get('div[id="identifierNext"]').click()
The error:cold-van-45410
08/25/2022, 2:09 AMgray-kilobyte-89541
08/25/2022, 2:54 AMcold-van-45410
08/25/2022, 4:01 AMstale-optician-85950
08/25/2022, 7:36 AMwonderful-wire-43244
08/25/2022, 8:52 AMwonderful-wire-43244
08/25/2022, 8:53 AMacceptable-hamburger-48790
08/25/2022, 9:28 AM