'How to pass custom url in cypress
My application requires passing custom url to cy.visit for every page. For eg:
"env": {
"testenv" : "sbx",
"sbx":{
"my":"https://abcabcabx#/",
"foo": "https://defdefx#/"
}
In base class, its read as :
cy.visit(Cypress.env()[Cypress.env()['testenv']][brand]);
Our application is in lower env and there is no connectivity between pages so we test each page by hitting url for that page. Example : https://abcabcabx#/about-your-detail
for about your finance, url will be : https://abcabcabx#/about-your-finance
that is how i am calling url in test class :
For about your detail page - url will be :
let brands = ['my', 'foo']
aboutYourDetailPage.openUrl(brand)
How can i customise this url for each class.
Thanks in advance !!
Solution 1:[1]
you can define the base url for your tests in the 'cypress.json' configuration file { "baseUrl": "http://localhost:3000/#/" } and after in each your class use only path to specific page 'cy.visit('my')' here the example: https://docs.cypress.io/api/commands/visit#Prefixes OR get the base url from env.variables from your CLI command for tests 'const fullUrl = config.env.urlConfig' in the /plugins/index.ts and using base url for opening specific page in the files 'cy.visit(Cypress.env('my'));'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Denys Pavliuk |
