【发布时间】:2020-08-06 15:35:53
【问题描述】:
问题:
我无法使用 Capybara、rspec 和 selenium webdriver 登录 Web 应用程序。 我可以在各个字段中填写用户名和密码,但是当我尝试单击登录按钮时,应用程序没有登录。相反,应用程序返回“无法处理的实体”(尝试启用和禁用 cookie)。使用 Headless chromium 64 Linux。
lib/abcd.rb
def click_login user, password
visit "https://www.******.com/users/sign_in"
fill_in 'user[email]', :with => user
fill_in 'user[password]', :with => password
click_button 'Login'
end
测试用例:
require_relative 'lib/*****.rb'
describe 'Visit Websites', type: :feature, driver: :selenium_chrome_headless do
it "TC001_Test case 1" do
click_login "user@account.com", "password123"
expect(page).to have_title "Welcome to home page"
end
output:// application stays in the same page
it "TC002_Test case 2" do
find(:xpath,".account menu").click
expect(page).to have_title "Account details page"
end
驱动程序设置 - 方法 1
def setup_driver
Capybara.register_driver :selenium_chrome_headless do |app|
Capybara::Selenium::Driver.new(app, browser: :chrome, options: driver_options, :driver_path => 'bin/chromedriver')
end
Capybara.configure do |config|
config.run_server = false
config.default_driver = :selenium_chrome_headless
end
end
def driver_options
options = Selenium::WebDriver::Chrome::Options.new(binary: 'bin/headless-chromium')
arguments = %w[--headless --disable-gpu --window-size=1280x1696
--disable-application-cache --disable-infobars --no-sandbox
--hide-scrollbars --enable-logging --log-level=0
--single-process --ignore-certificate-errors --homedir=/tmp]
arguments.each do |argument|
options.add_argument(argument)
end
options
end
驱动程序设置 - 方法 2
def setup_driver
Capybara.register_driver :selenium_chrome_headless do |app|
Capybara::Selenium::Driver.new(app, browser: :chrome, options: driver_options, :driver_path => 'bin/chromedriver')
end
Capybara.configure do |config|
config.run_server = false
config.default_driver = :selenium_chrome_headless
end
end
def driver_options
options = Selenium::WebDriver::Chrome::Options.new(binary: 'bin/headless-chromium')
arguments = %w[--headless --disable-gpu --window-size=1280x1696
--disable-application-cache --disable-infobars --no-sandbox
--hide-scrollbars --enable-logging --log-level=0
--single-process --ignore-certificate-errors --homedir=/tmp]
arguments.each do |argument|
options.add_argument(argument)
end
options
end
【问题讨论】:
-
使用堆栈跟踪显示完整的错误消息
标签: ruby rspec selenium-chromedriver capybara ui-automation