简体   繁体   English

量角器不等待页面加载

[英]Protractor not waiting for page load

I created a basic test with protractor to click on a element and on the new page check if given element exists, but Protractor does not seem to wait and it runs the assertion just after the click but before the new page loads. 我用量角器创建了一个基本测试,单击一个元素,然后在新页面上检查给定元素是否存在,但是量角器似乎没有等待,它在单击之后但在加载新页面之前运行了断言。 The element I am looking for is available on both pages, so protractor sees the element on the old page, before the new page loads. 我要查找的元素在两个页面上都可用,因此量角器会在加载新页面之前在旧页面上看到该元素。 Can someone please tell me what am I doing wrong? 有人可以告诉我我在做什么错吗?

it('should check when new page is loaded', function () {
button.click().then(function (){
    return expect(newElement).to.exist;
});

First of all ,add "getPageTimeout" variable to your Protractor configuration file. 首先,将“ getPageTimeout”变量添加到您的量角器配置文件中。

If you are not using it already.This is to set global page timeout based on your average page load time in your application. 如果尚未使用它。这是根据应用程序中的平均页面加载时间设置全局页面超时。

conf.js conf.js

getPageTimeout: 120000,//change it based on your app response time

If it does not help even then verify the page title of next page(assuming its different from previous page) before checking the actual element you are looking for. 如果仍然不能解决问题,则在检查实际要查找的元素之前,请验证下一页的页面标题(假定其与上一页不同)。

it('should check when new page is loaded', function () {
button.click().then(function (){
    browser.getCurrentUrl();
    browser.getTitle().then(function (title) {
            expect(title).toEqual('Next Page Title');
        });
   return expect(newElement.isDisplayed()).toBeTruthy();
});

Even if that does not help you may use expected conditions.There are several predefined conditions to explicitly wait for. 即使这不能帮助您使用预期的条件,也要明确等待几个预定义的条件。 In case you want to wait for an element to become present: 如果您要等待某个元素出现,请执行以下操作:

var EC = protractor.ExpectedConditions;

var e = element(by.id('xyz'));
browser.wait(EC.presenceOf(e), 10000);

expect(e.isPresent()).toBeTruthy();

You can use below method in Configuration file 您可以在配置文件中使用以下方法

jasmineNodeOpts: {
    showColors: true,
    includeStackTrace: true,
    defaultTimeoutInterval: 1440000
},

And In Spec file you can customise the wait time according to page and object visibility 在Spec文件中,您可以根据页面和对象的可见性自定义等待时间

browser.sleep(20000);

I hope above method will work fine in all the cases if you customise the wait time Properly. 我希望如果您适当地设置等待时间,上述方法在所有情况下都能正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM