有什么办法来优化/加速数据的发送与量角器一个用户界面? [英] Is there any way to optimize / speed up the sending of data to a UI with Protractor?

查看:239
本文介绍了有什么办法来优化/加速数据的发送与量角器一个用户界面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我也与此类似code:

I have code similar to this:

ExamPage.prototype.enterDetailsInputData = function (modifier) {
    page.sendKeys(this.modalExamName, 'Test Exam ' + modifier);
    page.sendKeys(this.modalExamVersionId, 'Test exam version ' + modifier);
    page.sendKeys(this.modalExamProductVersionId, 'Test exam product version ' + modifier);
    page.sendKeys(this.modalExamAudienceId, 'Test exam audience ' + modifier);
    page.sendKeys(this.modalExamPublishedId, '2014-06-1' + modifier);
    page.sendKeys(this.modalExamPriceId, '100' + modifier);
    page.sendKeys(this.modalExamDurationId, '6' + modifier);
};

这里的page.sendKeys功能。请注意,目前,这是不是做的承诺或类似的东西任何回报。如果函数不是codeD以及那我欢迎评论:

Here's the page.sendKeys function. Note that currently this is not doing any return of promises or anything like that. If the function is not coded well then I welcome comments:

// page.sendkeys function
sendKeys(id: string, text: string) {
    element(by.id(id)).sendKeys(text);
} 

我看着它慢慢地填写我的屏幕上的每个字段,然后一次又一次地重复它在后续更多的测试。

I watch as it slowly fills out each field on my screen and then repeats it again and again in more tests that follow.

有没有什么办法,这可以优化还是我不得不等待一个字段后,其他填写,并不得不忍受这需要很长的时间来运行测试?

Is there any way that this could be optimized or do I have to wait for one field after the other to fill and have to live with tests that take a long time to run?

我假设的SendKeys是基于承诺。我可以例如使用 AngularJS $ Q 发行,同时所有的SendKeys,然后使用$ Q等待它们完成?

I assume sendKeys is promise based. Could I for example use AngularJS $q to issue all the sendKeys at the same time and then use $q to wait for them to complete?

推荐答案

潜在的解决方案我觉得至少有一点两轮牛车是必需的,无论你如何优化它 - 量角器不给你这个了的框。然而将一个小的辅助函数类似这样的满足您的需求?做些什么,你需要加快双方文本 输入 s的 NG-模型 S'

Potential Solution I think at least a little hackery is required no matter how you optimize it - protractor doesn't give you this out of the box. However would a small helper function like this suit your needs? What else do you need to speed up sides text inputs with ng-models?

function setNgModelToString(element, value) {
    return element.getAttribute('ng-model').then(function (ngModel) {
        element.evaluate('$eval("' + ngModel + ' = \'' + value + '\'") && $digest()');
    });
}

解决方案示例:

describe('angularjs homepage', function() {
  it('should have a title', function() {
    browser.get('http://juliemr.github.io/protractor-demo/');

    var inputString1 = '';
    var inputString2 = '';
    for (var i = 0; i < 1000; i++) {
        inputString1 += '1';
        inputString2 += '2';
    }

    /* Uncomment this to see it runs much much slower when you enter each key. */
    //element(by.model('second')).sendKeys(inputString1);   

    setNgModelToString(element(by.model('second')), inputString2);

    expect(element(by.model('second')).getAttribute('value')).toEqual(inputString2);
  });
});

为什么该解决方案的工作?

您需要使用 $ EVAL 包分配,而不仅仅是分配为评估不评估副作用(嵌套的评价,但...嘿嘿)。假设这是在角前pressions truthy那么 $消化()是由称为&放大器;&安培; ;这会导致消化的情况发生,你需要,因为你设置从消化周期外的值更新的一切。

You need to use $eval to wrap the assignment and not just assignment as evaluate does not evaluate side effects (a nested evaluation, though... heh). Assuming that's truthy in angular expressions then $digest() is called from the &&; this causes a digest to happen, which you need to update everything since you set a value from outside the digest cycle.

有关解决方案的思路:

背后的一个端到端的测试,整个思路是使用你的应用程序,以模拟的最终用户。这可以说是不这样做,以及一个接一个发送键,或复制和粘贴(因为粘贴到要素是进入输入的有效途径;它只是很难成立,由于闪光灯等。 ,见下文)。

The whole idea behind an E2E test is to "emulate" an end-user using your app. This arguably doesn't do that as well as sending the keys one-by-one, or copy-and-paste (since pasting into elements is a valid way of entering input; it's just hard to set up due to flash, etc., see below).

其他可能的解决方案:


  • 复制和粘贴:的创建一个元素,输入文字,复制,粘贴文本发送按Ctrl + V将目标元素。这可能需要做一堆花哨的脚法,如使用Flash(暴露系统剪贴板是一个安全隐患),并有复制,单击一种无形的Flash播放器。见<一href=\"http://angular.github.io/protractor/#/api?view=webdriver.WebDriver.prototype.executeScript\"><$c$c>executeScript对目标评价功能,使您可以访问变量,例如窗口如果你需要的。

  • Copy and Paste: Create an element, enter text, copy it, paste the text sending Ctrl + V to the target element. This may require doing a bunch of fancy footwork, like using Flash (exposing the system clipboard is a security risk) and having "copy it" click an invisible flash player. See executeScript to evaluate functions on the target so that you have access to variables like window if you need that.

并行化你的测试。的这里阅读官方文档 并搜索碎片,然后多。如果你主要是担心整个测试集,而不是单独的测试,向外​​扩展您的浏览器计数的时间可能是要走的路。然而,有一个很好的机会,你是TDD-ING什么的,所以需要每个测试运行得更快。

Parallelizing your tests. Read the official doc here and search for "shard" and then "multiple". If you're mainly worried about the duration of your entire test collection and not individual tests, scaling out your browser count is probably the way to go. However there's a good chance you are TDD-ing or something, hence needing each test to run faster.

这篇关于有什么办法来优化/加速数据的发送与量角器一个用户界面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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