黄瓜和 JavaScript
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要引入延迟,您可以使用传统的等待机制:
我假设“选择显示为多个”意味着用户可以使用“Ctrl+LeftClick”来选择列表中的多个项目。在这种情况下,上面的以下代码应该允许您继续设置/选择项目,直到您满意为止。
http://wiki.openqa.org/display/WTR/Selection+Boxes
To introduce delay you could use traditional waiting mechanics:
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
您在这里应该做的是在尝试与页面交互之前验证选择元素是否存在于页面上。
您没有指定实际使用什么来驱动浏览器。但是,例如,如果您使用的是水豚,则有一个
has_select?
方法,如果没有立即找到该元素,该方法将自动等待一小段时间以使其出现,从而精确地处理你所描述的那种 AJAX 情况。Selenium 有一个 wait_for_element_present 方法,它可以做同样的事情。
一般来说,使用的模式基本上是这样的:
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: