Search code examples
mavenautomationtestngtest-data

Maven Test Automation Project


I have a maven test automation project developed using selenium and testng. This is what I am doing with my framework:

1.I have main class in src/main/java and within the main class I trigger methods to dynamically create and run the testng xml.

2.The tests to be run are determined from the XMLFlag.xls sheet and test data for the tests is set in TestNG.xlsx sheet in src/main/resources.

3.I have successfully created a jar of my entire package.

Since I have put my Test Data sheets(TestNG.xlsx and XMLFlag.xls)under src/main/resources, these Test data sheets get packaged within the jar.

But ideally, I would like to run my test scripts for different sets of test data and see if the scripts are successful. for example: I would like to run my scripts with ,say, username:abcd and password:1234 for the first time and then run the same set of scripts with username:efgh and password:9876.

But with my Test data sheets packaged within the jar I will not be able to achieve the above scenario since I cannot edit the test data sheets.

So let me say to overcome the above problem: 1.I put my Test data sheets in src/test/resources and not src/main/resources and then create a jar. But when I do this and try to run the jar,

I get an error message:

.\src\test\resources\XMLFlag.xls (The system cannot find the path specified)

This, I believe, is because the Test data sheets get placed in test-classes folder under target folder and not within the jar.

To put it in simple words: i. I want the test data sheets to be outside my jar, so that it can be edited and test scripts can be run based on the users requirement. ii.If the test data sheets are outside my jar and everything else within my framework is dependent on test data information(ie.test scripts, testng.xml) and is packaged within the jar, my jar would not run.

Is there a way to avoid this error and accomplish what I want to do? Or should I restructure my entire framework??

Kindly help me out.


Solution

  • How about passing the Test Data sheets as program arguments when you're executing your jar?

    That is,

    java -jar c:/path/to/your/jar c:/path/to/your/testng.xlsx c:/path/to/your/xmlflag.xlsx
    

    and then just in your main method, read the file names and their content such as

    File testNgXlsxFile = new File(args[0]);
    

    and pass the information from the files to your framework.

    Is that possible?