Andrew Cooke | Contents | Latest | RSS | Twitter | Previous | Next


Welcome to my blog, which was once a mailing list of the same name and is still generated by mail. Please reply via the "comment" links.

Always interested in offers/projects/new ideas. Eclectic experience in fields like: numerical computing; Python web; Java enterprise; functional languages; GPGPU; SQL databases; etc. Based in Santiago, Chile; telecommute worldwide. CV; email.

Personal Projects

Lepl parser for Python.

Colorless Green.

Photography around Santiago.

SVG experiment.

Professional Portfolio

Calibration of seismometers.

Data access via web services.

Cache rewrite.

Extending OpenSSH.

C-ORM: docs, API.

Last 100 entries

OpenSuse Leap 15 Network Fixes; Cat Soft LLC - Sell your invoices for immediate revenue that grows with Factoring Quotes's turnover!; Update; Credit Card Processing for Cat Soft LLC; Copier Quotes for Cat Soft LLC; [Book] Galileo's Middle Finger; VOIP quote for Cat Soft LLC; [Bike] Chinese Carbon Rims; Collection Agencies for Cat Soft LLC; Get Coffee Quotes for Cat Soft LLC; [Bike] Servicing Shimano XT Front Hub HB-M8010; [Bike] Aliexpress Cycling Tops; Now Is Cat Soft LLC's Chance To Save Up To 32% On Mail; Call Center Services for Cat Soft LLC; [Computing] Change to ssh handling of multiple identities?; [Bike] Endura Hummvee Lite II; [Computing] Marble Based Logic; [Link, Politics] Sanity Check For Nuclear Launch; [Link, Science] Entropy and Life; [Link, Bike] Cheap Cycling Jerseys; [Link, Music] Music To Steal 2017; [Link, Future] Simulated Brain Drives Robot; [Link, Computing] Learned Index Structures; Solo Air Equalization; Update: Higher Pressures; Psychology; [Bike] Exercise And Fuel; Continental Race King 2.2; Removing Lowers; Mnesiacs; [Maths, Link] Dividing By Zero; [Book, Review] Ray Monk - Ludwig Wittgenstein: The Duty Of Genius; [Link, Bike, Computing] Evolving Lacing Patterns; [Jam] Strawberry and Orange Jam; [Chile, Privacy] Biometric Check During Mail Delivery; [Link, Chile, Spanish] Article on the Chilean Drought; [Bike] Extended Gear Ratios, Shimano XT M8000 (24/36 Chainring); [Link, Politics, USA] The Future Of American Democracy; Mass Hysteria; [Review, Books, Links] Kazuo Ishiguro - Never Let Me Go; [Link, Books] David Mitchell's Favourite Japanese Fiction; [Link, Bike] Rear Suspension Geometry; [Link, Cycling, Art] Strava Artwork; [Link, Computing] Useful gcc flags; [Link] Voynich Manuscript Decoded; [Bike] Notes on Servicing Suspension Forks; [Links, Computing] Snap, Flatpack, Appimage; [Link, Computing] Oracle is leaving Java (to die); [Link, Politics] Cubans + Ultrasonics; [Book, Link] Laurent Binet; VirtualBox; [Book, Link] No One's Ways; [Link] The Biggest Problem For Cyclists Is Bad Driving; [Computing] Doxygen, Sphinx, Breathe; [Admin] Brokw Recent Permalinks; [Bike, Chile] Buying Bearings in Santiago; [Computing, Opensuse] Upgrading to 42.3; [Link, Physics] First Support for a Physics Theory of Life; [Link, Bike] Peruvian Frame Maker; [Link] Awesome Game Theory Tit-For-Tat Thing; [Food, Review] La Fabbrica - Good Italian Food In Santiago; [Link, Programming] MySQL UTF8 Broken; [Link, Books] Latin American Authors; [Link, Computing] Optimizatin Puzzle; [Link, Books, Politics] Orwell Prize; [Link] What the Hell Is Happening With Qatar?; [Link] Deep Learning + Virtual Tensor Machines; [Link] Scaled Composites: Largest Wingspan Ever; [Link] SCP Foundation; [Bike] Lessons From 2 Leading 2 Trailing; [Link] Veg Restaurants in Santiago; [Link] List of Contemporary Latin American Authors; [Bike] FTHR; [Link] Whoa - NSA Reduces Collection (of US Residents); [Link] Red Bull's Breitbart; [Link] Linux Threads; [Link] Punycode; [Link] Bull / Girl Statues on Wall Street; [Link] Beautiful Chair Video; Update: Lower Pressures; [Link] Neat Python Exceptions; [Link] Fix for Windows 10 to Avoid Ads; [Link] Attacks on ZRTP; [Link] UK Jazz Invasion; [Review] Cuba; [Link] Aricle on Gender Reversal of US Presidential Debate; {OpenSuse] Fix for Network Offline in Updater Applet; [Link] Parkinson's Related to Gut Flora; Farellones Bike Park; [Meta] Tags; Update: Second Ride; Schwalbe Thunder Burt 2.1 v Continental X-King 2.4; Mountain Biking in Santiago; Books on Ethics; Security Fail from Command Driven Interface; Everything Old is New Again; Interesting Take on Trump's Lies; Chutney v6; References on Entropy; Amusing "Alexa.." broadcast; The Shame of Chile's Education System

© 2006-2017 Andrew Cooke (site) / post authors (content).

