0

我是 Selenium RC 的新手,以前使用过 Selenium IDE,并且只在 Firefox 中运行测试。我正在尝试通过 Eclipse 使用 Selenium RC 运行基本测试;我的测试在 Firefox 和 Safari 中运行良好,因为我已经杀死了弹出窗口阻止程序,但 IE8 导致抛出 SeleniumException,其中包含带有 403 响应的“XHR ERROR”:

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)
    ...

我可以在 http://localhost:8080 上进行类似的测试(这里的斜线之间有空格,因为 SO 认为我在发送垃圾邮件),这很好 - 我可以让 IE 打开那个 Tomcat 默认页面并单击一个链接。只有当我尝试在 http://localhost:8080/pims 打开我的应用程序时,我才会看到此错误 - 并且仅在 IE 中。我可以通过在地址栏中键入它在 IE 中打开该 URL。

我确信 IE 中有一些设置导致了这种情况,但我已经尝试了我能想到的一切。http://localhost:8080 在我的受信任站点中,我已将该区域的安全性降至最低,允许任何与弹出窗口相关的内容等。如果我尝试添加 http://localhost:8080/ pims/ 到受信任的站点,IE 说它已经存在。

我也搞乱了代理设置,但无济于事,但可能错过了一些明显的东西。

我尝试使用 *iexplore、*iehta 和 *iexploreproxy 开始测试——它们的行为都相同。

有什么我错过的吗?

作为参考,这是我的测试用例 - 在 Firefox 中,它按原样工作,打开 PIMS 应用程序的索引页面并单击一个链接:

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");
    }
}

任何帮助是极大的赞赏!

4

2 回答 2

1

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.

于 2010-05-14T10:03:30.353 回答
0

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.

于 2010-05-17T15:47:36.780 回答