#need to check the browser version is IE via webdriver as other browsers like ff and chrome do not to be maximised if(page.driver.browser.browser.to_s == "internet_explorer") page.driver.browser.manage.window.maximize end
Wednesday, June 20, 2012
IE webdriver maximize window
Running cucumber test with webdriver in Internet Explorer browser has alot of issues. One issue that I encounter is that the IE browser window is not opening in a maximized state. Apparently, webdriver needs to have IE browser fully maximize in order for webdriver to be able to locate elements.
A workaround that I use is to maximize the IE browser on my first cucumber steps.
To change/resize the browser window:
IE undefined method map for nil class
I get the following error when running webdriver in IE 7 and 8. I am using ruby, Capybara with selenium webdriver version 2.2.24
Undefined method `map` for nil:NilClass (NoMethodError) or NoMethodError Exception: undefined method `map` for nil:NilClassIt seems that IE stand alone webdriver could not switch between http to https then to http again correctly and therefore it could not find any of the DOM element. This also cause the error of unable to delete cookie in IE
Selenium::WebDriver::Error:JavascriptError Exception: Unable to delete cookie with name 'cookiename'The workaround that I have for this Internet explorer webdriver issue is to start the session with https instead of http. This seem to have solve the issue. Alternatively, during the session you can make the test to visit a https page and then visit the current page again.
Capybara refresh back forward a page
To refresh a page in Capybara using selenium webdriver simply call the webdriver method directly
page.driver.browser.navigate.refresh (to, back, forward) or you can use the visit 'url' method
Capybara save page method
This is a pretty useful method to save the current active page for debugging.
This method can be triggered when the scenario fail.
After do |scenario| if scenario.failed? page.save_page end endThis will create a file called capybara-timestamp.html in the current directory
Tuesday, June 19, 2012
Capybara running in IE - Internet Explorer
To switch capybara to run in IE or different browser:
Capybara.register_driver :selenium do |app| Capybara::Selenium::Driver.new(app, :browser => :internet_explorer) end or Capybara.register_driver :selenium do |app| Capybara::Selenium::Driver.new(app, :browser => :firefox) end or Capybara.register_driver :selenium do |app| Capybara::Selenium::Driver.new(app, :browser => :chrome) endFor IE, you just need to download the standalone ie driver from selenium webdriver page InternetExplorerDriver otherwise you will get the webdriver warning "the IE driver is moving to a standalone executable... Falling back to bundled DLLs for now.." You can put the IE standalone driver in your rubyxxx/bin folder.
Monday, June 18, 2012
Modal dialog present webdriver Error
To surpress the IE security warning modal dialog present (Selenium::WebDriver::Error::UnhandledAlertError) use the following code
Internet Explorer security warning modal dialog box:
"Do you want to view only the webpage content that was delivered securely?
This webpage contains content that will not be delivered using a secure HTTPS connection, which could compromise the security of the entire webpage
"
"Internet explorer - This page is accessing information that is not under its control. This poses a security risk. Do you want to continue?" This warning is probably because we are using the IE Standalone selenium webdriver.
The workaround for the issue:
begin click_link "test" rescue Selenium::WebDriver::Error:UnhandledAlertError => e # may need to use the page.driver.wait_until method to wait until the alert present other wise you may get the # No alert is active (Selenium::WebDriver::Error::NoAlertPresentError) #page.driver.browser.switch_to.alert.accept #page.driver.browser.switch_to.alert.dismiss click_link "test" end
cucumber undefined method 'step' for error
This error undefined method `step` for "#<object:0x1a4f9f0>" (NoMethodError) occurs because you are using an older version of cucumber and therefore and older version of the Gherkin gem.
I was using cucumber 1.0.2 and I got the undefined method 'step' error. I upgraded to cucumber 1.2.1 and it has the method defined.
I was using cucumber 1.0.2 and I got the undefined method 'step' error. I upgraded to cucumber 1.2.1 and it has the method defined.
Wednesday, June 13, 2012
Installing and managing Ruby version using RVM
To install ruby using RVM please go to this article which also explain on how to switch back and forth between different version of ruby:
Install Ruby Mac
Tuesday, June 12, 2012
Using 'Given/When/Then' in step definitions is deprecated, use 'step' to call other steps
If you are getting this warning
"Using 'Given/When/Then' in step definitions is deprecated, use 'step' to call other steps" then just change this line in your steps definitions:
Given /^the user logs in$/ do And 'the user visits the main page' And 'the user clicks on the login button' . . endTo:
Given /^the user logs in$/ do step('the user visits the main page') step('the user clicks on the login button') . . end
term/ansicolor LoadError - cannot load such file
When you are using Using cucumber (1.2.1), you may get the cannot load such file -- term/ansicolor (LoadError).
To fix it simply install 'gem install term-ansicolor'
Subscribe to:
Posts (Atom)