Webdriver测试-将事件/通知推送到测试 [英] Webdriver test - pushing events/notification to the test

查看:99
本文介绍了Webdriver测试-将事件/通知推送到测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是情况:

我们运行webdriver测试(python)测试胖客户端(Javascript)应用程序.当应用程序遇到错误时(通常:后端不响应或响应失败),它会显示我们遇到问题"的用户界面.

we run webdriver tests (python) testing a fat-client (Javascript) application. When the application is faced with an error (typically: backend does not respond/responds wit FAILURE) it shows an "We've got a problem" UI.

当前,发生这种情况时,webdriver测试只是超时:

Currently, when this happens, the webdriver test just times-out:

a/测试进行了一些交互

a/ the test carries out some interaction

b/应用程序响应时说我们遇到了问题"用户界面

b/ the application responds with the said "we've got a problem" UI

c/测试会扫描DOM,以查找在交互成功后应该出现的某些元素

c/ the test scans the DOM looking for some elements which should appear if the interaction succeeds

d/,因为这些DOM元素不存在,所以测试会重复步骤c/,直到超时为止

d/ as these DOM elements are not there the test repeats step c/ until it times-out

当然,我们可以在测试中显式编写一些代码以查找错误通知UI.但是,我们必须在测试中从多个位置调用它(而且我们很可能会错过多个位置,等等).

of course, we can explicitly write some code in the test that looks for the error-notification UI. However, we will have to call it from multiple places in our tests (and we're likely to miss several spots, etc.)

我们正在寻找的是与这些相似的东西:

what we are looking for is something along these lines:

在网络驱动程序下运行时,该应用程序将不会显示错误UI,而是调用一些API,这些API实际上会通知"网络驱动程序测试已发生错误.在测试方面,我们将在此通知上注册一个侦听器.触发后,侦听器将立即使测试失败.

when running under webdriver the app will not show the error UI but instead invoke some API which will essentially "notify" the webdriver test that an error has occurred. On the test side, we'll register a listener on this notification. when fired, the listener will immediately make the test fail.

本质上,我们正在寻找从应用程序端到webdriver测试端的事件分发API.

Essentially we are looking for an event dispatching API from the application side to the webdriver test side.

网络驱动程序是否提供这样的API?

Does webdriver offer such an API?

推荐答案

不是. Webdriver具有用于繁忙等待的API(表示为隐式等待).

Not really. Webdriver has an API for a busy wait (denoted Implicit Waits).

一个可以稍微修饰一下的建议是在两侧都使用迷你"sdk",但是我不确定Webdriver是否支持多线程(同时支持两个查询).

One suggestion that could slightly prettify this is using mini "sdk"s on both sides, but I'm not sure if Webdriver supports multithreading (two queries simultaneously) i.e.

  1. 如果发生错误,客户端会添加预定义的元素.
  2. 测试端生成一个新线程,并对预定元素使用隐式等待(仅在发生错误时添加).一旦他找到了元素(这意味着有错误,其中一个字段包含错误消息),就会用错误中断测试线程.

请参见此处为类似示例

这篇关于Webdriver测试-将事件/通知推送到测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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