How to make automated test scripts in protractor wait, until the page is loaded fully(如何使量角器中的自动化测试脚本等待,直到页面完全加载)
问题描述
不,但真的!我知道这个通用问题已被问过数千次,但有一些更具体的问题对我来说似乎可行,因此我想知道如何实现它
问题
我正在使用
对
如果不完全相同,但我如何让量角器挂起,直到页面完全加载
重要考虑
显然,我可以做很多肮脏的解决方案,比如显式等待.但是我每隔一段时间就会回到这个问题,所以我对这些 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
- I'm against
browser.sleep()
for more than 1000 ms! browser.waitForAngular()
as this is not an angular pageExpectedConditions.urlIs()
the url is the variable I'm assertingExpectedConditions.presenseOf()
the page maybe changing so I can't rely on elements insidebrowser.executeScript("return window.document.readyState")
returnscompete
immediately, though the page is still loading (I was certain this is what I need, but that didn't work either)- 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)
这篇关于如何使量角器中的自动化测试脚本等待,直到页面完全加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使量角器中的自动化测试脚本等待,直到页面完全加载
基础教程推荐
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- 直接将值设置为滑块 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01