黄瓜和 JavaScript

发布于 2024-09-29 08:58:06 字数 160 浏览 3 评论 0原文

我正在使用 ajax 来进行选择。用户必须单击选择中的一项。

一个。 Ajax 需要一些时间,我是否需要延迟测试,如果需要怎么办? b.选择显示为多个

项目,并且标记中的类将其定义为可单击项目。如何告诉黄瓜从选择中选择一个项目?

问候

埃兰·诺伊

I am using ajax to bring up a selection. The user has to click one item in the selection.

a. Ajax takes some time, do I need a delay in the test, and if so how?
b. The selection appears as multiple

items and the class in the tag defines it as clickable item. How do I tell cucumber to select an item from the selection?

Regards

Elan Noy

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

作妖 2024-10-06 08:58:06

要引入延迟,您可以使用传统的等待机制:

$browser.select_list(:id,'selection_field').select('first item') # Watir uses set or select
sleep 2  # Wait 2 seconds
$browser.select_list(:id,'selection_field').set('second item') # Watir uses set or select

我假设“选择显示为多个”意味着用户可以使用“Ctrl+LeftClick”来选择列表中的多个项目。在这种情况下,上面的以下代码应该允许您继续设置/选择项目,直到您满意为止。

http://wiki.openqa.org/display/WTR/Selection+Boxes

To introduce delay you could use traditional waiting mechanics:

$browser.select_list(:id,'selection_field').select('first item') # Watir uses set or select
sleep 2  # Wait 2 seconds
$browser.select_list(:id,'selection_field').set('second item') # Watir uses set or select

I am under the assumption that 'selection appears as multiple' means that a user can use 'Ctrl+LeftClick' to select multiple items in the list. In that case, the following code above should allow you to continue to set/select items until your heart is content.

http://wiki.openqa.org/display/WTR/Selection+Boxes

溺渁∝ 2024-10-06 08:58:06

您在这里应该做的是在尝试与页面交互之前验证选择元素是否存在于页面上。

您没有指定实际使用什么来驱动浏览器。但是,例如,如果您使用的是水豚,则有一个 has_select? 方法,如果没有立即找到该元素,该方法将自动等待一小段时间以使其出现,从而精确地处理你所描述的那种 AJAX 情况。

Selenium 有一个 wait_for_element_present 方法,它可以做同样的事情。

一般来说,使用的模式基本上是这样的:

  1. 断言该项目存在于页面上,使用某种方法,如果该项目没有立即出现,则该方法将重试,如果在设定的时间后没有出现,则超时
  2. 尝试交互一旦你确定它在页面上,就使用该元素

What you should aim to do here is to verify that the select element is present on the page before trying to interact with it.

You don't specify what you are actually using to drive your browser. But, for example, if you are using capybara, there is a has_select? method, which, usefully, will automatically wait a short time for the element to appear if it is not found immediately, precisely to handle the kind of AJAX situation you describe.

Selenium has a wait_for_element_present method which does much the same thing.

In general, the pattern to use basically this:

  1. Assert that the item is present on the page, using some method which will retry if it isn't immediately there, and times out if it does not appear after a set amount of time
  2. Attempt interacting with the element once you are certain it is on the page
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文