Unable to set the invocation count using maven/testng with Java

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Unable to set the invocation count using maven/testng with Java

ann22301@gmail.com
Good morning,

I am using TestNG (version 6.8) to set up an selenium automation framework using Java and Maven with a multi-threaded driver on the Grid.  I would like to override the invocation count by specifying a -Dparameter at the command line using maven (mvn).  For example, if I run the following:

mvn clean test -Dgroups=regression -DpositiveTestsToRun=5

I would like the 5 to set how many times the @Test for positiveTests runs.

I've tried this using this in an @BeforeMethod but I don't know how to pass the first argument (the bold null) which is the annotation.  (Btw please excuse the formatting)

@BeforeMethod(alwaysRun = true)

public void beforeMethod(ITestContext context)

{

ITestNGMethod currentTestNGMethod = null;

for (ITestNGMethod testNGMethod : context.getAllTestMethods())

{

if (testNGMethod.getInstance() == this)

{

currentTestNGMethod = testNGMethod;

TestNG tng = new TestNG();

tng.setAnnotationTransformer(new MyTransformer(nullcurrentTestNGMethod.getRealClass(), nullnull));

}

}

}


I've also tried using the ITestNGMethod as follows but it doesn't work either:


// Issue with the below when using both ITestAnnotation annotation,

// ITestContext context

// must be supplied as @Parameters or in @Configuration but googling says

// @Configuration is deprecated

@BeforeMethod(alwaysRun = true)

public void beforeMethod2(ITestContext context)

// ITestAnnotation annotation,

{

ITestNGMethod currentTestNGMethod = null;

System.out.println("============= TestNGMethod.class: " + ITestNGMethod.class);

for (ITestNGMethod testNGMethod : context.getAllTestMethods())

{

if (testNGMethod.getInstance() == this)

{

currentTestNGMethod = testNGMethod;


System.out.println("-------- currentTestNGMethod: " + currentTestNGMethod);

/////////////// doesn't work

currentTestNGMethod.setInvocationCount(getPositiveTestsToRun());

break;

}

}

System.out

.println("============= in @BeforeMethod of DriverBase positiveTestsToRun: " + getPositiveTestsToRun());

// TestNgListener.getTestMethod().setInvocationCount(getPositiveTestsToRun());


System.out.println("=== currentTestNGMethod.getInvocationCount(): " + currentTestNGMethod.getInvocationCount());

System.out.println("currentTestNGMethod.toString(): " + currentTestNGMethod.toString());

}


I've tried so many things to no avail.  Any help would be appreciated!


Best regards,

Ann

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Unable to set the invocation count using maven/testng with Java

SUBRAMANYESWARA RAO BHAVIRISETTY
Can you override the transform method provided by IAnnotationTransformer by writing your own listener and then use the listener later in the pom?
 
@Override
        public void transform(ITestAnnotation arg0, Class arg1, Constructor arg2,
                        Method arg3) {
                arg0.setInvocationTimeOut(System.getProperty('timeout'));
                arg0.setInvocationCount(System.getProperty('positiveTestsToRun'));
            LOG.info("Invoking method " + arg3.getName() + " for " + configarr[0] + " times with timeout " + configarr[1] );
        }

<properties>
                                                <property>
                                                        <name>listener</name>
                                                        <value>org.uncommons.reportng.HTMLReporter,org.uncommons.reportng.JUnitXMLReporter,src.TestNGTransformer</value>
                                                </property>
                                        </properties>


Subramanyam


On Mon, Apr 17, 2017 at 7:33 AM, Ann Millikin <[hidden email]> wrote:
Good morning,

I am using TestNG (version 6.8) to set up an selenium automation framework using Java and Maven with a multi-threaded driver on the Grid.  I would like to override the invocation count by specifying a -Dparameter at the command line using maven (mvn).  For example, if I run the following:

mvn clean test -Dgroups=regression -DpositiveTestsToRun=5

I would like the 5 to set how many times the @Test for positiveTests runs.

I've tried this using this in an @BeforeMethod but I don't know how to pass the first argument (the bold null) which is the annotation.  (Btw please excuse the formatting)

@BeforeMethod(alwaysRun = true)

public void beforeMethod(ITestContext context)

{

ITestNGMethod currentTestNGMethod = null;

for (ITestNGMethod testNGMethod : context.getAllTestMethods())

{

if (testNGMethod.getInstance() == this)

{

currentTestNGMethod = testNGMethod;

TestNG tng = new TestNG();

tng.setAnnotationTransformer(new MyTransformer(nullcurrentTestNGMethod.getRealClass(), nullnull));

}

}

}


I've also tried using the ITestNGMethod as follows but it doesn't work either:


// Issue with the below when using both ITestAnnotation annotation,

// ITestContext context

// must be supplied as @Parameters or in @Configuration but googling says

// @Configuration is deprecated

@BeforeMethod(alwaysRun = true)

public void beforeMethod2(ITestContext context)

// ITestAnnotation annotation,

{

ITestNGMethod currentTestNGMethod = null;

System.out.println("============= TestNGMethod.class: " + ITestNGMethod.class);

for (ITestNGMethod testNGMethod : context.getAllTestMethods())

{

if (testNGMethod.getInstance() == this)

{

currentTestNGMethod = testNGMethod;


System.out.println("-------- currentTestNGMethod: " + currentTestNGMethod);

/////////////// doesn't work

currentTestNGMethod.setInvocationCount(getPositiveTestsToRun());

break;

}

}

System.out

.println("============= in @BeforeMethod of DriverBase positiveTestsToRun: " + getPositiveTestsToRun());

// TestNgListener.getTestMethod().setInvocationCount(getPositiveTestsToRun());


System.out.println("=== currentTestNGMethod.getInvocationCount(): " + currentTestNGMethod.getInvocationCount());

System.out.println("currentTestNGMethod.toString(): " + currentTestNGMethod.toString());

}


I've tried so many things to no avail.  Any help would be appreciated!


Best regards,

Ann

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.



--
Subramanyam

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Loading...