views:

666

answers:

2

I'm new to Selenium RC, having previously used Selenium IDE and only run tests in Firefox. I'm trying to get a basic test to run using Selenium RC through Eclipse; my test works OK in Firefox, and in Safari now that I've killed the pop-up blocker, but IE8 is causing a SeleniumException to be thrown, containing an "XHR ERROR" with a 403 response:

com.thoughtworks.selenium.SeleniumException: XHR ERROR: URL = http://localhost:8080/pims Response_Code = 403 Error_Message = Forbidden
    at com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:97)
    at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:91)
    at com.thoughtworks.selenium.DefaultSelenium.open(DefaultSelenium.java:335)
    at org.pimslims.seleniumtest.FirstTest.testNew(FirstTest.java:32)
    ...

I can do a similar test on http:/ /localhost:8080 (space between the slashes here because SO thinks I'm spamming) and it's fine - I can make IE open that Tomcat default page and click a link. It's only if I try to open my application at http:/ /localhost:8080/pims that I see this error - and only in IE. I can open that URL in IE by typing it into the address bar.

I was convinced that there's some setting in IE that's causing this, but I've tried everything I can think of. http:/ /localhost:8080 is in my Trusted Sites, and I've turned the security for that zone down to the minimum, allowed anything that looks related to popups, etc. If I try adding http:/ /localhost:8080/pims/ to Trusted Sites, IE says it's already there.

I've also messed around with proxy settings, to no avail, but may have missed something obvious.

I've tried starting the test with *iexplore, *iehta, and *iexploreproxy - all behave the same.

Is there something I've missed?

For reference, here is my test case - this works as is, in Firefox, opening the PIMS application's index page and clicking a link:

public class FirstTest extends SeleneseTestCase {
    @Override
    public void setUp() throws Exception {
        this.setUp("http://localhost:8080/", "*firefox");
    }

    public void testNew() throws Exception {
        final Selenium s = this.selenium;
        s.open("/pims");
        s.click("logInOutLink");
        s.waitForPageToLoad("30000");
    }
}

Any help is greatly appreciated!

+1  A: 

This is surprising, and has that "filthy hack" feel to it, but it may just be the answer.

Set the test up to point at Tomcat root:

this.setUp("http://localhost:8080/", "*iexplore");

and make Selenium-RC navigate to the application via Tomcat Manager instead of opening it directly.

/*
 * This works
 */
public void testFromRoot() throws Exception {
    final Selenium s = this.selenium;
    s.open("/");
    s.click("link=Tomcat Manager");
    s.waitForPageToLoad("30000");
    s.click("link=/pims");
    s.waitForPageToLoad("30000");
    s.click("link=User Help");
    s.waitForPageToLoad("30000");
    s.click("logInOutLink");
    s.waitForPageToLoad("30000");
}

/*
 * This doesn't
 */
public void testNew() throws Exception {
    final Selenium s = this.selenium;
    s.open("/pims"); // <<<<<<<<<<<<<< Test fails here with exception, 403 error
    s.click("link=User Help");
    s.waitForPageToLoad("30000");
    s.click("logInOutLink");
    s.waitForPageToLoad("30000");
}

I'll keep pursuing this, but it looks hopeful. If someone has some insight into why this works, I'd feel a whole lot more confident that it's the right answer. It may also be working because of some combination of this and IE's own security settings (which I've been messing with all week).

Plan B is to drop back from IE8 to IE7 (I'm thinking stricter cross-domain controls in 8), but I'm hoping to avoid that.

Ed Daniel
A: 

Slightly better solution, which doesn't involve logging into Tomcat Manager:

s.open("/");
s.getEval("window.document.body.innerHTML='<a href=\"/pims\">Link to PIMS<\\/a>'");
s.click("link=Link to PIMS");

This opens the Tomcat root page, replaces its entire body with a link to the application, and clicks that link.

It's ugly, but it works.

Ed Daniel