我正在尝试在我的页面上测试登录功能,该功能具有隐藏的形式。 功能文件:
Feature: Test login page
As a visitor to the site
I can login
Scenario: User login
When I go to http://abc.com/
And I enter username: abc and password: abc
Then I should see "My Account (abc)"
Step_Definitions:
When /^I go to (.*)$/ do |path|
visit path
end
require 'net/http'
When (/^I enter username: abc and password: abc$/) do
uri = URI('http://www.abc.com/')
res = Net::HTTP.post_form(uri,{ 'username' => 'abc' , 'password' => 'abc'})
puts res
end
Then /^I should see "(.*)"$/ do |text|
page.should have_content(text)
end
用户名和密码正确,但此方案失败。我的帖子是否正确..我需要保持会话还是什么? res的输出也不正确,它甚至不能登录。
这要归功于贾斯汀,解决方案 - >不要使用HTTP帖子,因为selenium和capybara是用户模仿用户行为。所以按照用户的流程。