Why must I use browser.sleep while writing protractor tests

隐身守侯 提交于 2020-01-02 00:17:08

问题


My first run at E2E tests. I'm trying to digest someone else's protractor tests.

Problem: There are a lot of browser.driver.sleep and this seems fragile.

Goal: not to use browser.driver.sleep

Question: What is a better approach to browser.driver.sleep? Something less fragile like a promise or something I dont know about lol?

var config = require('../../protractor.conf.js').config;
describe('this Homepage Body Tests', function(){
browser.driver.get(config.homepageUrl);

it("should open find a clinic page", function(){
  // page loads :: want to fix this random wait interval 
  browser.driver.sleep(2000);
  browser.ignoreSynchronization = true;

  var string = 'clinic';
  var main = '.search-large-text';
  var link = element(by.cssContainingText('.submenu li a', string));

  link.click().then(function() {
    // page reloads :: want to fix this random wait interval
    browser.driver.sleep(3000);
    var title = element(by.cssContainingText(main, string));
    expect(title.getText()).toBe(string);
  });
});
});

回答1:


Since there is an ignoreSynchronization turned on, you cannot use waitForAngular(), which would be a solution in case of an angular-site testing.

A better solution here would be to set a page load timeout:

browser.manage().timeouts().pageLoadTimeout(10000);  // 10 seconds

See also these relevant threads on explicit waits and timeouts:

  • Use protractor to test login on non-AngularJS page (Leo's answer is very detailed)
  • Protractor : How to wait for page complete after click a button?
  • Timeouts


来源:https://stackoverflow.com/questions/27240744/why-must-i-use-browser-sleep-while-writing-protractor-tests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!