java - Selenium RC 403 错误 - 禁止代理

标签 java eclipse macos selenium selenium-rc

我正在尝试在 Snow Leopard 上使用 Java 6、JUnit 4 和 Eclipse 运行 Selenium RC 1.0.3。

这是我的测试类,来自 Selenium 文档:

public class TestCase extends SeleneseTestCase {

  @Before
  public void before() throws Exception {
    setUp("http://www.google.com/", "*firefox");
  }

  @Test
  public void test() {
    selenium.open("/");
    selenium.type("q", "selenium rc");
    selenium.click("btnG");
    selenium.waitForPageToLoad("30000");
    assertTrue(selenium.isTextPresent("Advanced search"));
  }
}

我收到以下错误,该错误发生在调用 selenium.open() 时:

11:16:59.916 INFO - Got result: 
XHR ERROR: URL = http://localhost:4444/ Response_Code = 403 
Error_Message = Forbidden+for+Proxy on session a8cf1e0bd5ed42c5a4df0c25ec5f5286

我试过(在网上找到各种建议)用 *chrome*firefox 替换 *firefox,替换 httphttps 并添加 selenium.start(),但没有任何帮助,甚至没有改变行为。

有什么想法吗?

编辑: selenium-server 正在运行,本地防火墙已禁用。

最佳答案

OK,这里有一个解决方案,没有任何理解:如果去掉@Before方法,将对setUp()的调用移到@测试方法,然后就可以了:

@Test
public void test() throws Exception {
  setUp("http://www.google.com/", "*chrome");
  selenium.open("/");
  selenium.type("q", "selenium rc");
  selenium.click("btnG");
  selenium.waitForPageToLoad("30000");
  assertTrue(selenium.isTextPresent("Advanced search"));
}

但这里有一个更好的解决方案,基于理解:

import com.thoughtworks.selenium.SeleneseTestCase;

public class TestCase extends SeleneseTestCase {

  public void setUp() throws Exception {
    setUp("http://www.google.com/", "*firefox");
  }

  public void testAuto() throws Exception {
    selenium.open("/");
    selenium.type("q", "selenium rc");
    selenium.click("btnG");
    selenium.waitForPageToLoad("30000");
    assertTrue(selenium.isTextPresent("Advanced search"));
  }
}

事实证明,SeleneseTestCase 从 JUnit 3 扩展了 TestCase。我已经将文档示例升级到 JUnit 4,而没有考虑可能导致什么问题。

关于java - Selenium RC 403 错误 - 禁止代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2905295/

相关文章:

c - 如何为C配置eclipse?

cocoa - Mac OS X (Cocoa) 应用程序的自动化 UI 测试工具

java - Eclipse 类文件元数据

Java .War 文件删除

java - 单击按钮后如何切换 Activity/布局?

java - 两种变体中列的多对多关系和命名

Eclipse 中的 Android SDK DDMS 无法识别我的 Android 手机

c++ - 如何在 OS X 10.10 上的 Xcode 6 中提供库框架?

python - 如何在 Mac 上的 Python 中使用 CGEventCreateKeyboardEvent?

java - 打印一个正方形三角形。如何镜像数字?