Reputation: 47
An Ecommerce website have different URL's for different countries. And each of these website have to be tested. We have set of automation scripts written in CYPRESSIO. Looking for ideas how these scripts can be rerun for different URL's.
Example URL's for different countries
UK: https://www.abc.co.uk
CH: https://www.abc.ch
DE: https://www.abc.de
There are some functionalities which are country specific and hence we have to run tests for all the URL's . Any ideas and leads would be appreciated.
Thanks in advance :)
Upvotes: 2
Views: 1164
Reputation:
Set the tests inside a data loop
const urls = ['https://www.abc.co.uk', 'https://www.abc.ch', 'https://www.abc.de'];
urls.forEach(url => {
describe(`Testing url: ${url}`, () => {
before(Cypress.config('baseUrl', url))
it('...', () => {
})
})
Testing a simplified scenario,
support/index.js
beforeEach(() => {
console.log('beforeEach in support', Cypress.config('baseUrl'))
})
dynamic-baseUrl.spec.js
const urls = ['https://www.abc.co.uk', 'https://www.abc.ch', 'https://www.abc.de'];
urls.forEach(url => {
describe(`Testing url: ${url}`, () => {
before(() => Cypress.config('baseUrl', url))
it('sees the required baseURL', () => {
console.log('it', Cypress.config('baseUrl'))
})
})
})
console output
beforeEach in support https://www.abc.co.uk
it https://www.abc.co.uk
beforeEach in support https://www.abc.ch
it https://www.abc.ch
beforeEach in support https://www.abc.de
it https://www.abc.de
Cypress log
Testing url: https://www.abc.co.uk
...passed
Testing url: https://www.abc.ch
...passed
Testing url: https://www.abc.de
...passed
Upvotes: 2
Reputation: 18650
One way would be to create country-specific cypress.json
files.
For eg. cypress-de.json
Inside it you can define baseURL
and country-specific test cases using testFiles[]
as:
{
"testFiles": [
"TC_01.spec.js",
"TC_02.spec.js",
"TC_03.spec.js",
"TC_04.spec.js"
],
"baseUrl": "https://www.abc.de"
}
Now when you want to run tests, all you have to do is pass the relevant cypress.json file through CLI using the command:
npx cypress run --config-file cypress-de.json
Upvotes: 0