Run TestNG XML from another Java Project with Path

1,057 views
Skip to first unread message

colin o regan

unread,
Jul 7, 2016, 8:47:52 AM7/7/16
to testng-users
Hi,

How can I run a TestNG XML suite from another java project?

My project is to run a TestNG XML suite from another project, it will ask for the path to the XML and when the path is given it will execute.

However when I do run it, the XML will run but it can't find the test classes specified in it.

Is there anyway around this?

Thank you.

⇜Krishnan Mahadevan⇝

unread,
Jul 7, 2016, 10:03:31 AM7/7/16
to testng...@googlegroups.com
Can you please show us how you are running the tests ? Please tell us the exact mechanism with as much details as possible.

Also please let us know as to how is the other project being made available.

All this additional context is going to help us understand your problem a bit more better.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

colin o regan

unread,
Jul 7, 2016, 10:47:49 AM7/7/16
to testng-users
Hi Kirshnan,

I'm using the following code:

fileChooserSingleB.setOnAction(
        new EventHandler<ActionEvent>(){
        @Override
        public void handle(final ActionEvent e) {
        FileChooser fileChooserSingle = new FileChooser();
        fileChooserSingle.setInitialDirectory(new File ("C:\\Users\\reganc3\\git\\stoage_mgmt\\unisphere360\\resources\\testruns"));
        fileChooserSingle.getExtensionFilters().addAll(
        new ExtensionFilter("XML Files", "*.xml"));
        File selectedFile = fileChooserSingle.showOpenDialog(null);
        if (selectedFile != null) {
       
       
       
        String xmlFileName = selectedFile.getAbsolutePath();
        TestNG testng = new TestNG();
        List<String> testFilesList = new ArrayList<String>();
        testFilesList.add(xmlFileName); //test suite resides in the working directory's root folder
        testng.setTestSuites(testFilesList); //you can addd multiple suites either here by adding multiple files or include all suites needed in the testng.xml file 
        //testng.setUseDefaultListeners(false);
        //testng.addListener(htmlRep); 
        testng.run();
       
       
       
        }
       
        else {
       
        System.out.println("none selected");
        }
       
        }
        }
        );

The code is for a GUI, so when a button is pressed it will open Java File Chooser, from here you can browse your files. When you select a file, the path of the file is saved to the variable " xmlFileName".

It is then run using "testng.run();"

This project is just a one java class project for the GUI. 

The automation project isn't as such being made available, all the user is doing is searching for file and selecting it. This then gives the path of the file to the code to run the XML.

Here is the error message generated:

Exception in thread "JavaFX Application Thread" org.testng.TestNGException: 
Cannot find class in classpath: com.emc.qe.u360.tests.LogoutTests

For trouble shooting, I implemented the above code for the GUI within my automation project, but it still could not find the test classes.

When running the TestNG xmls normally ( from eclipse, jenkins ) it works perfectly.

My automation project is a Maven style project, using TestNG and Selenium.

⇜Krishnan Mahadevan⇝

unread,
Jul 7, 2016, 11:34:43 PM7/7/16
to testng...@googlegroups.com
Colin,

From your code, it looks like your GUI project [ the one that is opening up the File Chooser ] and your test project [ the one that lives in this directory  C:\\Users\\reganc3\\git\\stoage_mgmt\\unisphere360  ] are not coming together with respect to the CLASSPATH.
Your GUI project needs to have access to all the .class files that represent the byte code of the java classes in [C:\\Users\\reganc3\\git\\stoage_mgmt\\unisphere360]. So you have two options that you can try :

  1. Modify the CLASSPATH of your GUI project such that it includes the build path of your test project as well.
  2. Build a jar out of your test project and add it up in your lib folder/dependencies section of your GUI project
Please try one of these and kindly check if that resolves your issue at hand.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

colin o regan

unread,
Aug 15, 2016, 4:45:53 AM8/15/16
to testng-users
Hi Krishnan,

I have done the above and I am stuck with this error now.

[TestNGClassFinder] Warning: Can't link and determine methods of class com.emc.qe.u360.tests.LogoutTests
[[TestNGClassFinder]] Unable to read methods on class com.emc.qe.u360.tests.LogoutTests - unable to resolve class reference org/openqa/selenium/WebDriver
[TestNGClassFinder] Warning: Can't link and determine methods of class com.emc.qe.u360.tests.LoginPageTests
[[TestNGClassFinder]] Unable to read methods on class com.emc.qe.u360.tests.LoginPageTests - unable to resolve class reference org/openqa/selenium/WebDriver
[TestNG] Running:
  C:\Users\reganc3\git\stoage_mgmt\unisphere360\resources\testruns\poc1.xml
 
My GUI project is not using a maven style project and my test project is using a maven style project.

Could this be the issue?

Thanks,
Colin.

colin o regan

unread,
Aug 15, 2016, 5:03:34 AM8/15/16
to testng-users

Hi Krishnan,

I have actually solved the above issue, it was a stupid mistake, I never had my selenium web driver jars imported to my project.

At the moment now it works. However, all my tests are skipping. Any ideas what could be causing this?

Thanks Krishnan.

Regards,
Colin. 

⇜Krishnan Mahadevan⇝

unread,
Aug 15, 2016, 8:19:28 AM8/15/16
to testng...@googlegroups.com
Would be hard to say without seeing the stacktrace (or) reason for skipping.

Can you please share more information in terms of stacktraces etc., ?

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users+unsubscribe@googlegroups.com.

colin o regan

unread,
Aug 15, 2016, 8:49:51 AM8/15/16
to testng-users
Thanks for the speedy reply Krishnan.

At the moment this is the only information I get back from the console

[TestNG] Running:
  C:\Users\reganc3\git\stoage_mgmt\unisphere360\resources\testruns\poc1.xml


===============================================
example suite 1
Total tests run: 8, Failures: 0, Skips: 8
Configuration Failures: 2, Skips: 14
===============================================

All this happens in about 2 seconds.

Ill try see if I can get more details behind it.

The XML I'm running works perfectly running it normally, but running it from the GUI the above happens.

Ill try get more details and get back to you.

Thanks again, you are a great help and I appreciate it immensely.

On Monday, August 15, 2016 at 1:19:28 PM UTC+1, Krishnan wrote:
Would be hard to say without seeing the stacktrace (or) reason for skipping.

Can you please share more information in terms of stacktraces etc., ?

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

On Mon, Aug 15, 2016 at 2:33 PM, colin o regan <colinor...@gmail.com> wrote:

Hi Krishnan,

I have actually solved the above issue, it was a stupid mistake, I never had my selenium web driver jars imported to my project.

At the moment now it works. However, all my tests are skipping. Any ideas what could be causing this?

Thanks Krishnan.

Regards,
Colin. 

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.

⇜Krishnan Mahadevan⇝

unread,
Aug 15, 2016, 10:25:26 AM8/15/16
to testng...@googlegroups.com
Colin,

Try bumping the verbose levels in your suite xml file [ verbose=3 for e.g., ]. That should print you more information on the console with respect to the failures.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

To unsubscribe from this group and stop receiving emails from it, send an email to testng-users+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages