让 Ruby 等到网页更改
Making Ruby wait until web page has changed
我在 Ruby/Cucumber 中进行了一项测试,即 运行 对网络服务的几个连续页面进行测试。我需要让它等到某个特定页面完成它的工作并关闭,以便检查后续页面的内容。
除了测试看错页面时,其他一切正常。
我看到有 wait & until 方法,但我不知道如何将它们应用于检查当前 URL - 我怎样才能让我的程序等到要检查的页面有打开了吗?
如有任何帮助,我们将不胜感激。
感谢您的评论。测试是 运行 selenium webdriver 和 Firefox 浏览器。希望这能让它更清楚。
我想让它等待之前的代码是:
def confirm_payment
within_frame(find('iframe')) do
find_by_id('CompanyLogo').click
end
end
这是此块的最后一步:
if @pymnt_rqd == "y"
confirm_customer_details
enter_payment_card_details
confirm_payment
#wait here until the page has turned to the response screen
end
我需要它等到页面翻过再转到这个:
#Check the text on the response screen against the csv file.
check_response_screen
要等待新页面,您可以等待新正文:
require 'selenium-webdriver'
driver = Selenium::WebDriver.for :chrome
wait = Selenium::WebDriver::Wait.new(timeout: 10)
driver.navigate.to "http://whosebug.com/"
# get the body element
body = driver.find_element(:css, "body")
# do something to change the page
...
# wait for a new page (new body)
wait.until {driver.find_element(:css, "body") != body}
我在 Ruby/Cucumber 中进行了一项测试,即 运行 对网络服务的几个连续页面进行测试。我需要让它等到某个特定页面完成它的工作并关闭,以便检查后续页面的内容。
除了测试看错页面时,其他一切正常。
我看到有 wait & until 方法,但我不知道如何将它们应用于检查当前 URL - 我怎样才能让我的程序等到要检查的页面有打开了吗?
如有任何帮助,我们将不胜感激。
感谢您的评论。测试是 运行 selenium webdriver 和 Firefox 浏览器。希望这能让它更清楚。
我想让它等待之前的代码是:
def confirm_payment
within_frame(find('iframe')) do
find_by_id('CompanyLogo').click
end
end
这是此块的最后一步:
if @pymnt_rqd == "y"
confirm_customer_details
enter_payment_card_details
confirm_payment
#wait here until the page has turned to the response screen
end
我需要它等到页面翻过再转到这个:
#Check the text on the response screen against the csv file.
check_response_screen
要等待新页面,您可以等待新正文:
require 'selenium-webdriver'
driver = Selenium::WebDriver.for :chrome
wait = Selenium::WebDriver::Wait.new(timeout: 10)
driver.navigate.to "http://whosebug.com/"
# get the body element
body = driver.find_element(:css, "body")
# do something to change the page
...
# wait for a new page (new body)
wait.until {driver.find_element(:css, "body") != body}