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

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

问题描述

我有一组几乎完全相同的烟幕测试.我想将它们放入一个循环中并在参数数组中循环.但是,测试是异步运行的,因此循环在测试运行之前完成.这导致测试在第 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天全站免登陆