I am testing links on a website using selenium and cucumber. Naturally these links would load in the current browser window. Though when I run my test they are opening in a new window each time! Even opening a webpage .get will open a brand new window. What am I missing here?
Also I am only doing testing in firefox so far
env.rb
require 'Rspec'
require 'selenium-webdriver'
include Rspec::Expectations
#=======================================================================================
Before do
@driver = Selenium::WebDriver.for :firefox
@accept_next_alert = true
@driver.manage.timeouts.implicit_wait = 30
@verification_errors = []
end
After do
#@driver.quit
@verification_errors.should == []
end
#=======================================================================================
wait = Selenium::WebDriver::Wait.new(:timeout => 25)
def element_present?(how, what)
@driver.find_element(how, what)
true
rescue Selenium::WebDriver::Error::NoSuchElementError
false
end
def alert_present?()
@driver.switch_to.alert
true
rescue Selenium::WebDriver::Error::NoAlertPresentError
false
end
def verify(&blk)
yield
rescue ExpectationNotMetError => ex
@verification_errors << ex
end
def close_alert_and_get_its_text(how, what)
alert = @driver.switch_to().alert()
alert_text = alert.text
if (@accept_next_alert) then
alert.accept()
else
alert.dismiss()
end
alert_text
ensure
@accept_next_alert = true
end
I realized that it is opening an odd firefox browser. I have changed the settings in firefox to open windows in new tabs (based on another question) and I realized selenium is opening an instance of firefox that has all old settings. I don't have multiple versions of firefox installed I don't understand where this could be coming from either.
step def:
When /^I am viewing Google$/ do
if @driver.current_url != "www.google.com"
@driver.get "www.google.com"
end
end
This code repeated will load many windows. Also any .click interactions with the website
I have recently asked a question that is similar to this one (didn't realize I was somewhat repeating myself) here is the link to it for anyone interested:
How to use same browser window for automated test using selenium-webdriver (ruby)?