我正在尝试在 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
,替换 http
与 https
并添加 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/