Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

parameterized TestNG factory initialization using Maven Surefire plugin

 
Stefan Strobel
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi experts,

I'm pretty new to all Maven, TestNG and the Surefire plugin that connects both.
So for, I can execute tests using the testng.xml file and groups/classes defined in the pom. Now I need to implement a factory pattern that will run all test methods for one (or more) classes.
Currently I have the following setup:
I have a test class which extends a base class to set up the environment (I'm running GUI tests with Selenium Webdriver). In the TestBase class, I prepare a number of different browsers. The Tests are grouped and my surefire plugin calls a specic group. Upon initialization of the test object containg the test methods, a factory shall provide the browsers.

Hm difficult to show that in a compact way.
But when I run my maven script the following happens:
org.testng.TestNGException:
Can't invoke public void org.test.pages.HomePageTest.testTitleMatching() throws java.lang.InterruptedException: either make it static or add a no-args constructor to your class


Currently my code looks like the following:


My parent class:


here comes my factory:


and my surefire plugin configuration:


So can anyone image what is going wrong? I read in other posts that I have to use the factory pattern (what actually do, don't I?). Wild guesses?

Thanks!
Stefan
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could follow the second part of the error messages: "add a no-args constructor to your class"

The constructor you do have takes a parameter and I suspect that TestNG is ignoring the @Factory annotation (is that a TestNG annotation? if not, is it an annotation of a TestNG extension and if so did you properly configure the extension?)
 
Stefan Strobel
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Peter,

thanks for your answer. I managed to get it work two days ago with another approach. Turns out I missed one of the many possible variations:





It works like a charm now. Even with an args-constructor. Hope this helps anyone else
 
Vasyl Lenko
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had the same issue. Solution: DataProvider method should return Object[][] instead of Iterator<Object[]>.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic