Skip Links

Blog

Posts tagged with "automation".

Sikuli script - automation by screenshots

Sid

Sid

26 Jan 2010 17:27

We’re fans of Watir which amongst other things we use to automate web browser tests.

It makes automation very easy and you can do a lot with nearly no coding. What coding you do have to do is fairly intuitive.

However, looking at Sikuli it makes Watir look very complicated.

I don’t think it’s going to replace testing, as it’s not obvious that there’s a way of testing the resulting page (unless you can take a screenshot of the whole page?!). Anyway, once I’ve downloaded and tried I’ll post here with results. It seems too good to be true, but we’ll see!

Thanks to Ed who brought this to our attention.

Tagged in: automation, screenshots, sikuli, mit

JRuby, the Betfair API, and Antigua

Sid

Sid

21 Mar 2011 18:43

I’m writing a bot to place bets using Betfair’s API. The smarts about what bets to put on will be provided by bet-guru “Meffa”. The easier bit will be the robot. It’s just a “fun” project (disclosure: secret hope is that will be on a beach in Antigua next year :) but a good opportunity to try something other than Rails-style projects using JRuby.

Betfair provide a full API and more importantly really excellent documentation and a full-featured demo app. Other API providers (and I include ourselves) please note. The API comes in different flavours, but I’m using the Java one which makes web service calls through Apache Axis.

I’m going to chronicle the steps to build our “botfair” bot although I’ll leave out the secret sauce of Meffa’s algorithms otherwise that beach is going to get crowded.

The first step is making a simple API call using from the interactive JRuby prompt.

Ingredients

Logging in and checking markets

Once you’ve extracted the sample application. You’ll need to build it and the WSDL stubs.

We’ll be calling methods from the \betfair-java-sample\src\demo\APIDemo.java class so it’s worth opening up this source file to take a look.

Build the sample and stubs
Before we can do anything we need to compile the classes and regenerate the web services stubs. You’ll need Java 5 for this.

Navigate to the directory and then run ant to build the class files and ant stubs to regenerate the WSDLs.

Set the classpath
You’ll need to make sure that all of the JARs needed by the sample are on your classpath. There are a lot, so I wrote a Ruby script to generate the classpath statement. Run it from the lib file to create you a batch file to do it:

jars=Dir.glob("*.jar")
f=File.new("set-classpath.bat","w")
jars.each do |j|
	f.puts("set CLASSPATH=%CLASSPATH%;c:\\dev\\betfair-java-sample\\lib\\#{j}")
end
f.close

Login and look at markets
In this part we login to Betfair from the interactive JRuby prompt, jirb. You’ll need your Betfair username and password.

1. Start a command prompt in the compiled classes directory (where Ant created your classes).

2. Set the classpath by running the file we generated above. This will make sure that all of the JARs are available (if anyone has a better way of doing this then please let me know!)

3. Type jirb to create a JRuby interactive session and then run each of the commands below separately in the session

require "java"
include_class 'demo.util.APIContext'
include_class 'demo.handler.GlobalAPI'
context=APIContext.new
GlobalAPI.login(context,'your_username','your_password')
types = GlobalAPI.getActiveEventTypes(context)
types.each do |e|
puts e.name
end

What did we do?
The result of all that should have been a list of markets that you can view or bet on using other features of the API.

This isn’t particularly useful as a bot to bet with but does act as a nice proof-of-concept to show that it’s pretty easy to rig up a betfair client using JRuby and Betfair’s API.

Next time …

The next stage will be to poll a particular market (will pick English football whilst the season is still going) and report back on potential opportunities.

Tagged in: jruby, betfair, bots, automation