我有我的代码这个问题。我的应用程序内的这个页面使用http基本认证。我正在使用Rspec和Capybara测试我的应用程序,但是在删除评论时我遇到了数据确认问题,但它似乎无法通过。Rails 4水豚+硒,数据确认
这里是我的测试代码:
before(:each) do
page.driver.browser.authorize ENV['ADMIN_LOGIN'], ENV['ADMIN_PASSWORD']
...
end
...
it "should redirect to create new inspiring post and create new post on click" do
visit admin_path
click_link("create_inspi")
fill_in("Title",:with => "Test title")
fill_in("Short",:with => "Test short desc")
fill_in("Body",:with => "Test body desc")
fill_in("Date",:with => "12.12.2012")
click_button("Create new post")
test(
have_content("Test title"),
have_content("12.12.2012")
)
end
example "when inside Link to all... you can delete particular comment",:js => true do
visit admin_path
click_link("Link to all comments in Web development and Motivation category")
click_link(@webdev_comment.id)
page.driver.browser.accept_js_confirms
end
现在,默认情况下为我的测试我使用的水豚:: RackTest ::驱动程序,但现在因为我无法找到一个方法来确认RackTest我的数据确认必须使用Selenium驱动程序来确认此数据。但是使用这个硒驱动程序我的最后一个例子现在测试时,我发现一个问题:
1) testing admin webpage when inside Link to all... you can delete particular comment
Failure/Error: page.driver.browser.authorize ENV['ADMIN_LOGIN'], ENV['ADMIN_PASSWORD']
NoMethodError:
undefined method `authorize' for #<Selenium::WebDriver::Driver:0x00000003e6ad68>
# ./spec/features/admin.rb:13:in `block (2 levels) in <top (required)>'
我的问题是:
如何与硒验证基本的HTTP?
-------------- EDITED ------------------
我找到了一种方法来登录到管理员通过使用此代码
example "when inside Link to all... you can delete particular comment",:js => true do
visit root_path
@url = current_url
@tablica = @url.split("http://")
@correct_url = @tablica[1]
admin_selenium_path = "http://#{ENV["ADMIN_LOGIN"]}:#{ENV["ADMIN_PASSWORD"]}@#{@correct_url}admin"
page.visit admin_selenium_path
click_link("Link to all comments in Web development and Motivation category")
click_link(@webdev_comment.id)
page.driver.browser.accept_js_confirms
end
但现在,即使它登录,有字面上的测试数据库中没有数据硒驱动程序,它抛出周围说,特定的对象不能被发现的错误。
before(:each) do
# page.driver.browser.authorize ENV['ADMIN_LOGIN'], ENV['ADMIN_PASSWORD']
@mystory = Mystory.create(name: "My story:",body: "My name is Matthew...")
end
上面这段代码之前的块内没有创建一个必要的@mystory记录里面的数据库的水豚与硒驱动程序。
任何想法如何用selenium驱动程序填充水豚数据库?
遗憾的是它不工作。但感谢您的帮助! :)。 – Matthew 2014-09-11 14:10:47
您是否在确认出现之前添加它?而不是之后?如果是之后,那么它将不起作用。它必须在(甚至在测试的第一行)之前完成 – RichardAE 2014-09-11 15:42:57
我在块前添加它并且它不工作。 – Matthew 2014-09-11 15:47:53