硒的webdriver和通用等待或延迟 [英] Selenium WebDriver and generic wait or delay

查看:221
本文介绍了硒的webdriver和通用等待或延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我拼命地寻找一种方式来拖延的webdriver一些处决,但我似乎没有找到一个。

So I'm desperately looking for a way to delay some executions in WebDriver but I don't seem to find one.

Web应用程序,我尝试针对运行黑盒测试,工程用Ajax调用但是这些Ajax调用不要在DOM渲染什么,所以我不能用明确的等待。此外,隐含只适用于 find_element 语句,并再次将没有任何意义。

The web app which I try to run black box test against, works with ajax calls but these ajax calls do not render anything on DOM, thus I can't use explicit wait. Also, the implicit only works for find_element statements and again won't be useful.

我不得不使用成功 time.sleep(),但我希望有延迟执行的更好的方式。

I had success using time.sleep() but I hope there is a nicer way of delaying the execution.

推荐答案

从我明白了什么(它的凌晨1点在这里,我可能会错过的东​​西),你需要你的测试以AngularJS同步,等待未完成的请求和角度,以安顿下来。

From what I understand (it's 1am here, I may miss something), you need your tests to be synchronized with AngularJS, waiting for outstanding requests and angular to "settle down".

这是什么,在Javascript世界, 量角器 完美地解决了 - 它总是知道何时角已准备就绪,它使测试更自然,你就别想同步的问题 - 它工作顺利,开箱即用:

This is what, in Javascript world, protractor solves perfectly - it always knows when Angular is ready and it makes the tests much more natural, you don't even think about synchronization issues - it works smoothly and out of the box:

您不再需要添加等待,可供您的测试。量角器
  可以在测试自动执行下一步骤的时刻
  网页完成尚未完成的任务,所以您不必担心
  等待您的测试和网页同步。

You no longer need to add waits and sleeps to your test. Protractor can automatically execute the next step in your test the moment the webpage finishes pending tasks, so you don’t have to worry about waiting for your test and webpage to sync.

对于Python中,有 pytractor 项目听起来像你应该评估:

As for Python, there is pytractor project that sounds like something you should evaluate:

pytractor是一个扩展到Selenium绑定的Python。它的
  目标是使angular.js应用测试与Python更容易。

pytractor is an extension to the Selenium bindings for Python. Its goal is to make testing of angular.js applications easier with Python.

它是建立在量角器,官方的Javascript的某些部分
  E2E /场景测试框架Angular.js。

It is built on some parts of protractor, the "official" Javascript E2E/Scenario testing framework for Angular.js.

作为红旗,注意项目不积极维护。至少,你可以学习的来源和使用在code推出的想法。

As a red flag, note that the project is not actively maintained. At least, you may study the source and use the ideas introduced in the code.

请注意,国内量角器 pytractor 注入哪些是异步执行的客户端脚本。为了等待角是准备,它们都使用 angular.getTestability(EL).whenStable()来源)。

Note that internally protractor and pytractor inject client-side scripts which are asynchronously executed. In order to wait for Angular to be "ready", they both use angular.getTestability(el).whenStable() (source).

另请参阅:

  • Understanding execute async script in Selenium
  • Using Angular JS(Protractor) with Selenium in Python
  • Force Selenium to wait for AngularJS

这篇关于硒的webdriver和通用等待或延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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