jump to navigation

Setting up Selenium RC & TestNG using Eclipse November 26, 2008

Posted by epyramid in selenium.
Tags: , ,
trackback

I found that it is not easy for the beginners to setup Selenium RC and run the GoogleTest.java example after downloading it from www.openqa.org . The purpose of this post is to help beginners (new users to Selenium RC) help setting up Selenium RC with TestNG using Eclipse.

This assumes that you have done the following steps.

Download and install Eclipse (www.eclipse.org)

Download the latest TestNG (www.testng.org)

Download Selenium RC (www.openqa.org)

Install TestNG plugin for eclipse

(http://testng.org/doc/download.html)

Please follow the step by step instructions to setup the test environment.

Launch Eclipse, you can setup any directory as your default workspace. For this example, my default workspace is as shown below.

001

Click OK, Eclipse will be launched.

Click File > New

002

Set the project name as Google.

0032

Click Next.

On the Source tab leave the default.

Click on Libraries.

Click on Add External Jars

Add the jar files for TestNG and Selenium RC Java client as shown below.

0042

Click Finish, now you will have a Java project created in Eclipse that is correctly set to use Selenium Client and TestNG jar files.

Now Right Click on the src > New > Class

005 

Name the class file as GoogleTest and Click Finish.

Now create a testng test within GoogleTest class as follows.

006

 

The next step is to run the Selenium Server as

007

Now Right Click on the test and run this as TestNG test.

008

The test will be successful.

009

Comments»

1. Suresh Kanukonala - February 12, 2009

Hi,
I gave done all the steps mentioned above.
But i am getting the warning message at org.testng.annotations.*;
and the warning message “The org.testng.annotations is never used is displaying.
Please help me in resolving this issue..

Thanks,
Suresh

epyramid - February 12, 2009

The warning messages will not effect the test execution. But it is a good approach to remove the unused import statements. Try to run the test and let me know if you get any error.

epyramid - July 27, 2009

There are many ways to run the test using the command line.

1. Use ANT and define a task to run the tests using TestNG.
2. Use Maven to run the tests and surefire plugin to collate the test results.
You can find more information on the following URL
http://testng.org/doc/documentation-main.html#running-testng

2. Suresh Kanukonala - February 13, 2009

thanks for ur reply..
here i am not getting the option to run the test as Testng as given in the screen shot above..
Please find the test and the erroer below..
TEST :

import com.thoughtworks.selenium.*;
import org.testng.annotations.*;
import static org.testng.Assert.*;
public class GoogleTest
{
public Selenium selenium;
public void setup()
{
selenium = new DefaultSelenium(“localhost”, 4444, “*firefox”,”http://yahoo.com”);
selenium.start();
}
public void search()
{
selenium.open(“http://www.Google.com/”);
assertEquals(“Google”, selenium.getTitle());
selenium.type(“q”, “Selenium OpenQA”);
assertEquals(“Selenium OpenQA”, selenium.getValue(“q”));
selenium.click(“btng”);
selenium.waitForPageToLoad(“50000″);
}
public void StopTest()
{
selenium.stop();
}
public static void main(String arg[])
{
GoogleTest g = new GoogleTest();
g.setup();
g.search();
g.StopTest();
}
}

Error :-
Exception in thread “main” com.thoughtworks.selenium.SeleniumException: Permission denied to get property Location.href
at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:73)
at com.thoughtworks.selenium.DefaultSelenium.open(DefaultSelenium.java:234)
at GoogleTest.search(GoogleTest.java:14)
at GoogleTest.main(GoogleTest.java:29)

3. epyramid - February 13, 2009

Eclipse will not give you the option to run the class as TestNG test because it does not recognise the class as TestNG test class.

Another thing that you need to check is whether you have TestNG plugin installed for your Eclipse. You can check this by going to the Run > Open Run Dialog
and you should have TestNG listed there.

Now coming back to the class, you need to specify the TestNG annotations for your test methods so that TestNG can identify the test methods and can execute them. Look at the image just after this line in the post.

“Now create a testng test within GoogleTest class as follows”.

You will notice that there is no main method and the methods are annotated as @Test @BeforeClass and @AfterClass. These annotations tell TestNG that these methods are test methods. Please refer to the TestNG documentation for the details on these annotations.

I hope this helps.

Thanks
Haroon

4. Eftikasa Blog - February 19, 2009

very goooood

thanks

:)

epyramid - February 19, 2009

you are welcome.

5. mustafa - February 22, 2009

I follow your steps but I copuldn’t get it to work, I do run testNG with watij, I have no problem there. but I could not get the seesion to start.

java.lang.RuntimeException: Could not start Selenium session:

epyramid - February 22, 2009

Did you start the Selenium Server?

> java -jar selenium-server.jar

I see this problem when the selenium server is not started.

6. Chetan - February 24, 2009

I have little experience in Selenium, I am using RC(Java)+TestNG+Ant+Eclipse setup, My problem at debugging, in my setup I am not able to debug in eclipse, its not recognizing.

epyramid - February 24, 2009

Chetan, can you please explain what it is not recognizing???

You should have TestNG eclipse plug-in installed for debugging.

You also need to ensure that you configure the TestNG plug-in to access the parameters you pass from the ANT if you pass any. Because sometime people define parameters in the ANT file that are fed into the TestNG tests and if you run the test from Eclipse it would not find the parameters that are define in the build.xml file therefore you need to define the run-time arguments otherwise you will get failures.

7. pradeep - February 25, 2009

hey haroon,
I just got a problem.
Theres no open run dialog button in my eclipse and i’m unable to run the sample code give by you.
can u please help me out

8. pradeep - February 25, 2009

hey i got it
i installed the plugin again and i can run the test

thnk u

9. Amar - March 16, 2009

Hi epyramid,

I am using ur steps and I am able to run the tests. but it is saying 0 tests ran, 0 pass and 0 failed.

Can you please let me know what I am doing wrong?

Thanks,
Amar

epyramid - March 19, 2009

Did you specify the @Test at the top of your test method definition???

10. Pallavi - March 18, 2009

Hi – You have got a very good blog for the beginers like me.. Thank You. I have followed all the instructions but seems like my test is not executing – it shows something like this – is this some set up issue? Please hel. Thanks

java.lang.UnsupportedClassVersionError: Bad version number in .class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.testng.internal.ClassHelper.forName(ClassHelper.java:74)
at org.testng.xml.XmlClass.getSupportClass(XmlClass.java:52)
at org.testng.internal.Utils.xmlClassesToClasses(Utils.java:76)
at org.testng.TestRunner.initMethods(TestRunner.java:281)
at org.testng.TestRunner.init(TestRunner.java:227)
at org.testng.TestRunner.init(TestRunner.java:189)
at org.testng.TestRunner.(TestRunner.java:150)
at org.testng.remote.RemoteTestNG$1.newTestRunner(RemoteTestNG.java:102)
at org.testng.remote.RemoteTestNG$DelegatingTestRunnerFactory.newTestRunner(RemoteTestNG.java:154)
===============================================
First
Total tests run: 0, Failures: 0, Skips: 0
===============================================

epyramid - March 19, 2009

There is something wrong with your JDK installation, try installing the JDK again.

11. Miles Parker - April 3, 2009

Hi Harron,

Nice tutorial. One nit.. you’ve added both of your dependent jars as external jars.

I think its a much better idea to create a lib dir in the project and/or a project your project is dependent upon. This way the project will actually be portable is someone wants to use it on a different machine. The solution works, but I think its good to get newbies started on the right road, especially if they are at the stage of wanting to do unit testing.

Miles

epyramid - April 3, 2009

Hi Miles,

I agree with you and wanted to do some follow ups to this on the topics on setting up selenium projects with different tools e.g. ANT, MAVEN, JUnit, Fitnesse
I have plans for this so lets see how this goes. Time is an issue these days.

12. Miles Parker - April 3, 2009

Yeah, tell me about it. :) I’m actually not sure why TestNG doesn’t offer a library ala JUnit or at least a plugin for the testng classes themselves. Its annoying to have to copy it into every project.

