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

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

问题描述

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

问题

我正在使用

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

重要考虑

显然,我可以做很多肮脏的解决方案,比如显式等待.但是我每隔一段时间就会回到这个问题,所以我对这些 70% 的时间都针对特定原因有效的肮脏解决方案不感兴趣

附:我认为该按钮会更改 document.load() 事件.但是我不知道我应该在控制台中写什么,以便在我刷新页面时该脚本记录一条消息

解决方案

你试过了吗

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

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

The problem

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

What I tried/what won't work for me

  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

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

Important to consider

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. 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

解决方案

Have you tried

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天全站免登陆