运行 针对许多网站的茉莉花测试

Run jasmine test against many websites

我正在测试网络过滤器,并想 运行 进行一个简单的测试来验证页面是否被阻止。我还要运行这个测试上百页。以下代码适用于单个页面:

for (var n = 0; n < 3; n++) {
     describe("Blocked Sites", () => {

        it('should block ', () => {
            sites.pageGo();
            expect(sites.blockedIDOnLoad.isVisible()).toBeTruthy;
        });

    });

}

sites.pageGo() 在每次循环重复时提供下一个站点。只要 pageGo() 提供的每个页面都被阻止,这就很好用。例如,如果它循环 3 次,我将获得 3 次通过测试。我可以看到浏览器加载每个不同的页面并被阻止。但是,如果任何页面未被阻止,则所有测试都会失败。我想 运行 针对许多站点进行此测试(有些被阻止,有些没有)。我是自动化测试的初学者,非常感谢您提供的任何 guidance/knowledge。有没有办法用我当前的框架实现这个测试,或者有更好的方法吗?

我能够通过使用 for...of 循环让它工作。这对我有用。希望这有帮助。

首先我设置了一个站点 class。

export default class Site {
    url: string;
    id: string;

    constructor(url: string, id: string) {
        this.url = url;
        this.id = id;
     }

    get blockedIDOnLoad() { return browser.element(this.id); }    
}

然后测试看起来像这样...

import site from './site';

describe("Blocked Sites", () => {
    //obviously you wouldn't do it this way for a bunch of sites
    //should help get the idea across though
    const sites = [ new site("http://www.google.com", "#lst-ib"),
        new site("http://facebook.com", "#blockedId"),
        new site("http://twitter.com", "#blockedId") ];    

    for (const s of sites) {
        it('should block', () => {
            browser.url(s.url);
            expect(s.blockedIDOnLoad.isVisible()).toBe(true);
        });            
    }
});

google 测试通过,因为这是该页面上的有效 ID。

我想你也可以像下面这样使用this

describe("test power", () => {

       function test(x){
       var result = x * x * x;
       it(`${x} in the power 3 is ${result}`, function() {
       assert.equal(pow(x, 3), result);
    });
       for (var x = 1; x <= 5; x++) {
    test(x);
  }  
}

});