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

C[omp]ute

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

Choochoo Training Diary

Last 100 entries

Surprise Paradox; [Books] Good Author List; [Computing] Efficient queries with grouping in Postgres; [Computing] Automatic Wake (Linux); [Computing] AWS CDK Aspects in Go; [Bike] Adidas Gravel Shoes; [Computing, Horror] Biological Chips; [Books] Weird Lit Recs; [Covid] Extended SIR Models; [Art] York-based Printmaker; [Physics] Quantum Transitions are not Instantaneous; [Computing] AI and Drum Machines; [Computing] Probabilities, Stopping Times, Martingales; bpftrace Intro Article; [Computing] Starlab Systems - Linux Laptops; [Computing] Extended Berkeley Packet Filter; [Green] Mainspring Linear Generator; Better Approach; Rummikub Solver; Chilean Poetry; Felicitations - Empowerment Grant; [Bike] Fixing Spyre Brakes (That Need Constant Adjustment); [Computing, Music] Raspberry Pi Media (Audio) Streamer; [Computing] Amazing Hack To Embed DSL In Python; [Bike] Ruta Del Condor (El Alfalfal); [Bike] Estimating Power On Climbs; [Computing] Applying Azure B2C Authentication To Function Apps; [Bike] Gearing On The Back Of An Envelope; [Computing] Okular and Postscript in OpenSuse; There's a fix!; [Computing] Fail2Ban on OpenSuse Leap 15.3 (NFTables); [Cycling, Computing] Power Calculation and Brakes; [Hardware, Computing] Amazing Pockit Computer; Bullying; How I Am - 3 Years Post Accident, 8+ Years With MS; [USA Politics] In America's Uncivil War Republicans Are The Aggressors; [Programming] Selenium and Python; Better Walking Data; [Bike] How Fast Before Walking More Efficient Than Cycling?; [COVID] Coronavirus And Cycling; [Programming] Docker on OpenSuse; Cadence v Speed; [Bike] Gearing For Real Cyclists; [Programming] React plotting - visx; [Programming] React Leaflet; AliExpress Independent Sellers; Applebaum - Twilight of Democracy; [Politics] Back + US Elections; [Programming,Exercise] Simple Timer Script; [News] 2019: The year revolt went global; [Politics] The world's most-surveilled cities; [Bike] Hope Freehub; [Restaurant] Mama Chau's (Chinese, Providencia); [Politics] Brexit Podcast; [Diary] Pneumonia; [Politics] Britain's Reichstag Fire moment; install cairo; [Programming] GCC Sanitizer Flags; [GPU, Programming] Per-Thread Program Counters; My Bike Accident - Looking Back One Year; [Python] Geographic heights are incredibly easy!; [Cooking] Cookie Recipe; Efficient, Simple, Directed Maximisation of Noisy Function; And for argparse; Bash Completion in Python; [Computing] Configuring Github Jekyll Locally; [Maths, Link] The Napkin Project; You can Masquerade in Firewalld; [Bike] Servicing Budget (Spring) Forks; [Crypto] CIA Internet Comms Failure; [Python] Cute Rate Limiting API; [Causality] Judea Pearl Lecture; [Security, Computing] Chinese Hardware Hack Of Supermicro Boards; SQLAlchemy Joined Table Inheritance and Delete Cascade; [Translation] The Club; [Computing] Super Potato Bruh; [Computing] Extending Jupyter; Further HRM Details; [Computing, Bike] Activities in ch2; [Books, Link] Modern Japanese Lit; What ended up there; [Link, Book] Logic Book; Update - Garmin Express / Connect; Garmin Forerunner 35 v 230; [Link, Politics, Internet] Government Trolls; [Link, Politics] Why identity politics benefits the right more than the left; SSH Forwarding; A Specification For Repeating Events; A Fight for the Soul of Science; [Science, Book, Link] Lost In Math; OpenSuse Leap 15 Network Fixes; Update; [Book] Galileo's Middle Finger; [Bike] Chinese Carbon Rims; [Bike] Servicing Shimano XT Front Hub HB-M8010; [Bike] Aliexpress Cycling Tops; [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

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

Selenium Tests of Multiple Browser and OS Combinations

From: andrew cooke <andrew@...>

Date: Wed, 11 Aug 2010 16:07:57 -0400

This is a follow-up to my earlier post on Selenium at
http://www.acooke.org/cute/SeleniumWe0.html - there I gave a summary of
Selenium and the basic tools needed to run simple, single tests.

However, what is interesting me at the moment (because we need it at work) is
how to run the same test in several browsers, on different operating systems.
This requires two things:

1 - A way to distribute jobs across machines
2 - A way to make tests general (the tests in the first article specified
    the target browser).

Selenium provides these things via something called "Selenium Grid", although
much of the documentation for that focuses on running tests in parallel (for
speed) rather than on exploiting different environments.

A warning: the Selenium Grid documentation sucks.  I have spent a frustrating
couple of days getting this working.  Even the demo they provide to test the
system doesn't work.  And the system itself seems a bit limited and
unreliable.  But, unfortunately, I don't see anything better.


OK, so what is Selenium Grid?  It's three things:

A - A central hub that manages a collection of servers
B - A collection of servers (possibly on remote machines)
C - Library support for writing tests

(A+B) address (1) above and (C) addresses (2).  This is all packaged in a Java
deploy and run using ant-based scripts.


First, I want to describe how the distribution of tasks works, because I found
this far from intuitive.  It's important to understand that all the servers
(called "remote controls") are equivalent and dumb.  They don't "know" that
they are running on Windows, or can access the Opera browser, for example.
The only way that such information is made available to the system is through
the *environment*.

When you start a server you specify its environment.  This is a string, and
the standard form is something like "IE on Windows" or "Firefox on Linux".
That information is passed by the server to the central hub which uses that
(and only that) to route tests.

The hub is also contacted by the test.  The test requests a particular
environment (I'll address 2/C below) and the hub then routes the test to the
corresponding server.


At this point it's probably worth describing exactly how these things run.
This is how I start the hub and a local server on Linux (first script uses
konsole as they log to stdout - although on Windows you don't see anything,
and I don't understand why):

  > cat startup-selenium.sh
  #!/bin/bash
  konsole --hold -e startup-hub.sh &
  sleep 5
  konsole --hold -e startup-rc.sh &

  > cat startup-hub.sh
  #!/bin/bash
  cd .../selenium-grid-1.0.6/
  ant launch-hub

  > cat startup-rc.sh
  #!/bin/bash
  cd .../selenium-grid-1.0.6/
  ant \
    -Dport=5555 \
    -Dhost=10.2.0.0 \
    -DhubURl=http://10.2.0.0:4444 \
    -Denvironment='Firefox on Linux' \
    launch-remote-control

You can see how the server's environment is defined as 'Firefox on Linux'.
Note also that the server is told the location of the hub so that it can
register itself.  You can see the hub's status by pointing a browser at
/console on the same URL (so http://10.2.0.0:444/console in my example above).


I can then run a test:

  > ant -Dbrowser="Firefox on Linux" run-in-sequence
  Buildfile: build.xml

  run-in-sequence:
       [java] [Parser] Running:
       [java]   Selenium Grid Tests In Sequence
       [java]
       [java] 11-Aug-2010 15:45:52 com.thoughtworks.selenium.grid.tools.ThreadSafeSeleniumSessionStorage startSeleniumSession
       [java] INFO: Contacting Selenium RC at 10.2.0.0:4444
       [java] 11-Aug-2010 15:45:59 com.thoughtworks.selenium.grid.tools.ThreadSafeSeleniumSessionStorage startSeleniumSession
       [java] INFO: Got Selenese session:com.thoughtworks.selenium.DefaultSelenium@...
       [java] 11-Aug-2010 15:46:16 com.thoughtworks.selenium.grid.tools.ThreadSafeSeleniumSessionStorage closeSeleniumSession
       [java] INFO: Closing Selenese session: com.thoughtworks.selenium.DefaultSelenium@...
       [java]
       [java] ===============================================
       [java] Selenium Grid Tests In Sequence
       [java] Total tests run: 1, Failures: 0, Skips: 0
       [java] ===============================================
       [java]

  BUILD SUCCESSFUL
  Total time: 23 seconds

I will explain how tests are written and structured, but first I need to add
one extra point.  There's an additional piece of information needed, which is
the "driver" used to run the tests.  This depends on the browser, and so we
need to map from environment to driver.  This is done in the file
grid_configuration.yaml in the main selenium-grid directory and displayed in
the hub console display.


So far I have addressed my point (1), but haven't really explain how (2) is
solved.  And in truth, I don't completely know - I am simply copying some code
that works.

However, I do know that the documentation is *particularly* poor on this, so
this information is critical.

First, the ant scripts use TestNG to run Java tests.  But the tests generated
by the IDE (export as Java TestNG) seem sot be using an old, unsupported
library.  Do *not* try hunting down the appropriate class and jar
(SeleneseTestNgHelper) because it does not work with the rest of the
(ant-based) environment, as far as I can see.

Instead, copy the supplied code used in the (broken!) tests in the Selenium
Grid package.  In particular, copy GoogleImageTestBase.java and compare ti to
the code generated by the IDE - it's pretty obvious how to do the translation.

Note that the libraries involved do the necessary work of somehow adapting the
tests to use the parameters supplied to any when invoking with a particular
environment.


If you do all that then you will need to link to the following jars:
  commons-logging-1.0.4.jar
  selenium-java-client-driver.jar
  testng-5.7-jdk15.jar
  selenium-server-1.0.3-standalone.jar
  selenium-grid-tools-standalone-1.0.6.jar

You will also need a build.xml that can compile that and run the test.  I
used:

  <project name="..." basedir=".">

    <property name="src.dir"     value="${basedir}/src"/>
    <property name="classes.dir" value="${basedir}/classes"/>
    <property name="lib.dir"     value="${basedir}/lib"/>

    <path id="classpath">
      <fileset dir="${lib.dir}" includes="**/*.jar"/>
      <pathelement path="${classes.dir}"/>
    </path>

    <target name="compile">
      <mkdir dir="${classes.dir}"/>
      <javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath"/>
    </target>

    <property name="webSite" value="http://10.2.0.0:8080/" />
    <property name="seleniumHost" value="10.2.0.0" />
    <property name="seleniumPort" value="4444" />
    <property name="browser" value="*firefox" />

    <target name="run-in-sequence" description="Run Selenium tests one by one">
      <java classpathref="classpath"
            classname="org.testng.TestNG"
                failonerror="true">
            <sysproperty key="java.security.policy" file="${basedir}/lib/testng.policy"/>
            <sysproperty key="webSite" value="${webSite}" /> 
            <sysproperty key="seleniumHost" value="${seleniumHost}" />
            <sysproperty key="seleniumPort" value="${seleniumPort}" /> 
            <sysproperty key="browser" value="${browser}" /> 

        <arg value="-suitename" />
        <arg value="Selenium Grid Tests In Sequence" />
        <arg value="-d" />
        <arg value="${basedir}/target/reports" />
        <arg value="-testclass"/>
        <arg value="MyClass"/>
      </java>
    </target>

  </project>

which is just a simple copy of the one supplied in the grid package.


I hope that helps!

Andrew

Windows etc

From: andrew cooke <andrew@...>

Date: Wed, 11 Aug 2010 16:13:46 -0400

I just realised that the post only describes running on Linux.  In case it's
not obvious, what I also do is:

- start a Windows VM
- install Safari, Google Chrome and Opera
- install Java and ant
- install selenium grid
- start 3 servers with environments "Safari in Windows", "Chrome in
  Windows", and "Opera in Windows"
- modify the hub config so it understands those environments and maps them to
  the correct browsers ("drivers")
- disable pop-up blocking in all (important!)
- then, on Linux I can run the test on these, too (the servers are listed on
  the hib, on Linux)

Andrew

PS Selenium support for Opera appears to be broken at the moment...

Fressia too

From: andrew cooke <andrew@...>

Date: Wed, 11 Aug 2010 17:45:39 -0400

A friend just pointed me at a package called Fressia -
http://fressia.sourceforge.net/ - that another friend wrote (and that I guess
I heard about and then forgot - sorry).  That seems to package Selenium up
into something that you drive via a Python DSL.  It might be a simpler way to
use Selenium and it also appears to be more complete (tests email sending too,
for example).

Andrew

Firefox uses Proxy with Selenium

From: andrew cooke <andrew@...>

Date: Tue, 17 Aug 2010 13:01:37 -0400

If you are testing with Firefox, and it keeps connecting to your web proxy,
even though there is nothing configured in the browser, check your KDE network
settings!  Selenium builds a Firefox profile based on the proxy defined
there... (this has taken me hours to track down!)

Andrew

Regarding Firefox Using Company Proxy Settings

From: "Jeffrey A. Aborot" <image.gif@...>

Date: Tue, 09 Aug 2011 13:28:39 +0800

Hi Andrew,

I am trying out Selenium Grid and got stuck with Selenium Grid's demo 
app not being able to get pass our company's proxy server. I tried 
explicitly coding into the demo app's build.xml our company's proxy 
setting yet still selenium launches firefox, asks for authentication, 
and then does nothing with firefox's page empty. Are you referring to 
the same problem in your post "Firefox uses Proxy"?

Thanks in advance.

jeffrey aborot
newbie tester

Re: Regarding Firefox Using Company Proxy Settings

From: andrew cooke <andrew@...>

Date: Fri, 12 Aug 2011 08:10:12 -0400

Sorry, I completely missed your email (just saw this message when I looked at
my web pages!).

I can't be sure, but it sounds like a similar problem.  I was using a proxy
and had that defined in my KDE settings.  When Firefox started it read those
settings and used them.  Since my test server was local, the proxy couldn't
"see" it and so the Firefox client failed to run tests.

To fix it I cleared the settings from KDE.

Unfortunatley I cannot remmeber any more details.  I hope you aleady fixed
this, or that this is not too late to help....

Andrew

Comment on this post