Issue #8 resolved

Google App Engine Go Compatibility

bthomson
created an issue

Hello again,

I have gotten this package working with Google App Engine Go and wanted to share my results.

Basically for App Engine you have to be able to modify the http.Client periodically. The docs for urlfetch package explain a little bit of it.

In the selenium package var httpClient *http.Client is defined in remote.go. The easiest way for me to make it work was to export httpClient, ie change it from httpClient to HttpClient everywhere. That is the only change needed to the selenium package.

Now in our App Engine App code we are allowed to modify the HttpClient in selenium package with something like this:

func myRequestHandler(w http.ResponseWriter, r *http.Request) {
    selenium.HttpClient.Transport = &urlfetch.Transport{
        Context:  appengine.NewContext(r),
        Deadline: 30 * time.Second,
    }
    ...
}

It's important to increase the deadline, since the 5 second default probably isn't long enough!

However that is not enough, I also ran into another problem. On my local machine I use a URL like "http://user:key@ondemand.saucelabs.com/wd/hub" as an executor. But it does not work in App Engine for some reason. Instead we have to use SetBasicAuth on the request. This can be fixed outside of selenium package with another http.Transport wrapper:

type Transport struct {
    urt *urlfetch.Transport
}

func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error) {
    req.SetBasicAuth("myuser", "mykey")
    return t.urt.RoundTrip(req)
}

And then the request handler code from above changes slightly:

func myRequestHandler(w http.ResponseWriter, r *http.Request) {
    selenium.HttpClient.Transport = &Transport{&urlfetch.Transport{
        Context:  appengine.NewContext(r),
        Deadline: 30 * time.Second,
    }}
}

Anyway I don't know if you want to make any changes to the package for this, but I wanted to at least share this info here in case someone else wants to use it on App Engine in the future.

Cheers,

Brandon

Comments (3)

  1. Log in to comment