什么是browser.ignoreSynchronization在量角器? [英] What is browser.ignoreSynchronization in protractor?

查看:749
本文介绍了什么是browser.ignoreSynchronization在量角器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到了这么多的时间,人们建议使用:

I have seen it so many time where people suggest to use:

browser.ignoreSynchronization=true;  // or false

但我不明白为什么我们需要它?

But I do not understand why do we need it?

推荐答案

简单的答案是,它使得量角器等不到角承诺,如从 $ HTTP $超时来解决,而你可能想,如果你正在测试的行为做的过程中 $ HTTP $超时(例如,装载的消息),或测试无棱角网站或网页,如单独的登录页面。

The simple answer is that it makes protractor not wait for Angular promises, such as those from $http or $timeout to resolve, which you might want to do if you're testing behaviour during $http or $timeout (e.g., a "loading" message), or testing non-Angular sites or pages, such as a separate login page.

例如,要测试一个按钮,一个请求过程中设置了一个加载消息可以将其设置为真正获取元素时+检查其内容

For example, to test a button that sets a loading message during a request you can set it to true when fetching an element + checking its contents

element(by.css('button[type="submit"]')).click();
browser.ignoreSynchronization = true;
expect(element(by.css('.message')).getText().toBe('Loading...');    
browser.ignoreSynchronization = false;
expect(element(by.css('.message')).getText().toBe('Loaded'); 

一个更复杂的答案是,它设置为真正意味着后续添加/注射到控制流不还加 browser.waitForAngular 。有情况下,当控制流的理解,并且当/事物是如何加入/注入是非常重要的。例如,如果你使用 browser.wait 来测试一个多阶段的过程中,传递到功能等待是之后的在测试的功能的其余部分已经添加到控制流程。注入到控制流程的

A more involved answer is that is that setting it to true means that subsequent additions/injections to the the control flow don't also add browser.waitForAngular. There are cases when an understanding of the control flow, and when/how things are added/injected into it is important. For example if you're using browser.wait to test a multi-stage process, the function passed to wait is injected into to the control flow after the rest of the functions in the test have added to the control flow.

element(by.css('button[type="submit"]')).click();
browser.ignoreSynchronization = true;
expect(element(by.css('.message')).getText().toBe('Stage 1');
browser.wait(function () {
   // This function is added to the control flow after the final
   // browser.ignoreSynchronization = false in the test
   // so we need to set it again here 
   browser.ignoreSynchronization = true;
   return element(by.cssContainingText('.message', 'Stage 2')).isPresent().then(function(isPresent) { 
     // Cleanup so later tests have the default value of false
     browser.ignoreSynchronization = false;
     return !isPresent;
   });
});
expect(element(by.css('.message')).getText().toBe('Stage 2');
browser.ignoreSynchronization = false;
expect(element(by.css('.message')).getText().toBe('Stage 3');

要使用替代 browser.ignoreSynchronization 是直接访问标准的webdriver API

An alternative to using browser.ignoreSynchronization is to access the standard webdriver API directly

element(by.css('button[type="submit"]')).click();
expect(browser.driver.findElement(by.css('.message')).getText().toBe('Loading...');    
expect(element(by.css('.message')).getText().toBe('Loaded'); 

直接使用驱动程序的方法找到的元素意味着该系统将尝试找到他们,而无需等待任何正在进行 $ HTTP 的要求来完成,就像设置 browser.ignoreSynchronization = TRUE

Using the driver methods directly to find the elements means that the system will try to find them without waiting for any ongoing $http requests to finish, much like setting browser.ignoreSynchronization = true.

这篇关于什么是browser.ignoreSynchronization在量角器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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