13. omsis - April 18, 2009

Hi,

I am facing problem in installing the testng in eclipse. Can you please gide me how to instal testNG plugin to eclipse step by step

epyramid - April 18, 2009

The process of installing TestNG eclipse plugin is very simple. You can follow the instruction on the following URL.
http://testng.org/doc/download.html

If it does not help, then please let me know. Are you getting any error during installation???

Haroon

14. omsis - April 22, 2009

Hi,

Thanks. Its a nice post and very helpfull.

I am able to do it successfully and also able to execute the program by followng the steps which is given here.

I am facing one more problem with handling the pop-ups. when I am downloading some files from my application one pop-up coming, having open,save,cancel button. When I will click on the save button it should save the file to the disk, But that clik is not recording in the selenium IDE. How to do it in selenium RC. I need your help.

epyramid - April 24, 2009
15. Aditya Tandon - May 27, 2009

Hi Mate

It is working for me exactly as it should be thanks for this tutorial however i am wondering .with one point here

I have installed TESTNG and i can see it being installed as well and it is there in Run Dialog box however when i click on run as option it provide me the option of running the test as TESTNG .. I always have to run the application as JAVA APPLICATION ,,
Anyclues for this issue , why this is happening

epyramid - May 27, 2009

I would suggest you to create a run configuration and then try running the tests. If you are using Eclipse then do the following.

Click Run > Run Configurations
Select TestNG and configure the configuration for your test. Once you do that you should be able to run the tests by right click on the test file and then select TestNG.

16. Adriel - June 4, 2009

Hello.

When I run the test I am getting the error:

java.lang.runtimeexception: Firefox 3 could not be found in the path!
Please add the directory containing ”firefox.exe” to your PATH environment variable, or explicitly specify a path to Firefox 3 like this: *firefox3c:\blah\firefox.exe

I found one place that said to fix this error I need to:
“make sure that firefox is installed and firefox-bin exists in the path. ”
Firefox is installed but what path are they referring to? I’m lost.

Thanks!

epyramid - June 4, 2009

check your Path environment variable. Adding Firefox to your path variable would fix the problem. At the moment selenium is not able to find the firefox.exe to launch the browser.

What operating system you are using??? PATH environment variable is different in different operating systems. In case of windows you can follow the steps below.

Right Click on My Computer > Properties > Advanced Properties > Environment Variables

Under variables you can find the PATH environment variable.

17. Adriel - June 4, 2009

I’m using vista 64 bit. I have found it and have added the following text in the variable value text box:

C:\Program Files (x86)\Mozilla Firefox\;

I then closed pressed ok and re-ran but to no avail. It still gives me the same error.

18. Adriel - June 4, 2009

Never mind. I restarted eclipse and it worked. Thanks for the help.

epyramid - June 5, 2009

Glad to hear that.

19. mala - June 5, 2009

Hi,

I have set up my environment as suggested. I recorded steps in my browser using selenium ide, exported it to java and running it in a project in eclipse. My web page has a popup calendar box. I am able to have it opened. I then use the code to click on one of the dates.
selenium.click(“link=28″);

It does select the date on the page but I get a time out. This is the error:
Got result: Timed out after 30000ms on session

Thanks for your help.

epyramid - June 6, 2009

This error appears when Selenium is waiting for a page to load event and the event is not there. What happens when you click the link 28 on the calendar popup? does that generate a new page load or just select the date and populate the date in an edit field.

If there is page load then the next statement should be waitForPageToLoad and if not then this should not be there.

The error is not on selenium.click but the statement after this is causing the test to fail.

20. mala - June 8, 2009

Thanks for your reply.

When I click on 28, it populates the date in the edit field. The error I am getting is:
Got result: Timed out after 30000ms on session 5dc9bf70267b496883eb070384ff34ae

I get this even after adding the waitForPageToLoad for 30000 ms. I increased the number to 60000 and 90000 and am still getting the error.

Thanks again.

epyramid - June 8, 2009

I have a question about the behavior of the application. Does clicking on 28 also generates a new page load statement?? if it does not then you do not need waitForPageToLoad and if it does then you need waitForPageToLoad.

What should application do when you click on 28 and insert the date in the edit field, what is the next step????

21. mala - June 8, 2009

When I click on 28, it does not generate a new page load. You are correct, I do not need it. It is using an Ajax call.
The next step(s) are to fill out the rest of the input fields including drop downs and then submit the form.

epyramid - June 9, 2009

Selenium does not have any built-in method for AJAX calls, therefore you have to synchronize your test script with you application with other visual cues, such as an expected element state based on the AJAX call and use isElementPresent or isVisible if AJAX call makes any change to the UI and if it does not then you can always use Thread.sleep (milliseconds) and milliseconds should be the time the test wait for the AJAX call to be complete.

