8

I am new to TestNG and Selenium Webdriver and trying to create a testng.xml using eclipse.

Done some research in www and understand that this file can be created by doing Right Click on the Java class >> TestNG >> Convert to TestNG

However this Convert Refactoring wizard is not opening.

Whether this wizard will not open, if the Java class already contains @Test annotations (!?)

Can you help me to create testng.xml using eclipse please.

(I am using Eclipse Luna)

2
  • did you solve the problem. please do share. i am facing the same problem. Commented Aug 13, 2015 at 14:05
  • please find the below workaround. Commented Aug 13, 2015 at 14:28

5 Answers 5

19

Created testng suite file manually as below:

  1. Run once your project from Eclipse
  2. Refresh your project
  3. Now, “test-output” folder will be created under your project –> unfold the folder
  4. Double click the ‘index.html’ file -> It will be opened in the Eclipse Browser window or any other external browser (e.g. IE, Google Chrome, FF, MS Edge etc.)
  5. Click on the ‘.xml’ link given on the left panel
  6. The test suite XML will get opened on the right-side panel
  7. Take a copy of the XML content
  8. Right click your project >> New >> File
  9. Give name of your test suite file (with .xml extension e.g. testng.xml) and click Finish
  10. Paste the content that you copied from the ‘index.html’ and amend your suite file as per your needs
Sign up to request clarification or add additional context in comments.

2 Comments

problem is that only. "test-output" folder is not created.
Right Click in Package Explorer in Eclipse >> Build Path >> Configure Build Path > TestNG Click on TestNG and see the configuration. There you can set your Output directory. Verify whether it is updated with null or updated under with any other folder - more often it will updated as "/test-output"
4
  • Step 1 : Select your project folder in which you have all the packages.
  • Step 2 : Right click on selected project folder
  • Step 3 : Mouse hover on TestNG option from the given list which is located at the bottom.
  • Step 4 : Select "Convert to TestNG" option
  • Step 5 : A modal will appear with the name of "Generate testng.xml"
  • Step 6 : Click on Finish button to complete the process.

Comments

1

Praveen, please right click on the project and then go to convert to testNG,

now it will create testng.xml in which you will have all your classes, you can select the classes which u want and then execute this testng.xml as testng suite.

1 Comment

igniteram1, I am encountering issue only on this step..when I do right click on the project and go to "TestNG >> Convert to TestNG", I am not getting any wizard to create testng.xml and no XML is created..
1
  1. Click on Project
  2. CNTL+ENTER
  3. Go to general file
  4. Create a file in your project with name testng.xml
  5. click on finish
  6. Open that file and write the given below code

Change the names according to your program and run that testng.xml Run as Testng it will run your program with Testng

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite Name"  > 
<!-- suite name="Suite Name" --> 


             <test name="TestA" allow-return-values="true">
                     <classes>
                       <!-- packagename.Testcase class name  -->
                             <class name ="listnerDemo.Testcases" />
                     </classes>
             </test>


                   <listeners>
              <!-- packagename.customerlistner_classname  -->
                       <listener class-name="listnerDemo.CustomerListner"/>
              </listeners>

</suite>

*********************************if you have to run using multiple suite********

let me give you an example if you have three suites that have multiple cases then create the tree .xml file and write the code as above for all the three suite

then create a testng.xml file that will include the code as below

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<Suite name="Data driver testng project">
<Suite-files>
    <Suite-files path="C:\Arpan\Study Documents\Selenium\Selenium Framework\Core_Framework_TestNG\suiteA.xml" />
    <Suite-files path="C:\Arpan\Study Documents\Selenium\Selenium Framework\Core_Framework_TestNG\suiteB.xml" />
    <Suite-files path="C:\Arpan\Study Documents\Selenium\Selenium Framework\Core_Framework_TestNG\suiteC.xml" />
</Suite-files>
</Suite>

Then run the testng.xml Run as Testng then it will run all the program of those are part of these three suites

Comments

0

How to implement TestNG:

  1. Go to the eclipse marketplace.

  2. Search for TestNG > Install > Restart IDE. install

  3. Create a New Java Project > Go to Build path > Add library > Select TestNG.

  4. Go Project src file > New > TestNG Class.

  5. Write your code.

  6. Run as TestNG. Run testng

  7. Now Right-click on the Project > however on TestNG > Convert to TestNG.

Convert

  1. Now refresh your project view > Check the testng.xml file created.

Testng.xml file

Now as many Test cases you add it will be added in your testng.xml and you can add params from the .xml file and check with all the annotations, then it will give a nice report as well. Does Bellow comment on whether you got any difficulties or not?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.