views:

698

answers:

3

I'm trying to run Selenium RC 1.0.3 using Java 6, JUnit 4, and Eclipse on Snow Leopard.

Here is my test class, from the Selenium docs:

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

I receive the following error, which occurs at the time that selenium.open() is called:

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

I've tried (finding various suggestions on the web) replacing *firefox with *chrome or *firefox, replacing http with https and adding selenium.start(), but none have helped, or even changed the behavior.

Any ideas?

EDIT: The selenium-server is running, and the local firewall is disabled.

A: 

Hi, Have you started Selenium Server on your local machine?

And where is the code for the setup class?

I has to be running before running any tests.

Cheers, Stefan

StefanE
I've started the selenium server. The setup method (did you mean method?) is inherited from com.thoughtworks.selenium.SeleneseTestCase.
FarmBoy
A: 

What's your network setup like? Is it possible you're running into a corporate firewall issue?

mezmo
+1  A: 

OK, here's a solution, without any understanding: If the @Before method is removed, and the call to setUp() is moved into the @Test method, then it works:

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

But here is a better solution, based on understanding:

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

It turns out that SeleneseTestCase extends TestCase from JUnit 3. I had upgraded the documentation example to JUnit 4 without thinking about what problems may be caused.

FarmBoy
I don't know if it's a cut and paste error or not, but according to the JUnit4 docs, your before method should be static, and after finding the source for SeleneseTestCase, it looks like the setup method is trying to manipulate instance data, which it couldn't get to. Not sure why that isn't throwing an error.
mezmo
If you run your test in TestNG, it doesn't have the same requirements for static methods.
mezmo
Are you thinking of the `@BeforeClass` annotation? Otherwise, give me the link, I use `@Before` for non-static methods frequently.
FarmBoy
You are right, my eyes just kind of skipped over the "non static" on the @Before. Sorry. Are you able to just get right through if just open the URL in the browser otherwise?
mezmo
Yes. I can do that, or use either of the solutions posted here.
FarmBoy