22. Simon - July 7, 2009

Very nice, it works perfectly!

23. Roney - July 10, 2009

hi,

i added testng plugin in the buld path of my project in Eclipse 3.4.2. But i am not able to get the testng in Open Run Dialog. Only JUnit is there .

Help me out …

epyramid - July 10, 2009

I am using TestNG with Eclipse 3.4.2 with no problem. Did you restart the eclipse after installation???

Roney - July 10, 2009

Yes i had restarted the Eclipse still i m not able to get it, the plugin which i use for TestNG is the one which available alongwith Selenium

24. Roney - July 10, 2009

Hi,

I also need help in
> how to create testcase report (in case of a single testcase)
> how to create testcase report (in case of multiple test cases available)
> how to run testcases in test Suite

Please help me out . Thanks in Advance.

epyramid - July 10, 2009

TestNG generates reports in different formats, it all depends on your choice as how to run the tests. You can run the tests using Maven, ANT or any TestNG IDE Plugin .

Roney - July 10, 2009

Is it possible to execute the testcases in Standalone, i mean without the help of any IDE’s only with Selenium Server running behind. And can u recommend me some sites or docs which help me in clearing the above doubt relate to testcase report and test suite creation

25. Roney - July 10, 2009

Inside this folder
C:\selenium-grid-1.0.3-bin\selenium-grid-1.0.3\vendor\testng-5.7-jdk15.jar

I have used this jar in Eclipse

epyramid - July 10, 2009

adding a jar does not gurantee a plugin in Eclipse. Please follow the instruction on the following the instructions below to install TestNG plugin for Eclipse.

For the Eclipse plug-in, we suggest using the update site:

– Select* Help / Software updates / Find and Install.* – *Search for new features to install.* – *New remote site.* – Enter http://beust.com/eclipse in the URL and whatever description you want. – Make sure the check box next to http://beust.com/eclipse is checked and click *Next*. – Eclipse will then guide you through the process.

26. Deepa V - July 13, 2009

Hi

I need a help for verifying the popuptext that present in a popup window in selenium script.That popup window contains yes/no button and the text label.
Do you want to delete the selected ActivityType?

epyramid - July 14, 2009

Use getAlert method that retrieves the message of a JavaScript alert generated during the previous action, or fail if there were no alerts.

http://release.seleniumhq.org/selenium-remote-control/1.0-beta-2/doc/java/com/thoughtworks/selenium/Selenium.html

27. Huy Nguyen - July 15, 2009

I can run it properly, but after running completed, I opened TestNG tab and it showed “Failed: 1″. Here are the error:

Failure Exception:
java.lang.IllegalMonitorStateException
at java.lang.Object.wait(Native Method)
at GoogleTest.googleSearch(GoogleTest.java:25)
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.MethodHelper.invokeMethod(MethodHelper.java:607)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:517)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:669)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:956)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:126)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:110)
at org.testng.TestRunner.runWorkers(TestRunner.java:759)
at org.testng.TestRunner.privateRun(TestRunner.java:592)
at org.testng.TestRunner.run(TestRunner.java:486)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:332)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:327)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:299)
at org.testng.SuiteRunner.run(SuiteRunner.java:204)
at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:877)
at org.testng.TestNG.runSuitesLocally(TestNG.java:842)
at org.testng.TestNG.run(TestNG.java:751)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:73)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:124)

Can you explain or help me to fix it.
Thank you

epyramid - July 15, 2009

Close Eclipse and run the test again.

28. Huy Nguyen - July 16, 2009

Hi epyramid,
After restart Eclipse, I can run this testcase with “Green” color without any errors.
Thank you a lot :)

29. sanjeev - July 17, 2009

Hi..

Here is my code:

package com.testscripts;
import com.thoughtworks.selenium.*;
import org.testng.annotations.*;
import static org.testng.Assert.*;

