水豚找不到 javascript
我是水豚测试的新手,遇到了一些问题。
我有一个正在尝试运行的场景,这是步骤实现:
When /^I select the signin link$/ do
click_link 'Sign in'
end
我尝试使用 xpath、css 访问此链接,并尝试了 within
实现。 Capybara 似乎无法找到它,并且在所有情况下都会返回 Capybara::ElementNotFound
异常。
当我加载没有 JavaScript 的网页时,链接不可见,我想知道这是否就是水豚找不到它的原因。我找到了一个 trigger
方法,但不确定它是如何工作的。有谁有trigger
的工作示例,或者我应该做什么的任何其他想法?
I am new to Capybara testing and am having a few issues.
I have a scenario I am trying to run, and this is the step implementation:
When /^I select the signin link$/ do
click_link 'Sign in'
end
I have tried to access this link with xpath, css, and tried the within
implementation as well. Capybara cannot seem to find it, and returns a Capybara::ElementNotFound
exception in all cases.
When I load the webpage without JavaScript, the link is not visible, and I'm wondering if this is why Capybara cannot find it. I found a trigger
method, but am unsure how it works. Does anyone have a working example of trigger
, or any other ideas for what I should do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否使用 selenium webdriver 来运行此测试?听起来您正在尝试运行一个需要 javascript 来查看某些元素的场景,而不使用支持 javascript 的驱动程序。
在您的
.feature
文件中,您所要做的就是在场景之前添加以下行:@javascript 标记告诉水豚使用 selenium-webdriver 来运行测试。它将启动 Firefox 并进行测试 - 允许所有 JavaScript 功能正常工作。这会大大减慢测试速度,因此仅在绝对必要时才使用它来测试 ajax-y 和 javascript-y 行为。
如果仍然不起作用,您可以使用此步骤:
这将在新浏览器中以该页面的当前状态为您打开页面,以便您检查。
Are you using the selenium webdriver to run this test? It sounds like you are trying to run a scenario that requires javascript to see certain elements, without using a driver that supports javascript.
In your
.feature
file all you have to do is add this line before the scenario:The @javascript tag tells capybara to use selenium-webdriver to run the test. It'll fire up firefox and go through the test - allowing all javascript functionality to work. This slows tests down considerably so only use it when absolutely necessary to test ajax-y and javascript-y behavior.
If that still doesn't work you can use this step:
Which will open the page up for you in a new browser in that page's current state for your inspecting pleasure.