如何在量角器中等待自动测试脚本,直到页面完全加载 [英] How to make automated test scripts in protractor wait, until the page is loaded fully

查看:48
本文介绍了如何在量角器中等待自动测试脚本,直到页面完全加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不,但是真的!我知道这个通用问题已经被问过数千遍了,但是还有一些更具体的问题对我来说似乎可行,因此我想知道如何实现它

No, but really! I know this generic question has been asked thousands of times, but there is something more specific that looks feasible to me and thus I want to know how to achieve it

我正在使用量角器测试角度应用.在应用程序内部,我想验证单击链接时我是否被重定向到了正确的页面(非角度).问题在于,在到达要验证的页面之前,URL会更改3次左右(发生多个重定向),因此我无法让等待功能等待页面完全加载

I'm testing an angular app with protractor. Inside the app I want to verify that when I click a link I'm being redirected to the right page (non-angular). The problem is that until I reach the page I'm verifying, the url changes 3 times or so (there are multiple redirections happening), so I can't make a waiting function wait until the page is loaded completely

  1. 我反对browser.sleep()的时间超过1000毫秒!
  2. browser.waitForAngular(),因为这不是一个有角度的页面
  3. ExpectedConditions.urlIs()网址是我要声明的变量
  4. ExpectedConditions.presenseOf()页面可能会更改,因此我不能依赖其中的元素
  5. browser.executeScript("return window.document.readyState")立即返回compete,尽管页面仍在加载中(我确定这是我所需要的,但是那也不起作用)
  6. 我甚至尝试添加一个等待整个页面的innerHtml至少3秒钟不变的函数,但是它失败了,因为有时重定向之间会出现3秒钟以上的暂停. 3秒以上的一切都不是合理的超时时间
  1. I'm against browser.sleep() for more than 1000 ms!
  2. browser.waitForAngular() as this is not an angular page
  3. ExpectedConditions.urlIs() the url is the variable I'm asserting
  4. ExpectedConditions.presenseOf() the page maybe changing so I can't rely on elements inside
  5. browser.executeScript("return window.document.readyState") returns compete immediately, though the page is still loading (I was certain this is what I need, but that didn't work either)
  6. I tried even adding a functions that waits for innerHtml of the whole page not change for at least 3 sec, but it fails because at times there is a pause of more than 3 sec between redirects are happening. Everything above 3 sec isn't a reasonable timeout

问题

我注意到的是,当浏览器正在加载页面时,Reload this page按钮将其状态更改为Stop loading this page(X图标),直到我被重定向到最终页面(下面的屏幕截图).因此,问题是是否有一种方法可以使量角器指向chrome用于选择显示哪个图标的相同条件?

The question

What I noticed is when the browser is loading the page, Reload this page button changes its state to Stop loading this page (X icon) until I'm redirected to the final page (screenshots below). So the question is is there a way to make protractor point to the same condition that chrome uses to choose which icon is displayed?

vs

如果不完全相同,但是如何使量角器挂起,直到页面完全加载

And if not exactly the same, but how do I make protractor hang until the page is fully loaded

很明显,有很多肮脏的解决方案,我可以像显式等待一样来做.但是我会不时地回到这个问题,所以我对这些肮脏的解决方案不感兴趣,这些解决方案在70%的时间里都可以用于特定原因

Obviously there are a lot of dirty solutions that I can do like explicit waits. But I'm coming back to this question every once in a while, so I'm not interested in these dirty solutions that work 70% of the time for a specific cause

P.S.我发现按钮更改了document.load() 事件上的图标.但是我无法弄清楚应该在控制台中写些什么,以便在刷新页面时该脚本记录一条消息

P.S. I figured that the button changes the icon on document.load() event. But I can't figure out what should I write in the console in order for that script to log a message when I refresh they page

推荐答案

您尝试过

await browser.wait(async () =>
        await browser.driver.executeScript('return document.readyState;') === 'loading', 2000)
        .then(() => true, () => true);
await browser.wait(async () =>
        await browser.driver.executeScript('return document.readyState;') === 'complete', 5000)

这篇关于如何在量角器中等待自动测试脚本,直到页面完全加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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