public class GoogleTest {
private Selenium selenium;
@BeforeClass
public void setup() {
selenium =new DefaultSelenium(“localhost”, 4444, “*firefox”, “http://www.google.com”);
selenium.start();
}

@Test
public void GoogleSearch() {
selenium.open(“http://www.google.com”);
}

@AfterClass
public void tearDown() {
selenium.stop();
}
}

This script is running successfully with the IE. but im getting the following error while running with the Firefox. Could you help me with this..

[Parser] Running:
C:\Documents and Settings\nsanjeev\workspace\Webmail_NG\temp-testng-customsuite.xml

FAILED: GoogleSearch
com.thoughtworks.selenium.SeleniumException: Timed out after 30000ms
at com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:97)
at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:91)
at com.thoughtworks.selenium.DefaultSelenium.open(DefaultSelenium.java:335)
at com.testscripts.GoogleTest.GoogleSearch(GoogleTest.java:16)
… Removed 22 stack frames

===============================================
com.testscripts.GoogleTest
Tests run: 1, Failures: 1, Skips: 0
===============================================

Thanks in Advacne,
Sanjeev

epyramid - July 20, 2009

@Test
public void GoogleSearch() {
selenium.open(”/”);
selenium.waitForPageToLoad(“30000″);
}

It is a good practice to have a wait for page to load statement after open() function call so selenium does not time out.

30. piripi - July 17, 2009

Hi epyramid,
I have set up my environment as suggested.I copied the script in your screenshot and runned it in a project in eclipse. Selenium server is up, but when I rut it as a TestNG test, i get the error:

java.lang.NullPointerException
at GoogleTest.GoogleSearch(GoogleTest.java:18)
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.MethodHelper.invokeMethod(MethodHelper.java:580)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:478)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:617)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:885)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:126)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:110)
at org.testng.TestRunner.runWorkers(TestRunner.java:712)
at org.testng.TestRunner.privateRun(TestRunner.java:582)
at org.testng.TestRunner.run(TestRunner.java:477)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:324)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:319)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:292)
at org.testng.SuiteRunner.run(SuiteRunner.java:198)
at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:823)
at org.testng.TestNG.runSuitesLocally(TestNG.java:790)
at org.testng.TestNG.run(TestNG.java:708)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:73)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:124)

I don’t know what I’m doing wrong because it seems that is the selenium.open(“http://www.google.com/webhp”); statement who is trowing this excepcition, I guess I’m missing something in my configuration.

can anyone give me som clues??

31. Niranjan Kumar - July 20, 2009

Hi,

When i click on Run configuration, iam not able to see TestNG. I can see only java applet, java application, Junit and Task context Test. Can anyone helps me on how to configure TestNG.

Regards
Niranjan

epyramid - July 20, 2009

You need to install the TestNG plugin and remember to restart Eclipse after the install.

32. delarco - July 27, 2009

Hi!

I`m using Selenium RC + Eclipse and TestNG. It work`s fine but i have a little problem.
A wrote my test with Eclipse and i want run my test without Eclipse.
for example i have a java file. this is my test class. I want it run from the command-line. And i want the testNG reports.

Thanks!

33. Freenty - July 29, 2009

Tnx big match! waiting post about marven)

epyramid - August 3, 2009

I will write about this soon.

34. Dan - July 30, 2009

Hello All,
I have read many tutorials and have tried many examples. I am new to programing and java web application testing. I have got everything down except for error reporting which brings me here. I simply have had little luck. I think it is because I do not understand how to properly create the xml configuration files. It is becoming apparent to me that with error logging I must have a xml file, a certain way to feed it into the TestNG program, and a means of grabbing the report. I do not understand this process which is the reason for my “WARNING: No test suite found. Nothing to run” error. I would greatly appreciate any assistance or advice. Thanks

35. Guru chawl - August 9, 2009

I am beginner for selenium and java, but i have learn how to record scripts and export scripts to java language, manipulate them and run using selenium rc. Now i want to store results and display, especial in junit, how to generate report and also i want to do database checking how to do database connection and retrieve values . Please help me

epyramid - September 1, 2009

You can look at the following.

1. JUnit Reporter for the test reports.
2. DB Unit for database testing.

I hope this helps.

36. kar - August 26, 2009

Hi epyramid ,

First of all thanks for all this.Very good material.I am just wondering from where I can run the more examples. the example you posted here is very small I would like to run some complex java file with checking more functionality of Selenium.

Thanks,
Kar

epyramid - September 1, 2009

It is just a starting point and with Selenium “Sky is the limit”. You can find more examples on the Selenium User Forums or you can share your work with us.

37. Ajay - August 31, 2009

