在每个步骤之前\在量角器中使用事件发射器来处理动画 [英] Before each step \ Event emitter in Protractor to handle animation

查看:91
本文介绍了在每个步骤之前\在量角器中使用事件发射器来处理动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在量角器测试中处理动画.选项之一是禁用动画.但是我不想这么做.第二种方法是在每个步骤之前执行此操作:

I am trying to handle animation in my protractor tests. One of the options is to disable animation. But I don't want to do it. The second option is to do this way before each step:

var EC = protractor.ExpectedConditions;
browser.wait(EC.stalenessOf(element(by.css('[class*="ng-animate"]'))), 5000);

之所以能够成功,是因为Angular将"ng-animate"添加到了动画元素类别中.

It works because Angular adds "ng-animate" to the class of element which is in animation.

所以有两个问题:

  1. 如何在量角器的每个步骤之前添加?
  2. 如何在量角器中添加eventEmitter,以在诸如单击"之类的预定义方法上发出某些东西?

赞赏这两个问题的答案,即使它并非专门用于动画处理.

Appreciate any answers on this two questions even if it don't dedicate to animation handling.

推荐答案

这是我的解决方案.它需要有关插件在量角器中如何工作的知识. 有一个"waitForPromise"钩子,它的工作原理不清楚,但是

Here is my solution. It requires knowledge of how plugins work in protractor. There is "waitForPromise" hook which works unclear, but this example helped me to perform the solution.

waitForPromise: function(){
    return browser.executeAsyncScript(function(){
        var callback = arguments[arguments.length - 1];

        var counter = 0;
        var checker = setInterval(function(){
            if (counter>100){
                clearInterval(checker);
                callback();
            }

            if ($('[class*="ng-animate"]').length>0) {
                // console.log('catched');
            } else {
                // console.log('notPresent or Disappeared');
                clearInterval(checker);
                callback();
            }
            counter++;
        },50);

    }).then(function() {
        console.log('done');
    });
}

在执行测试期间的每个promise上,它仅检查是否存在任何具有"ng-animate"类的元素,如果存在,则等待该元素消失或计数> 100(5秒).这可能不是最佳解决方案,因为它可以是测试步骤中的任何动画.在这种情况下,您将在整体测试执行方面遇到巨大的延迟.

On each promise during the execution of tests, it just checks if there is any element with class "ng-animate" and if it does, it waits for this element to disappear or counter>100 (5 seconds). Probably this is not the best solution because it could be any animation during steps of the test. In this case, you will get a huge delay of overall tests execution.

这篇关于在每个步骤之前\在量角器中使用事件发射器来处理动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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