From 450e8597ebf8cb809b4936637b994baba032650e Mon Sep 17 00:00:00 2001 From: Angel Perez Date: Thu, 8 Mar 2018 19:30:00 -0400 Subject: [PATCH] Disable JavaScript on IE-specific scenarios --- spec/features/home_spec.rb | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/spec/features/home_spec.rb b/spec/features/home_spec.rb index c88f2d590..84e96d03d 100644 --- a/spec/features/home_spec.rb +++ b/spec/features/home_spec.rb @@ -132,26 +132,33 @@ feature "Home" do end feature 'IE alert' do - scenario 'IE visitors are presented with an alert until they close it', :js do - page.driver.headers = { "User-Agent" => "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)" } + scenario 'IE visitors are presented with an alert until they close it' do + # Selenium API does not include page request/response inspection methods + # so we must use Capybara::RackTest driver to set the browser's headers + Capybara.current_session.driver.header( + 'User-Agent', + 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)' + ) visit root_path expect(page).to have_xpath(ie_alert_box_xpath, visible: false) - expect(page.driver.cookies['ie_alert_closed']).to be_nil + expect(page.driver.request.cookies['ie_alert_closed']).to be_nil # faking close button, since a normal find and click # will not work as the element is inside a HTML conditional comment - page.driver.set_cookie 'ie_alert_closed', 'true' + page.driver.browser.set_cookie('ie_alert_closed=true') visit root_path expect(page).not_to have_xpath(ie_alert_box_xpath, visible: false) - expect(page.driver.cookies["ie_alert_closed"].value).to eq('true') + expect(page.driver.request.cookies['ie_alert_closed']).to eq('true') + + Capybara.current_session.driver.header('', '') end - scenario 'non-IE visitors are not bothered with IE alerts', :js do + scenario 'non-IE visitors are not bothered with IE alerts' do visit root_path expect(page).not_to have_xpath(ie_alert_box_xpath, visible: false) - expect(page.driver.cookies['ie_alert_closed']).to be_nil + expect(page.driver.request.cookies['ie_alert_closed']).to be_nil end def ie_alert_box_xpath