i have created a testng script from selenium ide and when i run that in eclipse,i get an error “you need to specify atleast one testng.xml or one class” .what does it mean?

and i hv followed the steps that you explained in the screenshots of “setting up selenium rc and testng using eclipse”.

epyramid - September 1, 2009

Check your TestNG plugin configuration. You should select Class if you are following this example.

You can check the configuration in Eclipse by Clicking on

Run > Run Configuration > TestNG and make sure that under Run the radio button for Class is selected and your class details are listed in the edit field next to it.

38. Rajiv Walia - August 31, 2009

I am trying to Run Selenium RC on Windows Win 7 but I am getting error. Steps followed by me are written below:

1. Installed Selenium IDE.

2. Record a test case and Exported as “PHP selanium RC”

3. Open it in notepad and get following code:

a. Code [Filename is "Example.php"]

setBrowser(”*chrome”);
$this->setBrowserUrl(”http://delicious.com/”);
}

function testMyTestCase()
{
$this->open(”/”);
$this->type(”homepage-searchinput”, “selenium”);
$this->click(”homepage-searchsubmit”);
$this->waitForPageToLoad(”30000″);
$this->getText(”xpath=/html/body[@id='index']/div
[@id='doc3']/div[@id='bd']/div
[@id='yui-main']/div[@id='content']/h3/div/em”);
}
}
?>

b. Replaced “$this->setBrowser(”*chrome”);” with

“$this->setBrowser(”*iexplore C:\Program Files (x86)\Internet Explorer\iexplore.exe”);”

c. Save and close it.

4. Installed Java

5. Downloaded Selenium RC and Run Selenium RC server by using “java -jar selenium-server.jar” command on command prompt and minimized it.

6. Installed PHP.

7. Copied and pasted the “Example.php” file in “C:\wamp\bin\php\php5.2.8″ folder

8. Open another cmd window and wrote cd C:\wamp\bin\php\php5.2.8

9. Run the command phpunit Example

10. I have noticed that Internet explorer was opened and nothing was happened after that.

10. Error recieved by me on my command prompt:

C:\wamp\bin\php\php5.2.8>phpunit Example
PHPUnit 3.3.17 by Sebastian Bergmann.

E

Time: 02:00

There was 1 error:

1) testMyTestCase
RuntimeException: Could not connect to the Selenium RC server.

FAILURES!
Tests: 1, Assertions: 0, Errors: 1.

epyramid - September 1, 2009

Did you start the selenium server using the following command.

> java -jar selenium-server.jar -interactive

You need to be in the directory where this jar is placed.

39. Ajay - September 2, 2009

hi,
i copied a sample test in testNG from some tutorials and imported in eclipse.the test name is “chaak.java” so when i ran that it asks me to specify a testng.xml file. so i even copied the xml file of the test “chaak” which was also there in tat tutorial. and now it runs perfectly which means if we have to run a testNG test in eclipse then we must also have its xml file as well.my doubt is how we can create a xml file of a testNG test that we create from selenium ide.

40. phil - September 2, 2009

Great Site!

Can you please help. I have just finished reinstalling Eclipse because I had an error whereby I can run a Java listing as a TestNG, but all the references to Selenium in the script in Eclipse are highlighted in red and I get the following when I try to “run as TestNG”..
[Parser] Running:
C:\EclipseWorkspace\QAReplacement\temp-testng-customsuite.xml

[[Utils]] Unable to open class Test – unable to resolve class reference SeleneseTestNgHelper

===============================================
QAReplacement
Total tests run: 0, Failures: 0, Skips: 0
===============================================

java.lang.NoClassDefFoundError: SeleneseTestNgHelper
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.testng.internal.ClassHelper.forName(ClassHelper.java:74)
at org.testng.xml.XmlClass.getSupportClass(XmlClass.java:52)
at org.testng.internal.Utils.xmlClassesToClasses(Utils.java:79)
at org.testng.TestRunner.initMethods(TestRunner.java:289)
at org.testng.TestRunner.init(TestRunner.java:235)
at org.testng.TestRunner.init(TestRunner.java:197)
at org.testng.TestRunner.(TestRunner.java:155)
at org.testng.remote.RemoteTestNG$1.newTestRunner(RemoteTestNG.java:102)
at org.testng.remote.RemoteTestNG$DelegatingTestRunnerFactory.newTestRunner(RemoteTestNG.java:154)
at org.testng.SuiteRunner$ProxyTestRunnerFactory.newTestRunner(SuiteRunner.java:529)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:250)
at org.testng.SuiteRunner.run(SuiteRunner.java:204)
at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:877)
at org.testng.TestNG.runSuitesLocally(TestNG.java:842)
at org.testng.TestNG.run(TestNG.java:751)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:73)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:124)
Caused by: java.lang.ClassNotFoundException: SeleneseTestNgHelper
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
… 28 more

