I am still new to Selenium WD and performing remote blackbox tests in general. I am trying to input the email and password values into their respective fields to login to my page. I am able to navigate to the sign in page from home. However, not matter how many ways I write it, the console returns a failing test and an error saying 'element cannot be found.' This is the signin form:
<div class="panel panel-default">
<div class="panel-body">
<h1>Log in</h1>
<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
<div class="field">
<div class="form-field_2">
<%= f.label :email %> : </div>
<div style="width: 50%; float: left; padding: 5px" id="email">
<%= f.email_field :email, autofocus: true %>
</div>
</div>
<br/>
<br/>
<div class="field">
<div class='form-field_2'>
<%= f.label :password %> : </div>
<div style="width: 50%; float: left; padding: 5px" id="password">
<%= f.password_field :password, autocomplete: "off"%>
</div>
</div>
<br/>
<br/>
<% if devise_mapping.rememberable? -%>
<div class="field">
<%= f.check_box :remember_me %>
<%= f.label :remember_me %>
</div>
<% end %>
<br/>
<div class="actions">
<div id="signin" style="text-align: center;">
<%= f.submit "Log in", class: "btn btn-danger", id: 'submit' %>
</div>
</div>
<% end %>
<br/>
<%= render "devise/shared/links" %>
</div>
</div>
My spec:
require './spec/spec_helper'
require 'selenium-webdriver'
feature "Signing in to ArtWare" do
before(:all) do
@driver = Selenium::WebDriver.for(:chrome)
end
it 'should let user in with a valid account and password' do
@driver.navigate.to 'https://artwear.herokuapp.com/'
@driver.find_element(:id, "signin").click
fill_in "user[email]", with: "[email protected]"
fill_in "user[password]", with: 'asdfasdf'
@driver.find_element(:id, "submit").click
expect(page).to have_content('Signed in successfully.')
end
it 'should let me logout' do
@driver.find_element(:id, "logout").click
expect(page).to have_content('Signed out successfully.')
end
it 'should not let use in with an invalid account' do
@driver.find_element(:id, "signin").click
@driver.find_element(:id, 'user[email]').set('[email protected]')
@driver.find_element(:id, "user[password]").set('asdfasdf')
@driver.find_element(:id, "submit").click
expect(page).to have_content("Invalid email or password")
end
it 'should not let user in with an invalid password' do
@driver.navigate.to 'https://artwear.herokuapp.com/'
@driver.find_element(:id, "logout").click
@driver.find_element(:id, "signin").click
@driver.find_element(:id, 'user[email]').set("[email protected]")
@driver.find_element(:id, "password").set('incorrect')
@driver.find_element(:id, "signin").click
expect(page).to have_content("Invalid email or password")
end
after(:all) do
@driver.quit
end
spec_helper:
require 'capybara/rspec'
require 'rubygems'
require 'bundler/setup'
Capybara.default_driver = :selenium
Capybara.app_host = 'http://artwear.herokuapp.com/'
Capybara.run_server = false
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app, :browser => :chrome)
end
and Gemfile
source 'http://rubygems.org'
gem 'rake'
gem 'rspec', '~> 3.3.0'
gem 'capybara', '~> 2.5.0'
gem 'selenium-webdriver', '2.47.1'
gem 'faker', '~> 1.5.0'
This is the output that I get for the email tag in Google DevTools:
<input autofocus="autofocus" type="email" value="" name="user[email]" id="user_email">
I have tried to change the selenium call to:
fill_in "user_email", with: "[email protected]"
fill_in 'user[email]', with: "[email protected]"
fill_in :user_email, with: "[email protected]"
@driver.find_element(:name, "user[email]").send_keys "[email protected]"
@driver.find_element(:name, "user[email]").set("[email protected]")
@driver.find_element(:id, 'user_email').set("[email protected]")
all of these return the same error:
Failure/Error: fill_in "user[email]", with: "[email protected]" Capybara::ElementNotFound: Unable to find field "user[email]" or: Failure/Error: @driver.find_element(:id, 'user[email]').set("[email protected]") Selenium::WebDriver::Error::NoSuchElementError: no such element
Could someone tell me what I am missing? I think I have gone through virtually every version that I have found in all Stackoverflow posts. Thank you in advance.