簡體   English   中英

Selenium RC 403錯誤 - 禁止代理

[英]Selenium RC 403 Error - Forbidden for proxy

我正在嘗試在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

我已嘗試(在網上找到各種建議)用*firefox *chrome*firefox替換*firefox ,用https替換http並添加selenium.start() ,但沒有人幫助,甚至改變了行為。

有任何想法嗎?

編輯: selenium-server正在運行,本地防火牆已禁用。

好的,這是一個解決方案,沒有任何理解:如果@Before方法被刪除,並且對setUp()的調用被移入@Test方法,那么它的工作原理如下:

@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,而沒有考慮可能導致的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM