How use dataprovider with Maven? Getting java.io.FileNotFoundException

741 views
Skip to first unread message

unni

unread,
Jun 12, 2012, 3:10:53 AM6/12/12
to testng...@googlegroups.com
I just started with Maven using M2eclipse. I am using jxl for data provider and have installed jxl.jar into Maven central repository though mvn install:install-file and added dependency in pom.xml and no error.

Also i have placed the excel file in src/main/resources added in pom.xml as below

      <build>
          <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>

and sunfire

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                   <properties>
                        <property>
                            <name>usedefaultlisteners</name>
                            <value>false</value>
                        </property>
                        <property>
                            <name>listener</name>
                            <value>org.uncommons.reportng.HTMLReporter, org.uncommons.reportng.JUnitXMLReporter</value>
                        </property>
                    </properties>
                    <workingDirectory>target/</workingDirectory>
                </configuration>
            </plugin>
but when i run its says

java.lang.RuntimeException: java.io.FileNotFoundException: resources\testDP.xls (The system cannot find the path specified)
org.testng.internal.MethodInvocationHelper.invokeDataProvider(MethodInvocationHelper.java:143)
org.testng.internal.Parameters.handleParameters(Parameters.java:426)
org.testng.internal.Invoker.handleParameters(Invoker.java:1370)
org.testng.internal.Invoker.createParameters(Invoker.java:1067)
org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1170)
org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
org.testng.TestRunner.privateRun(TestRunner.java:758)
org.testng.TestRunner.run(TestRunner.java:613)
org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
org.testng.SuiteRunner.run(SuiteRunner.java:240)
org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:87)
org.testng.TestNG.runSuitesSequentially(TestNG.java:1170)
org.testng.TestNG.runSuitesLocally(TestNG.java:1095)
org.testng.TestNG.run(TestNG.java:1007)
org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:61)
org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:144)
org.apache.maven.surefire.Surefire.run(Surefire.java:169)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:350)
org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1021)
Caused by: java.io.FileNotFoundException: resources\testDP.xls (The system cannot find the path specified)



Tomek Kaczanowski

unread,
Jun 12, 2012, 3:17:38 AM6/12/12
to testng...@googlegroups.com
Hi,

1) could you please pass a fragment of code which actually expect the
file to be there?
2) what is <workingDirectory>target/</workingDirectory> for?
3) And BTW. this bug has nothing to do with TestNG.

--
Regards / Pozdrawiam
Tomek Kaczanowski
http://practicalunittesting.com


2012/6/12 unni <junis...@gmail.com>:
> --
> You received this message because you are subscribed to the Google Groups
> "testng-users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/testng-users/-/rXlkVHJEi7UJ.
> To post to this group, send email to testng...@googlegroups.com.
> To unsubscribe from this group, send email to
> testng-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/testng-users?hl=en.
Message has been deleted

unni

unread,
Jun 12, 2012, 4:45:40 AM6/12/12
to testng...@googlegroups.com
1.  @DataProvider(name = "Field")
     public static Object[][] createField() throws Exception{
         Object[][] retObjArr=getTableArray("src\\
main\\resources\\testDP.xls",
                 "Homepage", "Field");
         return(retObjArr);
     }

it was "
resources\\testDP.xls" and i changed as above as per your notification.Still i get the same error:

java.lang.RuntimeException: java.io.FileNotFoundException: src\main\resources\testDP.xls (The system cannot find the path specified)


2. workingDirectory property which causes that velocity.log (file created by Velocity engine used internally by ReportNG) is placed in target instead of main project directory

3. since this question comes with dataprovider concept i thought of posting here. ALso i tried searching in Selenium-USers and TestNG-user before posting and could seen more Q&S in testng-users for dataprovider related.
> testng-users+unsubscribe@googlegroups.com.

Tomek Kaczanowski

unread,
Jun 12, 2012, 4:51:02 AM6/12/12
to testng...@googlegroups.com
hm, if you have src/main/resources added to your resources in pom.xml,
then I guess you should simply look for "testDP.xls" - could you
please try it?

and btw, it is a common pattern in Maven world to keep test resources
in src/test/resources rather than in src/main/resources.
>> > testng-users...@googlegroups.com.
>> > For more options, visit this group at
>> > http://groups.google.com/group/testng-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "testng-users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/testng-users/-/aVgdnNMwUiwJ.
>
> To post to this group, send email to testng...@googlegroups.com.
> To unsubscribe from this group, send email to
> testng-users...@googlegroups.com.

unni

unread,
Jun 12, 2012, 5:17:18 AM6/12/12
to testng...@googlegroups.com
1. i have changed it to

