gpt4 book ai didi

ruby-on-rails - 如何在 capybara 场景中添加等待条件?

转载 作者:行者123 更新时间:2023-12-04 13:20:43 25 4
gpt4 key购买 nike

我正在使用capybara来测试我的Rails应用程序以进行集成测试。
在我的应用程序中,有许多Lightbox,Ajax和js调用。

 @javascript   
Scenario: I agree functionatilty
Given I go to the create account page
When I click on button which is given as image "lnkTerms2"
And I follow "i_agree"
Then I go to the create account page

在上面的代码中,lnkTerms2是和id,这将有助于调用js函数来打开灯箱。
我收到一个错误
   Element is not currently visible and so may not be interacted with (Selenium::WebDriver::Error::ElementNotDisplayedError)
[remote server] resource://fxdriver/modules/atoms.js:9519:in `unknown'
[remote server] file:///tmp/webdriver-profile20111117-6876-18cfcfp/extensions/fxdriver@googlecode.com/components/nsCommandProcessor.js:256:in `unknown'
[remote server] file:///tmp/webdriver-profile20111117-6876-18cfcfp/extensions/fxdriver@googlecode.com/components/nsCommandProcessor.js:305:in `unknown'
[remote server] file:///tmp/webdriver-profile20111117-6876-18cfcfp/extensions/fxdriver@googlecode.com/components/nsCommandProcessor.js:320:in `unknown'
[remote server] file:///tmp/webdriver-profile20111117-6876-18cfcfp/extensions/fxdriver@googlecode.com/components/nsCommandProcessor.js:197:in `unknown'
(eval):2:in `send'
(eval):2:in `click_link'
./features/step_definitions/web_steps.rb:300:in `/^I click on button which is given as image "([^"]*)"$/'
features/Sign_up_process.feature:61:in `When I click on button which is given as image "lnkTerms2"'

问题是由于在webdriver中调用了此函数,因此没有时间加载javascript和ajax调用。
而且灯箱没有打开。
因此,请提出任何解决方案。

另外,如果我写那行
When I click on button which is given as image "lnkTerms2"

在4到5条语句之后,它可以正常工作,因为它有时间加载js。

最佳答案

对于等待ajax的步骤后的暂停,请尝试:

And I wait 5 seconds

您必须将以下代码添加到web_steps.rb:
When /^I wait (\d+) seconds?$/ do |seconds|
sleep seconds.to_i
end

关于ruby-on-rails - 如何在 capybara 场景中添加等待条件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8162855/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com