Selenium Web Testing

From: andrew cooke <andrew@...>

Date: Sat, 7 Aug 2010 19:31:39 -0400

I've been looking at Selenium, which is a system for testing web sites.  It's
very easy to use, for simple sites, and works impressively well.  Using a
Firefox plugin you "record" browsing a site and can then repeat that in
"playback mode" as a test.  You can also export the test as Python or Java
unit tests and run those against all the popular browsers on all the popular
operating systems.

That's pretty neat - you could have a bunch of VMs running different operating
systems and browsers, all running against a test web site.  I tested it by
running a Python unit test from Linux that tested Internet Explorer in a
Windows 7 VM.

However, for the particular case I had in mind there are some problems.  In
particular, it's not clear how to handle mixed namespaces (eg SVG is not in
the HTML namespace in the DOM) and, given how the system is implemented (as
Javascript accessing the DOM within the browser being tested) it will not work
with Adobe's SVG plugin on Windows.


The "Selenium IDE" is a Firefox plugin that:
 * Lets you define tests  (and group them in suites)
 * Lets you *run* tests (against Firefox)
 * Lets you save test for future use, or to reun from other languages

So for simple, Firefox only tests, this is a very quick, simple solution.  For
more complex testing it is also a good way of generating tests.

Tests can follow links and do things like verify text (when defining a test,
highlight the text, right click and select the correct option).

A test when saved in the "internal" format is a HTML table of commands.  When
saved as Python file it looks like:

  from selenium import selenium
  import unittest, time, re

  class test(unittest.TestCase):

      def setUp(self):
          self.verificationErrors = []
          self.selenium = selenium("localhost", 4444, "*firefox", 

      def test_selenium(self):
          sel = self.selenium
"link=Show Source")
          try: self.failUnless(sel.is_text_present("Google Code"))
          except AssertionError, e: self.verificationErrors.append(str(e))

      def tearDown(self):
          self.assertEqual([], self.verificationErrors)

  if __name__ == "__main__":

To run that, however, and to test other browsers, you need to install "Selnium
RC".  This is a bundle of packages that includes the server along with support
for various languages.

The server is a Java program that you run as:
  java -jar selenium-server.jar

Then, when you run the Python test...
..the server automatically opens firefox and runs the tests.  It's just like
someone is using your machine!

The only extra detail needed in practice is that "firefox" must be the binary,
not the usual script at /usr/bin/firefox (on Linux).  Otherwise you will see
the error

  Caution: '/usr/bin/firefox': file is a script file, not a real
  executable.  The browser environment is no longer fully under RC control

Since selenium checks for "firefox-bin" before "firefox" the easiest solution
is to:

1 - link firefox-bin to firefox in /usr/lib64/firefox
2 - include /use/lib64/firefox on the path

Then run the server as:

  PATH=$PATH:/usr/lib64/firefox java -jar selenium-server.jar

Note that you need firefox-bin to be in the same directory as firefox or you
will see the error:

  Could not read application.ini

With that fix, the server starts and kils firefox, and tests run repeatedly
(without it, only the first test worked - rerunning it somehoe treated the
website as a binary file).

So, next question - can we do the same on Windows?  I started a VB VM with
Windows 7, containing Java 6 and IE 8.  Downloading Selenium RC (the server)
and starting it, then running the same test (on Linux) but changed to call the
windows server, I got the error:

  Couldn't open app window; is the pop-up blocker enabled?"

Which is described at

The simplest solution is to change the browser type to iexploreproxy.  The
following code, run on Linux, invokes IE on Windows and gives a successful

  from selenium import selenium
  import unittest, time, re

  class test(unittest.TestCase):

      def setUp(self):
          self.verificationErrors = []
          self.selenium = selenium("", 4444, "*iexploreproxy", 

      def test_selenium(self):
          sel = self.selenium
          .... as before

Where is the VM address.

This can be automated further with Selnium Grid, which automatically runs
tests on different machines.

OK, so now to test a web page with SVG.

Hmmm.  Suddenly (well, hours later....) this is not so great.  First, the site
opens new windows on clicks.  These have a "_blank" target.  Selenium has a
command to identify windows by title, but it doesn't work in the IDE (the
Firefox plugin).  After much frustration I found that it *does* work when used
via the server.

Also, because the link is loaded into a new window (ie not the one that
Selenium is watching) the test does not wait for completion.  So a fixed
period wait (30s) needs to be added.

And when I click on a link in the SVG, the selenium IDE records nothing.  I
can add this explicitly to a Python test, but I can't work out what to add.

I have experimented with specifying a namespace in an xpath expresison and
also by using javascript.  Javascript can be tested in the browser address box
(running selenium each time is slow because of waiting for pages) and
unfortunately the code below (and related attempts) does not work.

javascript:alert(function(){var a = document.getElementsByTagName('a');var result = [];for (var i=0; i<a.length; i++) {if (a[i].href == 'some-url-here'){return a[i];}}return null;}())

javascript:alert(function(){var a = document.getElementsByTagNameNS('', 'svg'); return a[0];}())

(Javascript can be specified inside selenium to identify the target - see the
"dom=" protocol in the documentation for the Python library).

Worse, on IE I suspect this would also be broken by the plugin.

So I stalled at this point.  Selenium works surprisingly well (better than I
expected), but does not handle SVG well - there appear to be problems with
namespaces and, likely IE's plugin.


Comment on this post