@DataProvider(name = "Field")
     public static Object[][] createField() throws Exception{
         Object[][] retObjArr=getTableArray("testDP.xls",

                 "Homepage", "Field");
         return(retObjArr);
     }

and end up with
java.lang.RuntimeException: java.io.FileNotFoundException: testDP.xls (The system cannot find the file specified)

2. moved to svn/test/resources (thanks for the point)
>> > testng-users+unsubscribe@googlegroups.com.
>> > For more options, visit this group at
>> > http://groups.google.com/group/testng-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "testng-users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/testng-users/-/aVgdnNMwUiwJ.
>
> To post to this group, send email to testng...@googlegroups.com.
> To unsubscribe from this group, send email to
> testng-users+unsubscribe@googlegroups.com.

Krishnan Mahadevan

unread,
Jun 12, 2012, 5:24:16 AM6/12/12
to testng...@googlegroups.com
I think this is the problem to begin with :

    <build>
          <resources> 
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>

If I remember correctly, you are basically telling maven that it has to apply filtering (context substitution) to the folder you mentioned, but you never told it the set of files that it has to copy over to the target folder.

for src/main/resources, you would need something like this :


<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/buildinfo.properties</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<includes>
<include>**/db.properties</include>
<include>**/wsdl/*</include>
<include>**/abc.p12</include>
<include>**/scripts/*</include>
</includes>
</resource>
</resources>

for src/test/resources, I think there is something called <testResources> as well. 

Perhaps because the excel file is never even getting copied over to your target folder, is why you are seeing this error.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"



To view this discussion on the web visit https://groups.google.com/d/msg/testng-users/-/LSMhFk5AHdsJ.

To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.

unni

unread,
Jun 12, 2012, 6:04:25 AM6/12/12
to testng...@googlegroups.com
right now i placed testDP.xls in src/test/resources and i have added as per your say

      <testResources>
      <testResource>
        <directory>src/test/resources</directory>
        <filtering>true</filtering>
      </testResource>
    </testResources>

But still it throws same error.

Can you please tell me how to use dataprovider in Maven...

Krishnan Mahadevan

unread,
Jun 12, 2012, 6:05:40 AM6/12/12
to testng...@googlegroups.com
You still havent included the <includes> tag in your testResources section. I suggest that you please fix that part, do a maven compile, and then go over to your target/test-classes folder and first ascertain that your excel sheet is indeed there.

This has got nothing to do with TestNG AFAIK.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"



To view this discussion on the web visit https://groups.google.com/d/msg/testng-users/-/PPVD-Dkv5vEJ.

To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.

unni

unread,
Jun 12, 2012, 6:29:01 AM6/12/12
to testng...@googlegroups.com
I really didnt get what should i include. But i have included something like
<testResources>
      <testResource>
        <directory>src/test/resources</directory>
        <filtering>true</filtering>
        <includes>
            <include>**/*.xls</include>
        </includes>
      </testResource>
    </testResources>

But, without include,
when i use <testResources> the testDP.xls gets created under target/test-classes
and when i use <resources> as i used earlier, testDP.xls gets created under target/test-classes and target/classes

so the file gets created in the first time itself but end up with FileNotFoundException.

Cédric Beust ♔

unread,
Jun 12, 2012, 11:47:30 AM6/12/12
to testng...@googlegroups.com
Please take this discussion somewhere else (some Maven mailing-list). This is a Maven resource question, it has nothing to do with TestNG.

unni: please take some time to read the Sonatype Maven book, you need to learn the basics of Maven to do this.

-- 
Cédric




To view this discussion on the web visit https://groups.google.com/d/msg/testng-users/-/72YsG3MW0rUJ.

To post to this group, send email to testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.

Mark Derricutt

unread,
Jun 12, 2012, 10:25:31 PM6/12/12
to testng...@googlegroups.com
I don't think its even Maven related. Whatever getTableArray() is doing
seems to be throwing a FileNotFoundException - which is NOT a resources
issue ( i.e. class.getResource() ).

Since he's telling Maven to change his working directory, I suspect he
needs to use "../src/...." to read a parent directory.

unni

unread,
Jun 13, 2012, 2:10:17 AM6/13/12
to testng...@googlegroups.com

I am not looking anything related to Maven. I was working with DataProvider using JXL. I just started using maven and i face this issue and posted here looking forward to get some help for dataProvider.

My goal is using dataProvider with Maven (Not simple array example.. using any API JXL or any.. i was using JXL and comfortable with that). Can you please provide me a sample or tell me how to achieve this.
Reply all
Reply to author
Forward
0 new messages