Issue:
I am not able to login a web application using Capybara, rspec and selenium webdriver. I am able to fill the username and password to the respective fields, but when i tried to click on login button, application is not logging in. Instead the application returns 'Unprocessable entity' (tried enabling and disabling the cookies). Using 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
Test case:
require_relative 'lib/*****.rb'
describe 'Visit Websites', type: :feature, driver: :selenium_chrome_headless do
it "TC001_Test case 1" do
click_login "[email protected]", "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
driver setup - Approach 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
driver setup - Approach 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