I have followed the instructions above and had it working once when it was first installed a month ago but something has happened for the Selenium references to no longer be legal and I am a bit stumped, my script is below.

package com.example.tests;

import com.thoughtworks.selenium.*;
import org.testng.annotations.*;
import static org.testng.Assert.*;
import java.util.regex.Pattern;

public class Test extends SeleneseTestNgHelper {
@Test public void testUntitled() throws Exception {
selenium.open(“http://www.google.co.uk/ig?hl=en”);
assertEquals(selenium.getTitle(), “iGoogle”);
selenium.type(“q”, “firstname surname”);
selenium.click(“btnG”);
selenium.waitForPageToLoad(“30000″);
assertEquals(selenium.getTitle(), “firstname surname – Google Search”);
}
}

I have added all the jars below to the Java project and they show under the build path in project properties. TestNG Plug in is fully up to date as of last night according to Eclipse.

selenium-server.jar
selenium-server-coreless.jar
selenium-server-sources.jar
selenium-server-tests.jar
selenium-server-test-sources.jar

testng-5.9-jdk15.jar

selenium-java-client-driver.jar
selenium-java-client-driver-sources.jar
selenium-java-client-driver-tests.jar
selenium-java-client-driver-test-sources.jar

JRE System Library [jre6]

What am I missing?
thanks
phil

epyramid - September 3, 2009

I think SeleneseTestNgHelper is not a valid file in your case. Try the following.

package com.example.tests;

import com.thoughtworks.selenium.*;
import org.testng.annotations.*;
import static org.testng.Assert.*;
import java.util.regex.Pattern;

public class TestGoogle {
@Test public void testUntitled() throws Exception {
selenium.open(”http://www.google.co.uk/ig?hl=en”);
assertEquals(selenium.getTitle(), “iGoogle”);
selenium.type(”q”, “firstname surname”);
selenium.click(”btnG”);
selenium.waitForPageToLoad(”30000″);
assertEquals(selenium.getTitle(), “firstname surname – Google Search”);
}
}

41. Ajay - September 7, 2009

could you also please tell me which is the best way to run a testNG script from (xml,ant or command prompt?)

i ran my script with xml and found it good but would like to know that which one of these would be good to use.

42. seshu - September 8, 2009

Hi I am unable to view the testng icon in window menu bar and in Run as., can you please explain how to do step by step

43. dee - September 8, 2009

Hi,
I am trying to run the following code with eclipse..

import com.thoughtworks.selenium.*;

public class icici001 {
static Selenium selenium;
public static void main(String arg[])
{
selenium = new DefaultSelenium(“localhost”, 4444, “*iexplore”, “http://www.google.com”);
selenium.start();
selenium.click(“btnG”);
selenium.waitForPageToLoad(“30000″);
selenium.click(“link=ICICI Bank | Personal Banking | NRI Banking | Corporate Banking …”);
selenium.waitForPageToLoad(“30000″);
selenium.click(“link=Cards”);
selenium.waitForPageToLoad(“30000″);
selenium.click(“//img[@alt='Credit Cards']“);
selenium.waitForPageToLoad(“30000″);
selenium.click(“//img[@alt='VISA Cards']“);
selenium.waitForPageToLoad(“30000″);
selenium.click(“//tr[11]/td[2]/a/font”);
selenium.waitForPageToLoad(“30000″);
}
}

But it gives me the below error..

Exception in thread “main” com.thoughtworks.selenium.SeleniumException: ERROR: Element sf not found
at com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:97)
at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:91)
at com.thoughtworks.selenium.DefaultSelenium.type(DefaultSelenium.java:291)
at icici001.main(icici001.java:10)

Could you kindly help me out with the same?

44. rajeev singh - September 10, 2009

Hello,
i have windows vista installed laptop.
i have downloaded the selenium RC. but when i am trying to start the selenium server using java -jar selenium-server.jar command.
every time it is showing following exception:

22:39:59.538 INFO – Java: Sun Microsystems Inc. 14.1-b02
22:39:59.538 INFO – OS: Windows Vista 6.0 x86
22:39:59.538 INFO – v1.0-beta-1 [2201], with Core v1.0-beta-1 [1994]
22:39:59.616 INFO – Version Jetty/5.1.x
22:39:59.616 INFO – Started HttpContext[/selenium-server/driver,/selenium-server/driver]
22:39:59.616 INFO – Started HttpContext[/selenium-server,/selenium-server]
22:39:59.616 INFO – Started HttpContext[/,/]
22:39:59.679 WARN – Failed to start: SocketListener0@0.0.0.0:4444
Exception in thread “main” org.mortbay.util.MultiException[java.net.SocketException: Permission denied: listen failed]
at org.mortbay.http.HttpServer.doStart(HttpServer.java:686)
at org.mortbay.util.Container.start(Container.java:72)
at org.openqa.selenium.server.SeleniumServer.start(SeleniumServer.java:859)
at org.openqa.selenium.server.SeleniumServer.main(SeleniumServer.java:372)
java.net.SocketException: Permission denied: listen failed
at java.net.PlainSocketImpl.socketListen(Native Method)
at java.net.PlainSocketImpl.listen(Unknown Source)
at java.net.ServerSocket.bind(Unknown Source)
at java.net.ServerSocket.(Unknown Source)
at org.mortbay.util.ThreadedServer.newServerSocket(ThreadedServer.java:391)
at org.mortbay.util.ThreadedServer.open(ThreadedServer.java:477)
at org.mortbay.util.ThreadedServer.start(ThreadedServer.java:503)
at org.mortbay.http.SocketListener.start(SocketListener.java:203)
at org.mortbay.http.HttpServer.doStart(HttpServer.java:716)
at org.mortbay.util.Container.start(Container.java:72)
at org.openqa.selenium.server.SeleniumServer.start(SeleniumServer.java:859)
at org.openqa.selenium.server.SeleniumServer.main(SeleniumServer.java:372)

what i did:
1.i tried to change the port but no positive response and even on 4444 port no event is running.
2. i am the administrator of my machine.

Please try to resolve my problem.

45. AMC - September 30, 2009

I’m having trouble getting this to work. For my result I get:

===============================================
GoogleTest
Tests run: 0, Failures: 0, Skips: 0
===============================================

I have @Test above my test, but eclipse is giving me warning that “Test cannot be resolved to a type” on that line. I get the same warning on the @BeforeClass and @AfterClass line. Is this whats causing it not to work? I appreciate any help.

epyramid - October 17, 2009

Can you please post your code?

46. vinod - October 19, 2009

Hi,

Can you help me to configure the Selenium grid with eclipse.

Thanks
Cruise

epyramid - October 25, 2009

You don’t need Eclipse to set up Selenium Grid. Please read Selenium Grid documentation to understand the set up and purpose of Selenium Grid

epyramid - July 10, 2009

We use Selenium Maven plugin to run the selenium tests, you can find information about that on the following URL. http://mojo.codehaus.org/selenium-maven-plugin/

I hope this helps.

Cheers Haroon

epyramid - July 10, 2009

TestNG plugin is available on the following url. testng.org follow the instructions to install the plugin for Eclipse. Selenium does not come with any test runner plugin.

Cheers Haroon

Ajay - September 7, 2009

hi
i want to run my testNG script without eclipse.is there any other way where i can just run my testng script with anotations without eclipse.

ajay - September 11, 2009

I ran my testng test from eclipse and it was succesfull but i am facing difficulty when i am running my testng test from ant.
so could you plz tell me how exactly and the order we follow to run from ant without using eclipse.and i would really appreciate if u can post or send to my mail a simple example of how to run a testng test from ant script.

pooja - October 5, 2009

hi Can you pls guide me how to create test suite if i have more than one test script and also how to run test suite.

epyramid - October 17, 2009

Please read about test suite xml files if you are using TestNG.

http://www.testng.org

You can specify multiple test classes or java packages in a suite file and testng will execute all the classes one by one.