开发者

Simple Selenium Test Gives XHR ERROR : 404

I'm using selenium-rc with C# to test my asp.net mvc2 application. Currently all I am doing is opening the home page with selenium RC.

when I run my test I see the selenium remote control open in a browser and I see my application open correctly in a browser but selenium shows a 404 error and aborts the test.

In an attempt to get this working I have cut the test down to a simple console app and have changed the default selenium port here is my code:

static void Main(string[] args)
    {
        try
        {
            var _selenium = new DefaultSelenium("localhost", 1234, "*chrome", "http://localhost:6666");
            _selenium.Start();
            _selenium.Open("/");

            try
            {
                _selenium.Stop();
            }
            catch (Exception)
            {
                // Ignore errors if unable to close the browser
            }

        }
        catch (Exception e)
        {
            Console.WriteLine(e);
        }
        Console.WriteLine("Done.");
        Console.ReadKey();

    }

this fails with the error "XHR ERROR: URL = /localhost:6666/ Response_Code = 404 Error_Message = Not Found on session 5f2e59798ae74e7cb741d50cae7e817a"

and if you look in the running selenium console you see

15:53:16.238 INFO - Allocated session 5f2e59798ae74e7cb741d50cae7e817a for http://localhost:6666, launching...
15:53:16.265 INFO - Preparing Firefox profile...
15:53:18.325 INFO - Launching Firefox...
15:53:20.977 INFO - Got result: OK,5f2e59798ae74e7cb741d50cae7e817a on session 5f2e59798ae74e7cb741d50cae7e817a
15:53:20.980 INFO - Command request: open[/, ] on session 5f2e59798ae74e7cb741d50cae7e817a
15:53:22.654 INFO - Got result: XHR ERROR: URL = http://localhost:6666/ Response_Code = 404 Error_Message = Not Found on session 5f2e59798ae74e7cb741d50cae7e817a

Interesting things that I have tried are:

change the site to "google" - then my test works

change the site to "google" port 80 then it doesnt work.

moved my site from cassini to iis 7 - didnt work

made my site the default site on iis 7 eg http://localhost/ - didnt work

I've used fiddler to watch the session - all requests fired return successfully.

I've tried passing -avoidProxy and -ensureCleanSession when starting the RC server. Hasn't made any noticable difference.

If I reconfigure selenium to use the default port I get the following exception repeated over and over (once every 10 seconds / different sessionid each time). This doesn't happen once I've changed the default port but i've included it just in case.

16:26:38.019 WARN - POST /selenium-server/driver/?seleniumStart=true&localFrameAddress=top&seleniumWindowName=&uniqueId=sel_48694&sessionId=a87b8d6a9e444a5485a5044ef6370e2d&counterToMakeURsUniqueAndSoStopPageCachingInTheBrowser=1286810798016&sequenceNumber=4115 HTTP/1.1
java.lang.RuntimeException: sessionId a87b8d6a9e444a5485a5044ef6370e2d doesn't exist; perhaps this session was already stopped?
    at org.openqa.selenium.server.FrameGroupCommandQueueSet.getQueueSet(FrameGroupCommandQueueSet.java:220)
    at org.openqa.selenium.server.SeleniumDriverResourceHandler.handleBrowserResponse(SeleniumDriverResourceHandler.java:165)
    at org.openqa.selenium.server.SeleniumDriverResourceHandler.handle(SeleniumDriverResourceHandler.java:131)
    at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1530)
    at org.openqa.jetty.http.HttpContext.handle(HttpContext.java:1482)
    at org.openqa.jetty.http.开发者_高级运维HttpServer.service(HttpServer.java:909)
    at org.openqa.jetty.http.HttpConnection.service(HttpConnection.java:820)
    at org.openqa.jetty.http.HttpConnection.handleNext(HttpConnection.java:986)
    at org.openqa.jetty.http.HttpConnection.handle(HttpConnection.java:837)
    at org.openqa.jetty.http.SocketListener.handleConnection(SocketListener.java:245)
    at org.openqa.jetty.util.ThreadedServer.handle(ThreadedServer.java:357)
    at org.openqa.jetty.util.ThreadPool$PoolThread.run(ThreadPool.java:534)

Can anybody shed some light?


I am using C# and had similar problem with selenium.open method. I have refered the thread haroonzone posted in his answer above. and have made following changes in my code

Declare selenium as

private DefaultSelenium selenium;

instead of

private ISelenium selenium;

and call open method as

    selenium.Processor.DoCommand("open", new String[] { YOUR_URL, "true" });

instead of

    selenium.Open("YOUR_URL");

Additionally, you may want to call

selenium.SetTimeout("600000");

before DoCommand


What version of Selenium Server are you using? We get this problem with Selenium Server 2.0a2. It is fixed in later versions of Selenium, so if you download the latest version of the Selenium Server and run this test against it then you wont get the XHR exception. But if you cannot update the selenium version then you can do the following. The code snippet is in Java you can have a similar in C#.

The problem is with the selenium.open method. You can find more information on the following URL. http://code.google.com/p/selenium/issues/detail?id=408

selenium = new DefaultSelenium("localhost", port, browserString, url) {
        public void open(String url) {
            commandProcessor.doCommand("open", new String[] {url,"true"});
        }
    };
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