Save password prompts in Chrome 57 with WebDriver

When running Selenium WebDriver scripts against the latest version of Chrome (57) it shows a save password prompt that hasn’t appeared previously whilst using Chromedriver, as far as I know.

chrome 57 save password prompt Continue reading “Save password prompts in Chrome 57 with WebDriver”

WebDriverJs Select Lists in Chrome

Chromedriver/Chrome is pretty great at executing WebDriverJs scripts without taking away your focus (so you can execute them in the background whilst doing other things), the one exception I found was selecting items in a select list. I found it would do this:

Continue reading “WebDriverJs Select Lists in Chrome”

Lock down your browser versions if you run WebDriver tests

Recently our WebDriver tests that run in Chrome via a Windows service all suddenly stopped working even though we hadn’t made any changes to our tests. It seems Chrome had automatically updated itself on our WebDriver agents introducing a Chromium 38 bug meaning WebDriver won’t work at all (full details here and here). Getting these tests running again has been very painful, mainly due to Google not having standalone Chrome installers for any previous versions of Chrome publicly available.

If you run any WebDriver tests I highly recommend you lock down your browser versions to stop this happening to you in the future. Here’s how:

Firefox

Firefox is fantastic in this regard as they make every back version easily accessible as well as a simple way on all platforms to stop automatic upgrades. I tend to lock down to Firefox ESRs (Extended Support Releases) such as versions 24 and 31 which are listed on this comprehensive Wikipedia page.

To stop updates all you do is open preferences, advanced, update and select ‘never’.

Firefox Prevent Updates

Chrome

Chrome is a P.I.T.A. in both being able to install a previous version or lock down the currently installed one. Google prefer a Chrome web installer which always installs the latest version of Chrome, and if you want a specific version you need the alternate (offline) installer (for all users if you use a Windows service), but they only provide the latest installer. It’s hard if not impossible to find older alternate (offline) installers on the web, even oldapps.com can’t host them.

Once you have a version of Chrome on Windows that you want to keep, you need to download a group policy template, and disable automatic updates before running Chrome (so it doesn’t automatically update before you set the group policy). I won’t go into full details but you should be able to find all details here. Some sites mention using a plugin to stop updates but this doesn’t work so you’ll need to go down the group policy path.

Summary

Locking down browser versions avoids having to suddenly work out why your entire WebDriver test suite fails.

Setting text in Chromedriver is rather slow

A colleague contacted me today to see if there’s a way to increase the speed of a text_field.set operation in watir-webdriver when using Chrome on Mac OSX. I hadn’t noticed it before but Chrome seems to enter character by character into text fields which is noticeably slower than Firefox which seems to ‘set’ the field at once. Jari Bakken suggested I try Chrome native events which I didn’t even realize existed on Mac OSX.

So, I took Jari’s suggestion and I created a benchmark of a .set operation conducted ten times in a row on Firefox, and Chrome with and without native events. The results looked like:

                        user       system     total        real
set firefox             0.160000   0.020000   0.180000  ( 8.205473)
set chrome non-native   0.100000   0.010000   0.110000  (44.980334)
set chrome native       0.100000   0.010000   0.110000  (31.501647)

You can see that Chrome is drastically slower than Firefox in setting text fields, but native events does seem to provide a roughly 25% speed improvement. I think I will stick to running my watir-webdriver tests against Firefox unless specifically needed.

Sample Code for Benchmarks

Setting text using Chrome with native events enabled

require 'selenium-webdriver'
require 'watir-webdriver'
require 'bench'

d = Selenium::WebDriver.for :chrome, native_events: true
b = Watir::Browser.new d
b.goto 'bing.com'

benchmark 'set chrome native' do
  b.text_field(name: 'q').set 'ghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghgh'
end

run 10
b.close

Setting text using Chrome with native events disabled

require 'selenium-webdriver'
require 'watir-webdriver'
require 'bench'

b = Watir::Browser.new :chrome
b.goto 'bing.com'

benchmark 'set chrome non-native' do
  b.text_field(name: 'q').set 'ghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghgh'
end

run 10

b.close

Setting text using Firefox (native events aren’t available on OSX)

require 'selenium-webdriver'
require 'watir-webdriver'
require 'bench'

b = Watir::Browser.new :firefox
b.goto 'bing.com'

benchmark 'set firefox' do
  b.text_field(name: 'q').set 'ghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghghgh'
end

run 10

b.close

Configuring Chrome settings when running Watir-Webdriver

I recently found the need to ignore certificate errors when running Watir-Webdriver tests in Google Chrome. The way to do this is slightly different from doing it in Firefox. Unlike Firefox where you create capabilities and profiles, in Google Chrome you pass arguments to Chrome to enable/disable certain browser features.

For example: to ignore certificate errors, disable pop-ups, disable translate and specify a proxy you do:

b = Watir::Browser.new :chrome, :switches => %w[--ignore-certificate-errors --disable-popup-blocking --disable-translate --proxy-server=myproxy.com:8080]

NB: The %W[] converts a long string (separated by spaces) into an array of strings.

The full list of these options is available here. Thanks again to Jari Bakken for pointing me in the right direction.

Telling Watir-Webdriver to use a http and ssl proxy

I’ve been trying to get Watir-WebDriver to use a proxy for both http and https sites, but was having a bit of trouble.
There are a couple of key pointers: you need to specify the proxy address without the ‘http://’ prefix (or it’ll crash), and you need to also specify a :ssl parameter to Firefox profile.

Example: setting a http and https proxy for Firefox

profile = Selenium::WebDriver::Firefox::Profile.new
profile.proxy = Selenium::WebDriver::Proxy.new :http => 'my.proxy.com', :ssl => 'my.proxy.com'
browser = Watir::Browser.new :chrome, :profile => profile

Example: setting a http and https proxy for Chrome

switches = '--proxy-server=my.proxy.com'
browser = Watir::Browser.new :chrome, :switches => switches