Reputation: 41
I'm working on a project that has multiple systems. (ex: admin portal, client portal, etc.) and there are different environments in each system (ex: dev env, QA env, etc.) There is a separate QA repository for e2e testing and I need to test different systems with different URLs in a single test suite.
This question Cypress baseUrl configuation suggests a method of using multiple params in cypress.json
to represent the different systems URLs and to use a Cypress.config()
to refer to the correct URL. However, that method does not make use of the baseURL
property of Cypress.
Is there any in-built capability in Cypress to support the testing of multiple systems in a single test suite? (for example, switch the baseURL
from within test code or something of that sort)
Upvotes: 4
Views: 1566
Reputation:
I guess you want to use Cypress.config('baseUrl', <value>)
to set the baseUrl in a beforeEach()
.
You will need to choose how to indicate the system you are testing, perhaps different scripts to start with an environment variable
cypress open --env system=admin,environ=qa
then in the test
const baseUrls = {
'admin-qa': 'http:/example.com'
...
}
beforeEach(()=> {
const baseUrl = baseUrls[`${Cypress.env('system')-${Cypress.env('qa')}`];
Cypress.config(baseUrl)
})
I need to test different systems with different URLs in a single test suite
This suggests you want to run the test against all urls in the one run.
If so you can iterate an array of urls
const urls = [
'http://admin-dev.com',
'http://admin-qa.com',
'http://client-dev.com',
'http://client-qa.com'
]
urls.forEach(url => {
describe(`Testing ${url}`, () => {
before(() => Cypress.config('baseUrl', url))
it('tests that thing', ...
If any tests are specific to one environment, i.e must always have client-dev configuration, you can apply the baseUrl at test level
it('tests the other thing', { baseUrl: 'http://client-dev.com' }, () => {
...
})
Upvotes: 3