Reputation: 306
When I run the test, the specified URL does not open, even though it is entered correctly and set in BaseUrl in cypress.config.js:
> module.exports = defineConfig({ e2e: {
> "projectId": "fi4fhz",
> "viewportHeight": 1080,
> "viewportWidth": 1920,
> specPattern: 'cypress/e2e/**/*.{js,jsx,ts,tsx}',
> baseUrl: 'https://pha.mm.int:6001/',
>
> setupNodeEvents(on, config) {
>
> }, },
In every test file I have this:
beforeEach(() => {
cy.runInWeb();
});
and in commands.js I have:
Cypress.Commands.add("runInWeb", () => { cy.visit(Cypress.e2e().projectUrl) });
and in cypress.config.js I have:
"projectUrl": "https://pha.mm.int:6001/"
but it's not functioning. Where is the problem?
Upvotes: 0
Views: 196
Reputation: 155
Yes you visit() but not in the right way, if you store your url in env variable you get it out like this:
Cypress.Commands.add("runInWeb", () => { cy.visit(Cypress.env('projectUrl')) });
and you store the default like this:
// cypress.config.js
const { defineConfig } = require("cypress");
module.exports = defineConfig({
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
specPattern: 'cypress/e2e/**/*.cy.{js,jsx,ts,tsx}'
},
env: {
projectUrl: 'https://pha.mm.int:6001/',
},
})
or cypress.env.json
{
"projectUrl": "https://pha.mm.int:6001/"
}
Upvotes: 4
Reputation: 53
Ensure that you have this beforeEach prior to running your it test blocks. You need to use cy.visit('/')
before each of your tests.
beforeEach(() => {
//cy.session(id, setup); Use is if you want to stay logged into your application
cy.visit('/);
cy.wait(100);
});
If you're interested in using a session, visit the cypress docs here:
Upvotes: 1
Reputation: 184
The baseUrl value https://pha.mm.int:6001/
shows up in the browser address bar because Cypress uses it to configure set up the runner.
But the <iframe>
containing the web page under test isn't changed until you perform
the first cy.visit('/')
.
This is to allow you to execute code before the page load occurs, like cy.intercept()
and cy.fixture()
.
Upvotes: 3
Reputation: 7125
Based on the information in the question, I assume that you did not include a cy.visit()
command. Without that command, Cypress does not know to open a webpage.
Upvotes: 0