how to repeat same test suite for multiple time with different url - webdriver-io

I have a webapp which supports multiple language
based on the query params it loads in different lang
for ex : http://eeee.com/home?lang=US will load in english and http://eeee.com/home?lang=french
I have automation code written for english
I need to run the same code for all other language as well
something like
"test-english": "./node_modules/.bin/wdio wdio.conf.js --lang=US"
should run for english
"test-french": "./node_modules/.bin/wdio wdio.conf.js --lang=fr"
should run for french
or atleast first it should run all test for english and then for french
my wdio.conf.js
looks like
exports.config = {
specs: [
'./test/**/*.test.js'
],
baseUrl: 'http://eeee.com/',
}

Inorder to have custom option in wdio we can use something like this in wdio.conf.js
onPrepare: function(config, capabilities) {
if (process.argv !== undefined && process.argv.length) {
process.argv.forEach(arg => {
if (arg.indexOf('--lang=') !== -1) {
process.env.lang = arg.replace('--lang=', '');
}
});
}
},
before: function(capabilities, specs) {
global.lang = process.env.lang;
}

Related

CypressIO tests to be executed in multiple URL

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 :)
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
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

How to integrate cy.visit(local vs stage url) in a CI environment?

I have a test suite that opens a local url before making a bunch of assertions on some DOM elements.
Now I'd like to integrate Cypress in my CI/CD but I'm unsure on how to tell Cypress to visit the staging url instead of the local one.
Any idea?
it('The body of the page is in viewport', function() {
cy.visit(
'http://mylocalurltovisit.local.com.au:8666/foo'
);
let initialPosition;
const body = cy.get('body');
body.should('have.class', 'pdfView');
cy.get('.body-wrapper').should($el => {
initialPosition = $el.position();
expect(initialPosition.top).equal(0);
expect(initialPosition.left).equal(0);
});
});
I'd like for the visit url to automatically switch to say the staging one (which could be http://staging.com.au/foo) on the CI environment.
One way is to try creating the two different url's for local and staging sites as below in the cypress.json file.
{
"env": {
"project1_user": "admin",
"project1_password": "password",
"localSite" : {
"url" : "http://mylocalurltovisit.local.com.au:8666/foo"
},
"stagingSite" : {
"url" : "http://staging.com.au/foo"
}
}
}
Then receive the urls to const inside the test;
const localUrl = Cypress.env('localSite').url;
const stagingUrl = Cypress.env('stagingSite').url;
You can call in beforeEach or use directly inside the test. Same way you can use for staging site a well.
beforeEach( function() {
cy.visit(localUrl + '/somelogin.php' );
} );
Use an environment variable, but instead of putting it in the config file, pass it in the CI command that starts Cypress, e.g
cypress run --env TARGET=local
cypress run --env TARGET=staging
In the test, you can assign the correct url (once only), using a before().
describe('...', () => {
let url;
before(function() {
url = {
local: 'http://...',
staging: 'http://...'
}[Cypress.env('TARGET')];
})

TestCafe 'dynamic' tests cases

I created a few e2e sanity tests for my current project using TestCafe. These tests are standard TestCafe tests:
fixture(`Basic checkout flow`)
test('Main Flow', async (t) => {
});
I would like to execute this test for multiple site locales and for multiple channels. i.e. I need this test to run for nl_nl, nl_be, en_gb, .. and also for channels like b2c, b2b, ...
The easiest way is to create a loop in the test itself to loop over the locales and channels, but I want to run these test concurrently.
I tried to create a function to dynamically generate these tests, but TestCafe can't seem to detect the tests then.
dynamicTest('Main Flow', async (t) => {
});
function dynamicTest(testName, testFn) => {
const channels = ['b2c']
channels.forEach((channel) => {
test(`[Channel] ${channel}] ${testName}`, testFn);
});
};
Is there a better way of doing this? The only solution I see is running the test script multiple times from Jenkins to have concurrency.
more detailed code:
import HomePage from '../../page/HomePage/HomePage';
import EnvUtil from '../../util/EnvUtil';
const wrapper = (config, testFn) => {
config.locales.forEach(async locale =>
config.channels.forEach(async channel => {
const tstConfig = {
locale,
channel
};
tstConfig.env = EnvUtil.parse(tstConfig, config.args.env);
testConfig.foo = await EnvUtil.get() // If I remove this line it works!
testFn(config, locale, channel)
})
);
};
fixture(`[Feature] Feature 1`)
.beforeEach(async t => {
t.ctx.pages = {
home: new HomePage(),
... more pages here
};
});
wrapper(global.config, (testConfig, locale, channel) => {
test
.before(async (t) => {
t.ctx.config = testConfig;
})
.page(`foo.bar.com`)
(`[Feature] [Locale: ${locale.key}] [Channel: ${channel.key}] Feature 1`, async (t) => {
await t.ctx.pages.home.header.search(t, '3301');
.. more test code here
});
});
If I run it like this I get a "test is undefined" error. Is there something wrong in the way I'm wrapping "test"?
Using TestCafe of version 0.23.1, you can run tests imported from external libraries or generated dynamically even if the test file you provide does not contain any tests.
You can learn more here: Run Dynamically Loaded Tests

How to test a server side debugOnly package

I don't understand how it is possible to test a package that is debugOnly.
My package.js is quite simple :
Package.describe({
name: 'lambda',
version: '0.0.1',
debugOnly: true // Will not be packaged into the production build
});
Package.onUse(function(api) {
api.versionsFrom('1.2.1');
api.addFiles('lambda.js');
api.export("Lambda", 'server');
});
Package.onTest(function(api) {
api.use('tinytest');
api.use('lambda');
api.addFiles('lambda-tests.js', 'server');
});
My lambda-test.js :
Tinytest.add('example', function (test) {
test.equal(Lambda.func(), true);
});
My lambda.js :
Lambda = {
func: function() {
return "Christmas";
}
}
When I run meteor test-packages, it just fails : Lambda is not defined. If I remove the debugOnly: true the test pass. So how can I test my package using tinytest ?
Or this is a bug !
I had the same issue! It turns out the tests are working fine. The Lambda is not getting exported in the project either.
from https://github.com/meteor/meteor/blob/0f0c5d3bb3a5492254cd0843339a6716ef65fce1/tools/isobuild/compiler.js
// don't import symbols from debugOnly and prodOnly packages, because
// if the package is not linked it will cause a runtime error.
// the code must access them with `Package["my-package"].MySymbol`.
Try:
Tinytest.add('example', function (test) {
//also changed expected value from true to Christmas to make test pass
test.equal(Package['lambda']['Lambda'].func(), "Christmas");
//you can use Package['lambda'].Lambda as well, but my IDE complains
});
Now you can do something like this:
if (Package['lambda']) {
console.log("we are in debug mode and we have lamda");
console.log("does this say Christmas? " + Package['lambda']["Lambda"]['func']());
} else {
console.log("we are in production mode, or we have not installed lambda");
}

How to set the loader locale?

When I run my application in the browser, I can specify locale: 'en' as part of dojoConfig. When I run the tests in Node.js, the locale setting is the default value en. When I run the tests in a browser, the locale setting is set with the top preferred language of the browser (which is French in my case)...
I tried without success to set locale: 'en' as part of the loader configuration in my Intern config file:
return {
useLoader: { 'host-browser': 'node_modules/dojo/dojo.js' },
loader: {
locale: 'en',
packages: [{
name: 'dojo',
location: 'src/libs/dojo'
}, {
...
}
};
How can I set the locale setting for my tests running into the browsers? As I've two Intern config files, I don't mind doing something different for Node.js and for the browsers.
A+, Dom
I just hit the same issue (because dojo/_base/config.js was blowing up due to navigator.language being empty and navigator.userLanguage being undefined in my Firefox installation), and needed to get a locale set.
I ended up resorting to adding this to my testconfig.js:
if (typeof window !== 'undefined') {
// We're running inside a browser.
window.dojoConfig = window.dojoConfig || {};
window.dojoConfig.locale = window.dojoConfig.locale || "en-us";
}
Not sure whether that's 'the correct' way to do it, but it seems to be working for me with Intern 2.1.1.