Bru*_*oko 5 javascript testing automation jasmine protractor
我在 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();
});
});
});
Run Code Online (Sandbox Code Playgroud)
有没有办法在另一个测试中使用“它”“重用此测试”?
一种选择是循环测试下的 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();
});
});
});
});
});
Run Code Online (Sandbox Code Playgroud)
另一种可能会更好地扩展的方法是使用multiCapabilities所需的规范并将其添加到参数化测试中的 URL 的每个功能中。
这个想法是定义每个功能的参数:
multiCapabilities: [
{
browserName: "chrome",
url: "URL-1.html"
},
{
browserName: "chrome",
url: "URL-2.html"
}
],
Run Code Online (Sandbox Code Playgroud)
然后,在您的测试中使用getProcessedConfig()访问当前功能和url:
beforeEach(function () {
browser.getProcessedConfig().then(function (config) {
var url = config.capabilities.url;
browser.get(url);
});
});
Run Code Online (Sandbox Code Playgroud)
经过测试 - 对我有用。
| 归档时间: |
|
| 查看次数: |
455 次 |
| 最近记录: |