2016-03-07 19:52:19 -05:00
|
|
|
# frozen_string_literal: true
|
2010-09-17 19:56:32 -04:00
|
|
|
require 'spec_helper'
|
2013-11-14 16:25:00 -05:00
|
|
|
require "selenium-webdriver"
|
|
|
|
|
2016-07-26 14:15:35 -04:00
|
|
|
Selenium::WebDriver::Firefox.driver_path = '/home/travis/geckodriver' if ENV['TRAVIS'] && ENV['GECKODRIVER']
|
|
|
|
|
2013-11-14 16:25:00 -05:00
|
|
|
Capybara.register_driver :selenium_focus do |app|
|
2016-07-26 14:15:35 -04:00
|
|
|
# profile = Selenium::WebDriver::Firefox::Profile.new
|
|
|
|
# profile["focusmanager.testmode"] = true
|
|
|
|
# Capybara::Selenium::Driver.new(app, browser: :firefox, profile: profile)
|
|
|
|
Capybara::Selenium::Driver.new(app, browser: :firefox)
|
2013-11-14 16:25:00 -05:00
|
|
|
end
|
2009-11-14 04:44:46 -05:00
|
|
|
|
2012-10-30 09:32:47 -04:00
|
|
|
module TestSessions
|
2013-11-14 16:25:00 -05:00
|
|
|
Selenium = Capybara::Session.new(:selenium_focus, TestApp)
|
2012-10-30 09:32:47 -04:00
|
|
|
end
|
|
|
|
|
2016-04-04 16:26:29 -04:00
|
|
|
skipped_tests = [
|
2012-07-21 16:44:10 -04:00
|
|
|
:response_headers,
|
|
|
|
:status_code,
|
|
|
|
:trigger
|
|
|
|
]
|
2016-04-04 16:26:29 -04:00
|
|
|
skipped_tests << :windows if ENV['TRAVIS'] && !ENV['WINDOW_TEST']
|
|
|
|
|
|
|
|
Capybara::SpecHelper.run_specs TestSessions::Selenium, "selenium", :capybara_skip => skipped_tests
|
2012-07-21 16:44:10 -04:00
|
|
|
|
2014-04-03 13:25:03 -04:00
|
|
|
RSpec.describe Capybara::Session do
|
2009-11-14 04:44:46 -05:00
|
|
|
context 'with selenium driver' do
|
|
|
|
before do
|
2010-09-07 12:16:19 -04:00
|
|
|
@session = TestSessions::Selenium
|
2009-11-14 04:44:46 -05:00
|
|
|
end
|
2009-12-11 16:40:23 -05:00
|
|
|
|
2009-11-14 04:44:46 -05:00
|
|
|
describe '#driver' do
|
2009-12-11 16:40:23 -05:00
|
|
|
it "should be a selenium driver" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(@session.driver).to be_an_instance_of(Capybara::Selenium::Driver)
|
2009-11-14 04:44:46 -05:00
|
|
|
end
|
|
|
|
end
|
2009-12-11 16:40:23 -05:00
|
|
|
|
2009-11-14 04:44:46 -05:00
|
|
|
describe '#mode' do
|
|
|
|
it "should remember the mode" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(@session.mode).to eq(:selenium_focus)
|
2009-11-14 04:44:46 -05:00
|
|
|
end
|
|
|
|
end
|
2009-12-11 16:40:23 -05:00
|
|
|
|
2014-01-17 02:57:06 -05:00
|
|
|
describe "#reset!" do
|
|
|
|
it "freshly reset session should not be touched" do
|
|
|
|
@session.instance_variable_set(:@touched, true)
|
|
|
|
@session.reset!
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(@session.instance_variable_get(:@touched)).to eq false
|
2014-01-17 02:57:06 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-07-13 07:15:44 -04:00
|
|
|
describe "exit codes" do
|
|
|
|
before do
|
|
|
|
@current_dir = Dir.getwd
|
2012-07-13 07:28:33 -04:00
|
|
|
Dir.chdir(File.join(File.dirname(__FILE__), '..'))
|
2012-07-13 07:15:44 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
Dir.chdir(@current_dir)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should have return code 1 when running selenium_driver_rspec_failure.rb" do
|
|
|
|
`rspec spec/fixtures/selenium_driver_rspec_failure.rb`
|
2013-11-14 12:43:36 -05:00
|
|
|
expect($?.exitstatus).to be 1
|
2012-07-13 07:15:44 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should have return code 0 when running selenium_driver_rspec_success.rb" do
|
|
|
|
`rspec spec/fixtures/selenium_driver_rspec_success.rb`
|
2013-11-14 12:43:36 -05:00
|
|
|
expect($?.exitstatus).to be 0
|
2012-07-13 07:15:44 -04:00
|
|
|
end
|
|
|
|
end
|
2015-04-12 23:32:12 -04:00
|
|
|
|
2014-07-02 22:31:13 -04:00
|
|
|
describe "#accept_alert" do
|
2014-07-02 22:10:30 -04:00
|
|
|
it "supports a blockless mode" do
|
|
|
|
@session.visit('/with_js')
|
|
|
|
@session.click_link('Open alert')
|
|
|
|
@session.accept_alert
|
|
|
|
expect{@session.driver.browser.switch_to.alert}.to raise_error("No alert is present")
|
|
|
|
end
|
|
|
|
end
|
2015-04-12 23:32:12 -04:00
|
|
|
|
|
|
|
context "#fill_in with { :clear => :backspace } fill_option", :requires => [:js] do
|
|
|
|
it 'should fill in a field, replacing an existing value' do
|
|
|
|
@session.visit('/form')
|
|
|
|
@session.fill_in('form_first_name', :with => 'Harry',
|
|
|
|
fill_options: { clear: :backspace} )
|
|
|
|
expect(@session.find(:fillable_field, 'form_first_name').value).to eq('Harry')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should only trigger onchange once' do
|
|
|
|
@session.visit('/with_js')
|
|
|
|
@session.fill_in('with_change_event', :with => 'some value',
|
|
|
|
:fill_options => { :clear => :backspace })
|
|
|
|
# click outside the field to trigger the change event
|
|
|
|
@session.find(:css, 'body').click
|
|
|
|
expect(@session.find(:css, '.change_event_triggered', :match => :one)).to have_text 'some value'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should trigger change when clearing field' do
|
|
|
|
@session.visit('/with_js')
|
|
|
|
@session.fill_in('with_change_event', :with => '',
|
|
|
|
:fill_options => { :clear => :backspace })
|
|
|
|
# click outside the field to trigger the change event
|
|
|
|
@session.find(:css, 'body').click
|
|
|
|
expect(@session).to have_selector(:css, '.change_event_triggered', :match => :one)
|
|
|
|
end
|
|
|
|
end
|
2015-08-09 12:55:56 -04:00
|
|
|
|
2015-04-13 00:25:13 -04:00
|
|
|
context "#fill_in with { clear: :none } fill_options" do
|
|
|
|
it 'should append to content in a field' do
|
|
|
|
@session.visit('/form')
|
|
|
|
@session.fill_in('form_first_name', :with => 'Harry',
|
|
|
|
fill_options: { clear: :none} )
|
|
|
|
expect(@session.find(:fillable_field, 'form_first_name').value).to eq('JohnHarry')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "#fill_in with { clear: Array } fill_options" do
|
2016-04-05 12:33:19 -04:00
|
|
|
it 'should pass the array through to the element' do
|
2015-04-13 00:25:13 -04:00
|
|
|
#this is mainly for use with [[:ctrl, 'a'], :backspace] - however since that is platform dependant I'm testing with something less useful
|
|
|
|
@session.visit('/form')
|
|
|
|
@session.fill_in('form_first_name', :with => 'Harry',
|
|
|
|
fill_options: { clear: [[:shift, 'abc'], :backspace] } )
|
|
|
|
expect(@session.find(:fillable_field, 'form_first_name').value).to eq('JohnABHarry')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-08-09 12:55:56 -04:00
|
|
|
describe "#path" do
|
|
|
|
it "returns xpath" do
|
2015-08-20 17:35:15 -04:00
|
|
|
# this is here because it is testing for an XPath that is specific to the algorithm used in the selenium driver
|
|
|
|
@session.visit('/path')
|
2015-08-10 09:53:38 -04:00
|
|
|
element = @session.find(:link, 'Second Link')
|
|
|
|
expect(element.path).to eq('/html/body/div[2]/a[1]')
|
2015-08-09 12:55:56 -04:00
|
|
|
end
|
|
|
|
end
|
2009-11-14 04:44:46 -05:00
|
|
|
end
|
|
|
|
end
|
2013-11-22 18:59:51 -05:00
|
|
|
|
2014-04-03 13:25:03 -04:00
|
|
|
RSpec.describe Capybara::Selenium::Driver do
|
2013-11-22 18:59:51 -05:00
|
|
|
before do
|
|
|
|
@driver = Capybara::Selenium::Driver.new(TestApp, browser: :firefox)
|
|
|
|
end
|
2015-04-12 23:32:12 -04:00
|
|
|
|
2013-11-22 18:59:51 -05:00
|
|
|
describe '#quit' do
|
|
|
|
it "should reset browser when quit" do
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(@driver.browser).to be
|
2013-11-22 18:59:51 -05:00
|
|
|
@driver.quit
|
|
|
|
#access instance variable directly so we don't create a new browser instance
|
2013-11-14 12:43:36 -05:00
|
|
|
expect(@driver.instance_variable_get(:@browser)).to be_nil
|
2013-11-22 18:59:51 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|