Automating SignalR applications with Selenium WebDriver

Last Updated on by

Post summary: This post is about an “No response from server for url” issue during automation of web application using SignalR with Selenium WebDriver. Issue was resolved by configuring application to connect to server through WebSocket protocol.

I had to automate with Selenium WebDriver (version 2.43) a single page web application which was build with SignalR. First thing to do when you start an automation is to automate a smoke test scenario. So did I. It run fine on Internet Explorer (version 11) and Chrome (version 37). I was happy and confident I’m going to finish this project on time. The happy face was dramatically changed when I run the suite on Firefox (version 33). The driver timed out with “No response from server for url” issue. I searched the net for similar problems with no luck. I couldn’t find an end-to-end solution on issues with SignalR automation so I prepared this post.

About SignalR

ASP.NET SignalR is a library for building “real-time” applications that enables server to push events to client instead on relying client to request data from server. Once application is started SignalR client tries to connect to server with transport protocols in order shown in the list: WebSocket, Server-sent events, Forever Frame (IE only) and finally Ajax long polling.

My application was forced to connect to server with Long Polling transport (later on I discovered this was caused by a bug in application’s connection logic). Client (browser) opens connection to server. Server keeps this connection open for relatively long time (2 minutes in my case). Seems like this open connection is confusing Selenium and it doesn’t actually know when browser is ready. “Unstable” page loading strategy did not worked out:

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("webdriver.load.strategy", "unstable");
WebDriver driver = new FirefoxDriver(profile);

The only solution to make Selenium working with SignalR in all three browsers was to make application under test working with WebSocket transport protocol.

It is also beneficial for application itself to work with WebSockets. There are several SignalR prerequisites in order to use it with WebSockets: IIS 8 or IIS 8 Express with enabled WebSockets. In order to get enabled Web Sockets are installed additionally to IIS as a Windows feature.