[英]How to reuse Jasmine tests
我在Jasmine中進行了以下測試,我需要為2個不同的URL執行,這2個url是同一產品的不同版本:
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();
});
});
});
有沒有辦法在另一個測試中使用,'它'“以任何方式重復使用此測試”?
一種選擇是循環測試中的URL :
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();
});
});
});
});
});
另一種可能更好地擴展的方法是使用multiCapabilities
並將所需的規范添加到參數化測試的url的每個功能中。
我們的想法是在每個功能上定義參數:
multiCapabilities: [
{
browserName: "chrome",
url: "URL-1.html"
},
{
browserName: "chrome",
url: "URL-2.html"
}
],
然后,在您的測試中使用getProcessedConfig()
來訪問當前功能和url
:
beforeEach(function () {
browser.getProcessedConfig().then(function (config) {
var url = config.capabilities.url;
browser.get(url);
});
});
經過測試 - 適合我。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.