【问题标题】:Run jasmine test against many websites对许多网站运行 jasmine 测试
【发布时间】:2017-10-10 21:35:31
【问题描述】:

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

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 个通过测试。我可以看到浏览器加载每个不同的页面并被阻止。但是,如果没有阻止任何页面,则所有测试都会失败。我想对许多站点进行此测试(有些被阻止,有些没有)。我是自动化测试的初学者,非常感谢您提供的任何指导/知识。有没有办法用我当前的框架来实现这个测试,还是有更好的方法?

【问题讨论】:

    标签: javascript jasmine webdriver-io


    【解决方案1】:

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

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

    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。

    【讨论】:

      【解决方案2】:

      我认为您也可以使用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);
        }  
      }
      
      });
      

      【讨论】:

        猜你喜欢
        • 2012-02-05
        • 2016-06-13
        • 1970-01-01
        • 1970-01-01
        • 2018-11-02
        • 1970-01-01
        • 1970-01-01
        • 2019-02-17
        • 2022-08-16
        相关资源
        最近更新 更多