循环使用参数的量角器测试 [英] Looping on a protractor test with parameters

查看:123
本文介绍了循环使用参数的量角器测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组完全相同的烟幕测试。我想将它们放入一个循环并循环一个参数数组。但是,测试是异步运行的,因此循环在测试运行之前完成。这导致测试在第8个参数上运行8次,而不是每个参数运行一次。

I have a set of smokescreen tests that are all pretty much identical. I would like to put them into a loop and loop at an array of parameters. However, the tests are running asynchronously and so the loop completes before the tests are run. This results in the test being run 8 times on the 8th parameter instead of once for each parameter.

describe('Admin Console Campaigns', function() {
    var ptor;
    var adminUrl;
    var testParams = [
        {title: 'Dashboard', urlSuffix: '/communic8' },
        {title: 'Campaign Report', urlSuffix: '/Reports/Campaign' },
        {title: 'Partner Campaign Usage', urlSuffix: '/Reporting/PartnerCampaignUsage' },
        {title: 'Campaign Template Usage', urlSuffix: '/Reporting/CampaignTemplateUsage' },
        {title: 'Email Usage Report', urlSuffix: '/Reports/EmailUsage' },
        {title: 'Campaign Templates', urlSuffix: '/CampaignTemplates' },
        {title: 'Campaign Template Groups', urlSuffix: '/CampaignTemplateGroups' },
        {title: 'New Template', urlSuffix: '/CampaignTemplates/Add' }
    ];

    beforeEach(function() {
        ptor = protractor.getInstance();
        ptor.ignoreSynchronization = true;
        var testParams = smokescreenTestConfig.adminCampaigns;
        adminUrl = ptor.params.http + ptor.params.client + ptor.params.staging + ptor.params.sharedvue + ptor.params.admin;
    });

    afterEach(function(){

    });

    for(var i=0; i < testParams.length; i++){
        var testParam = testParams[i];

        it('should have a ' + testParam.title + ' tab', function() {
            testUrl = adminUrl + testParam.urlSuffix;
            basicTestFunctions.pageExists(testUrl, ptor, browser, testParam.title);
        }, 60000);
    };
});

有没有人知道如何强制循环等待测试?

Does anyone have an idea of how to force the loop to wait on the tests?

推荐答案

好的,不久前想出了这个,对不起,我忘了我已经发布在这里了。我们基本上在另一个文件中创建了一个配置数组,(虽然这不是必需的,只是让代码更容易阅读)然后将该数组拉到我们想要重复的测试之上的var中。然后我们在一个循环内部的函数中包围测试,并在每个循环中传入我们的数组中的行。

Ok figured this one out a while ago, sorry I forgot I had posted here. We basically created a configuration array in another file, (though this is not necessary, just makes the code easier to read) and then pulled that array into a var right above the test we wanted to repeat. Then we surrounded the test in a function inside of a loop and passed the lines from our array in with each loop.

var testParams = testConfig.testArray;

for (var i = 0; i < testParams.length; i++) {

  (function (testSpec) {
    it('write your test here', function () {
      //test code here
    });
  })(testParams[i]);

};

这里的关键是函数末尾的testParams [i]传递迭代循环。这迫使同步执行。

The key here is that "testParams[i]" at the end of the function passing in the iteration of the loop. This forces synchronous execution.

如果你想变得非常疯狂,我们最终还是编写了一个批处理文件,连续50次在我们所有的客户端运行这个烟幕。我们在大约10分钟内对整个平台进行了烟幕扫描。

If you want to get really crazy we also ended up writing a batch file that runs this smokescreen about 50 times consecutively across all of our clients. We smokescreen our entire platform in about 10 minutes.

这篇关于循环使用参数的量角器测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