tags:

views:

9003

answers:

5

I am new to Selenium. I generated my first java selenium test case and it has compiled successfully. But when I run that test I got the following RuntimeException

java.lang.RuntimeException: Could not start Selenium session: Failed to start new browser session: Error while launching browser at com.thoughtworks.selenium.DefaultSelenium.start <DefaultSelenium.java:88>

Kindly tell me how can I fix this error.

This is the java file I want to run.

import com.thoughtworks.selenium.*;

import java.util.regex.Pattern;

import junit.framework.*;

public class orkut extends SeleneseTestCase {

 public void setUp() throws Exception {

  setUp("https://www.google.com/", "*chrome");

 }
 public void testOrkut() throws Exception {

  selenium.setTimeout("10000");

  selenium.open("/accounts/ServiceLogin?service=orkut&hl=en-US&rm=false&continue=http%3A%2F%2Fwww.orkut.com%2FRedirLogin%3Fmsg%3D0&cd=IN&skipvpage=true&sendvemail=false");

  selenium.type("Email", "username");

  selenium.type("Passwd", "password");

  selenium.click("signIn");

  selenium.selectFrame("orkutFrame");

  selenium.click("link=Communities");

  selenium.waitForPageToLoad("10000");

 }

 public static Test suite() {

  return new TestSuite(orkut.class);

 }

 public void tearDown(){

  selenium.stop();

 }

 public static void main(String args[]) {

  junit.textui.TestRunner.run(suite());

 }

}

I first started the selenium server through the command prompt and then execute the above java file through another command prompt.

Second Question: Can I do right click on a specified place on a webpage with selenium.

+2  A: 

If you're using the last version of Selenium RC (after 1.0) you should change the following:

setUp("https://www.google.com/", "*chrome");

for

setUp("https://www.google.com/", "*firefox");

If this doesn't work, try creating a separate firefox profile and using that one:

http://seleniumhq.org/docs/05%5Fselenium%5Frc.html#specifying-the-firefox-profile

Santi
+1  A: 

I know this might sound silly but are you sure you have given selenium.start() in your code? Beginners can make this mistake.

Mugen
I ran into the exact same issue, and adding start() fixed the session problem.
ngeek
A: 

The setUp method basically invokes start method, so don't need to give selenium.start() in above code. I guess this is kind of selenium's bug. it stops testing before it get some response. but I've not found why yet.

Yoonyoul
A: 

(Question not Answer:) I also get the same exception: com.thoughtworks.selenium.SeleniumException: Failed to start new browser session: Error while launching browser

what's weired in my case is that I get it every first time that I try to run Selenium test suite and then on the second time I run it, it succeed. So nothing wrong in my code basically. Still points that might be relevant to the error:
1. I run Selenium on a 64 bit machine and the browser is IE7 64 bit
2. my code is something like:

SeleniumServer seleniumServer = new SeleniumServer();
seleniumServer.start();
Thread.sleep(2000); 
Browser browser = new Browser("localhost", 4444, "*iexplore", "http://localhost:8080");
browser.start();

on runtime the command: browser.start() throw exception after timeout waiting of 30 minutes.

Any idea? Anyone?

Guy
A: 

Always make sure, selenium.stop() method has been called at the end of test steps...

SHANMUGAVEL