Browser not launching in TestNG scirpt.

61 views
Skip to first unread message

Black Swan

unread,
Dec 29, 2011, 11:21:55 AM12/29/11
to seleniu...@googlegroups.com

Hi All,

I am playing around with TetsNG, and have written the following simple script, the script seems to be fine but its not launching the browser. I have added firefox.exe to the classpath and have also tried with absolute path of the browser as well but of no use. Can anyone please point out what's wrong.

And as Mark mentioned in an another mail chain that SeleneseTestCase is deprecated, so I am using SeleneseTestBase.

CODE:

package tests;


import org.openqa.selenium.server.SeleniumServer;
import org.testng.annotations.Test;

import com.thoughtworks.selenium.SeleneseTestBase;

public class SampleTest extends SeleneseTestBase {
 
    @Test
    public void f() throws Exception{

        SeleniumServer server = new SeleniumServer();
        server.boot();
        server.start();
        setUp("www.quikr.com","*firefox");
        selenium.open("/");
        selenium.setSpeed("2000");
        selenium.type("id=query", "abc");
        selenium.select("id=categoryId", "Pune");
  }
}

ERROR MESSAGES:
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:89)
    at com.thoughtworks.selenium.SeleneseTestBase.setUp(SeleneseTestBase.java:123)
    at com.thoughtworks.selenium.SeleneseTestBase.setUp(SeleneseTestBase.java:104)
    at tests.SampleTest.f(SampleTest.java:16)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:691)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:883)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1208)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
    at org.testng.TestRunner.privateRun(TestRunner.java:758)
    at org.testng.TestRunner.run(TestRunner.java:613)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
    at org.testng.SuiteRunner.run(SuiteRunner.java:240)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:87)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1142)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1067)
    at org.testng.TestNG.run(TestNG.java:979)
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:109)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:202)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:173)
Caused by: com.thoughtworks.selenium.SeleniumException: Failed to start new browser session: Error while launching browser
    at com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:97)
    at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:91)
    at com.thoughtworks.selenium.HttpCommandProcessor.getString(HttpCommandProcessor.java:262)
    at com.thoughtworks.selenium.HttpCommandProcessor.start(HttpCommandProcessor.java:223)
    at com.thoughtworks.selenium.DefaultSelenium.start(DefaultSelenium.java:81)
    ... 27 more

Mike Riley

unread,
Dec 29, 2011, 12:17:45 PM12/29/11
to Selenium Users
First, your stack shows that TestNG *is* launching your test code. It
is in your test code that you are getting the error of trying to start
the browser. Specifically it is on line 16 in your code, which
appears to be you call to setUp.

A couple of questions come to mind:

1) Why are you starting a server in your code? This will greatly slow
down your test, as you need to wait for the server to start up, and
you do not need a server to run a simple test. Just using the client
library will start the browser for you. You only need a server to
handle multiple tests running at the same time from different
programs.

2) Was this test code produced by one of the IDE output filters? If
so which one, so I know to avoid it in the future? ;)

If you really wish to use a server then have it started and running
already prior to running your test code. If you need a server on more
than one system look into using Grid2 to manage jobs for those
servers.

Mike

On Dec 29, 8:21 am, Black Swan <blackswan.co...@gmail.com> wrote:
> Hi All,
>
> I am playing around with TetsNG, and have written the following simple
> script, the script seems to be fine but its not launching the browser. I
> have added firefox.exe to the classpath and have also tried with absolute
> path of the browser as well but of no use. Can anyone please point out
> what's wrong.
>
> And as Mark mentioned in an another mail chain that SeleneseTestCase is
> deprecated, so I am using SeleneseTestBase.*
>
> CODE:*
> package tests;
>
> import org.openqa.selenium.server.SeleniumServer;
> import org.testng.annotations.Test;
>
> import com.thoughtworks.selenium.SeleneseTestBase;
>
> public class SampleTest extends SeleneseTestBase {
>
>     @Test
>     public void f() throws Exception{
>
>         SeleniumServer server = new SeleniumServer();
>         server.boot();
>         server.start();
>         setUp("www.quikr.com","*firefox");
>         selenium.open("/");
>         selenium.setSpeed("2000");
>         selenium.type("id=query", "abc");
>         selenium.select("id=categoryId", "Pune");
>   }
>
> }
>
> *ERROR MESSAGES:*

Frank Escobar

unread,
Dec 29, 2011, 12:30:07 PM12/29/11
to seleniu...@googlegroups.com
You have to user SELENIUM GRID, because you don't have the server connected:

