Selenium RC 测试 - IE 在 Tomcat 应用程序上给出 403 错误,Tomcat root 正常

发布于 2024-08-31 18:39:47 字数 1697 浏览 9 评论 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 中。我可以通过在地址栏中输入该 URL 在 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");
    }
}

非常感谢任何帮助!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

雨落□心尘 2024-09-07 18:39:47

这是令人惊讶的,并且有一种“肮脏的黑客”的感觉,但这可能就是答案。

将测试设置为指向 Tomcat 根:

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

并通过 Tomcat 管理器使 Selenium-RC 导航到应用程序,而不是直接打开它。

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

我会继续追求这个,但看起来很有希望。如果有人对为什么这有效有一些见解,我会更有信心这是正确的答案。它也可能因为这个和 IE 自己的安全设置(我整个星期都在搞乱)的某种组合而起作用。

B 计划是从 IE8 退回到 IE7(我正在考虑在 8 中进行更严格的跨域控制),但我希望避免这种情况。

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.

清引 2024-09-07 18:39:47

稍微好一点的解决方案,不涉及登录 Tomcat 管理器:

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

这将打开 Tomcat 根页面,将其整个正文替换为应用程序的链接,然后单击该链接。

它很丑,但很有效。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文