I have the following test in Jasmine, that I need to execute for 2 different URLs, these 2 url are different versions of the same product:
describe('TEST ',function(){
var basePage = new BasePage();
var page1 = new Page1();
describe('TEST',function(){
beforeEach(function(){
browser.get('URL-1.html');
});
it('REUSE THIS TEST' , function (){
browser.wait(EC.visibilityOf(viewerWidgetPage.videoPlayer));
page1.videoControls.click();
expect(basePage.hasClass(page1.videoPlayer, 'vjs-playing')).toBeTruthy();
page1.audioControl.click();
//Verify that the video property is muted.
browser.executeAsyncScript_(function(callback){
callback(window.player.muted());
}).then(function(isMuted){
expect(isMuted).toBeFalsy();
});
page1.audioControl.click();
//Verify that the video property is muted.
browser.executeAsyncScript_(function(callback){
callback(window.player.muted());
}).then(function(isMuted){
expect(isMuted).toBeTruthy();
});
});
});
Is there any way to use in another test, the 'it' "REUSE THIS TEST" in any way?
One option would be to loop over the URLs under test:
describe('TEST ',function(){
var basePage = new BasePage();
var page1 = new Page1();
var urls = ['URL-1.html', 'URL-2.html'];
urls.map(function (url) {
describe('TEST ' + url,function(){
beforeEach(function(){
browser.get(url);
});
it('REUSE THIS TEST' , function (){
browser.wait(EC.visibilityOf(viewerWidgetPage.videoPlayer));
page1.videoControls.click();
expect(basePage.hasClass(page1.videoPlayer, 'vjs-playing')).toBeTruthy();
page1.audioControl.click();
//Verify that the video property is muted.
browser.executeAsyncScript_(function(callback){
callback(window.player.muted());
}).then(function(isMuted){
expect(isMuted).toBeFalsy();
});
page1.audioControl.click();
//Verify that the video property is muted.
browser.executeAsyncScript_(function(callback){
callback(window.player.muted());
}).then(function(isMuted){
expect(isMuted).toBeTruthy();
});
});
});
});
});
Another approach, that would probably scale better, would be to use multiCapabilities
and to add the desired spec(s) to each of the capabilities parameterizing the url under test.
The idea is to define the parameter on every capability:
multiCapabilities: [
{
browserName: "chrome",
url: "URL-1.html"
},
{
browserName: "chrome",
url: "URL-2.html"
}
],
Then, in your test use getProcessedConfig()
to access the current capability and the url
:
beforeEach(function () {
browser.getProcessedConfig().then(function (config) {
var url = config.capabilities.url;
browser.get(url);
});
});
Tested - works for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With