Download "selenium-grid-1.0.8"

Unzip the file & open console (CMD), go to the directory of "selenium-grid-1.0.8" and enter:
ant launch-hub
After open other console and write:
ant launch-remote-control
More info:

Also you must send parameters with a file xml of testng


On Thu, Dec 29, 2011 at 1:21 PM, Black Swan <blacksw...@gmail.com> wrote:

Hi All,

I am playing around with TetsNG, and have written the following simple script, the script seems to be fine but its not launching the browser. I have added firefox.exe to the classpath and have also tried with absolute path of the browser as well but of no use. Can anyone please point out what's wrong.

And as Mark mentioned in an another mail chain that SeleneseTestCase is deprecated, so I am using SeleneseTestBase.

CODE:

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.

package tests;



--

Frank Escobar | QA Analyst | GlobalLogic Inc. 
Leaders in Software R&D Services
ARGENTINA | CHILE  |  CHINA | INDIA | ISRAEL | UKRAINE | UK | USA
485 Av Corrientes, 6th floor - Bs. As.
Home: +54-261-4290866 
| Cellphone: +54-9-261-5548041 | Office: +54-11-4394-3121  ext. (nº411) Skype Name: fescobar.systems | Professional Profile: http://ar.linkedin.com/in/fescobarsystems | Blog: blogs.globallogic.com

www.globallogic.com  

Disclaimer: http://www.globallogic.com/email_disclaimer.txt


Frank Escobar

unread,
Dec 29, 2011, 12:31:57 PM12/29/11
to seleniu...@googlegroups.com

Jayakumar C

unread,
Dec 29, 2011, 12:37:46 PM12/29/11
to seleniu...@googlegroups.com
Pass the url with prefix 'http://'. So the url would be "http://www.quikr.com".

Also no need of calling both boot() and start(). Call boot() alone to start the Se-RC server(with configurations if any).

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.



--
Jayakumar

tulsi.tester

unread,
Dec 30, 2011, 12:11:50 AM12/30/11
to Selenium Users
Hi Black Swan,

Try the following code to start your selenium server. For this first
you need to create a selenium server as a batch file.

To create selenium server as a batch file.
1. Open notepad
2. Type the following in the opened notepad

D:
cd Selenium\
java -jar selenium-server-standalone-2.14.0.jar (Here D is my local
drive where my selenium-server-standalone-2.14.0.jar file sits.).

3. Save the notepad file as .bat file on desktop (preferred).
4. Before running your scripts you need to start this batch file.

package firstPackage;

import org.testng.annotations.BeforeClass;
import org.testng.annotations.AfterClass;

import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.SeleneseTestBase;
import com.thoughtworks.selenium.Selenium;

public class FirstClass extends SeleneseTestBase {

protected Selenium selenium ;

@BeforeClass
public void StartServer()
{

selenium = new DefaultSelenium("localhost",4444,"*firefox","http://
www.quikr.com");
selenium.start();

try{
selenium.open("http://www.quikr.com");
selenium.waitForPageToLoad("400000");
}catch(Exception e){}

}

@AfterClass(alwaysRun=true)
public void StopServer()
{
selenium.close();
selenium.stop();
}
}




On Dec 29, 9:21 pm, Black Swan <blackswan.co...@gmail.com> wrote:
> Hi All,
>
> I am playing around with TetsNG, and have written the following simple
> script, the script seems to be fine but its not launching the browser. I
> have added firefox.exe to the classpath and have also tried with absolute
> path of the browser as well but of no use. Can anyone please point out
> what's wrong.
>
> And as Mark mentioned in an another mail chain that SeleneseTestCase is
> deprecated, so I am using SeleneseTestBase.*
>
> CODE:*
> package tests;
>
> import org.openqa.selenium.server.SeleniumServer;
> import org.testng.annotations.Test;
>
> import com.thoughtworks.selenium.SeleneseTestBase;
>
> public class SampleTest extends SeleneseTestBase {
>
>     @Test
>     public void f() throws Exception{
>
>         SeleniumServer server = new SeleniumServer();
>         server.boot();
>         server.start();
>         setUp("www.quikr.com","*firefox");
>         selenium.open("/");
>         selenium.setSpeed("2000");
>         selenium.type("id=query", "abc");
>         selenium.select("id=categoryId", "Pune");
>   }
>
> }
>
> *ERROR MESSAGES:*
Reply all
Reply to author
Forward
0 new messages