Quantcast

Disabled testcases dynamically

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

Disabled testcases dynamically

shakun tyagi
I am trying to disable test cases dynamically using IAnnotationTransformer, 

testng.xml 

<?xml version="1.0" encoding="UTF-8"?>

<suite name="SANITYDESKTOP" parallel="false" verbose="1">

<listeners>

      <listener class-name="com.sz.listeners.MyAnnotationsTransformer"/>

      <listener class-name="org.uncommons.reportng.HTMLReporter"/>

      <listener class-name="org.uncommons.reportng.JUnitXMLReporter"/>

  </listeners>

  

   <test verbose="10" name="USER BOOKING FLOW" preserve-order="true">

    <classes>

    <class name="com.sz.desktop.tests.DesktopUserBookingFlow"></class>

    </classes>

    </test>

</suite>





public class MyAnnotationsTransformer implements IAnnotationTransformer {

public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) {

if(testCondition(...)){

annotation.setEnabled(true);

}else{

annotation.setEnabled(false);

}

}




Test Class :


public class DesktopUserBookingFlow extends DesktopSetUp {

protected static Properties prop = new Properties();

@Test(testName="Desktop001_Login",enabled=true)

public void Desktop001_Login(){

HomePageImpl.clickOnLoginLink(driver);

LoginPageImpl.typeUsername(driver, "");

LoginPageImpl.typePassword(driver, "");

LoginPageImpl.clickLoginButton(driver);

}

@Test(testName="Desktop002_Search()",enabled=true)

public void Desktop002_Search(){

HomePageImpl.typeCityInSearchField(driver, "");

HomePageImpl.clickOnSearchButton(driver);

}



Testng failed to disable the test and through Null exception.


--
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: Disabled testcases dynamically

⇜Krishnan Mahadevan⇝
Stacktrace please ?

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 Wed, Feb 8, 2017 at 2:59 PM, shakun tyagi <[hidden email]> wrote:
I am trying to disable test cases dynamically using IAnnotationTransformer, 

testng.xml 

<?xml version="1.0" encoding="UTF-8"?>

<suite name="SANITYDESKTOP" parallel="false" verbose="1">

<listeners>

      <listener class-name="com.sz.listeners.MyAnnotationsTransformer"/>

      <listener class-name="org.uncommons.reportng.HTMLReporter"/>

      <listener class-name="org.uncommons.reportng.JUnitXMLReporter"/>

  </listeners>

  

   <test verbose="10" name="USER BOOKING FLOW" preserve-order="true">

    <classes>

    <class name="com.sz.desktop.tests.DesktopUserBookingFlow"></class>

    </classes>

    </test>

</suite>





public class MyAnnotationsTransformer implements IAnnotationTransformer {

public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) {

if(testCondition(...)){

annotation.setEnabled(true);

}else{

annotation.setEnabled(false);

}

}




Test Class :


public class DesktopUserBookingFlow extends DesktopSetUp {

protected static Properties prop = new Properties();

@Test(testName="Desktop001_Login",enabled=true)

public void Desktop001_Login(){

HomePageImpl.clickOnLoginLink(driver);

LoginPageImpl.typeUsername(driver, "");

LoginPageImpl.typePassword(driver, "");

LoginPageImpl.clickLoginButton(driver);

}

@Test(testName="Desktop002_Search()",enabled=true)

public void Desktop002_Search(){

HomePageImpl.typeCityInSearchField(driver, "");

HomePageImpl.clickOnSearchButton(driver);

}



Testng failed to disable the test and through Null exception.


--
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.

--
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: Disabled testcases dynamically

shakun tyagi
Hi Krishnan,


java.lang.NullPointerException

at com.sz.listeners.MyAnnotationsTransformer.transform(MyAnnotationsTransformer.java:19)

at org.testng.internal.annotations.JDK15AnnotationFinder.transform(JDK15AnnotationFinder.java:113)

at org.testng.internal.annotations.JDK15AnnotationFinder.findAnnotation(JDK15AnnotationFinder.java:179)

at org.testng.internal.annotations.JDK15AnnotationFinder.findAnnotation(JDK15AnnotationFinder.java:103)

at org.testng.internal.TestNGClassFinder.isTestNGClass(TestNGClassFinder.java:223)

at org.testng.internal.TestNGClassFinder.<init>(TestNGClassFinder.java:107)

at org.testng.TestRunner.initMethods(TestRunner.java:409)

at org.testng.TestRunner.init(TestRunner.java:235)

at org.testng.TestRunner.init(TestRunner.java:205)

at org.testng.TestRunner.<init>(TestRunner.java:153)

at org.testng.SuiteRunner$DefaultTestRunnerFactory.newTestRunner(SuiteRunner.java:536)

at org.testng.SuiteRunner.init(SuiteRunner.java:159)

at org.testng.SuiteRunner.<init>(SuiteRunner.java:113)

at org.testng.TestNG.createSuiteRunner(TestNG.java:1299)

at org.testng.TestNG.createSuiteRunners(TestNG.java:1286)

at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)

at org.testng.TestNG.run(TestNG.java:1057)

at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:281)

at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:75)

at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:121)

at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:290)

at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:242)

at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:121)


Thanks

Shakun


On Wed, Feb 8, 2017 at 7:04 PM, ⇜Krishnan Mahadevan⇝ <[hidden email]> wrote:
Stacktrace please ?

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 Wed, Feb 8, 2017 at 2:59 PM, shakun tyagi <[hidden email]> wrote:
I am trying to disable test cases dynamically using IAnnotationTransformer, 

testng.xml 

<?xml version="1.0" encoding="UTF-8"?>

<suite name="SANITYDESKTOP" parallel="false" verbose="1">

<listeners>

      <listener class-name="com.sz.listeners.MyAnnotationsTransformer"/>

      <listener class-name="org.uncommons.reportng.HTMLReporter"/>

      <listener class-name="org.uncommons.reportng.JUnitXMLReporter"/>

  </listeners>

  

   <test verbose="10" name="USER BOOKING FLOW" preserve-order="true">

    <classes>

    <class name="com.sz.desktop.tests.DesktopUserBookingFlow"></class>

    </classes>

    </test>

</suite>





public class MyAnnotationsTransformer implements IAnnotationTransformer {

public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) {

if(testCondition(...)){

annotation.setEnabled(true);

}else{

annotation.setEnabled(false);

}

}




Test Class :


public class DesktopUserBookingFlow extends DesktopSetUp {

protected static Properties prop = new Properties();

@Test(testName="Desktop001_Login",enabled=true)

public void Desktop001_Login(){

HomePageImpl.clickOnLoginLink(driver);

LoginPageImpl.typeUsername(driver, "");

LoginPageImpl.typePassword(driver, "");

LoginPageImpl.clickLoginButton(driver);

}

@Test(testName="Desktop002_Search()",enabled=true)

public void Desktop002_Search(){

HomePageImpl.typeCityInSearchField(driver, "");

HomePageImpl.clickOnSearchButton(driver);

}



Testng failed to disable the test and through Null exception.


--
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.

--
You received this message because you are subscribed to a topic in the Google Groups "testng-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/testng-users/617xzLrgZoA/unsubscribe.
To unsubscribe from this group and all its topics, 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.

--
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: Disabled testcases dynamically

⇜Krishnan Mahadevan⇝
Your NPE is arising out of your annotation transformer.
Please share your complete annotation transformer's code. Your stubbed code that you shared earlier isn't going to be of much help.

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 Thu, Feb 9, 2017 at 10:28 AM, shakun tyagi <[hidden email]> wrote:
Hi Krishnan,


java.lang.NullPointerException

at com.sz.listeners.MyAnnotationsTransformer.transform(MyAnnotationsTransformer.java:19)

at org.testng.internal.annotations.JDK15AnnotationFinder.transform(JDK15AnnotationFinder.java:113)

at org.testng.internal.annotations.JDK15AnnotationFinder.findAnnotation(JDK15AnnotationFinder.java:179)

at org.testng.internal.annotations.JDK15AnnotationFinder.findAnnotation(JDK15AnnotationFinder.java:103)

at org.testng.internal.TestNGClassFinder.isTestNGClass(TestNGClassFinder.java:223)

at org.testng.internal.TestNGClassFinder.<init>(TestNGClassFinder.java:107)

at org.testng.TestRunner.initMethods(TestRunner.java:409)

at org.testng.TestRunner.init(TestRunner.java:235)

at org.testng.TestRunner.init(TestRunner.java:205)

at org.testng.TestRunner.<init>(TestRunner.java:153)

at org.testng.SuiteRunner$DefaultTestRunnerFactory.newTestRunner(SuiteRunner.java:536)

at org.testng.SuiteRunner.init(SuiteRunner.java:159)

at org.testng.SuiteRunner.<init>(SuiteRunner.java:113)

at org.testng.TestNG.createSuiteRunner(TestNG.java:1299)

at org.testng.TestNG.createSuiteRunners(TestNG.java:1286)

at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)

at org.testng.TestNG.run(TestNG.java:1057)

at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:281)

at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:75)

at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:121)

at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:290)

at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:242)

at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:121)


Thanks

Shakun


On Wed, Feb 8, 2017 at 7:04 PM, ⇜Krishnan Mahadevan⇝ <[hidden email]> wrote:
Stacktrace please ?

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 Wed, Feb 8, 2017 at 2:59 PM, shakun tyagi <[hidden email]> wrote:
I am trying to disable test cases dynamically using IAnnotationTransformer, 

testng.xml 

<?xml version="1.0" encoding="UTF-8"?>

<suite name="SANITYDESKTOP" parallel="false" verbose="1">

<listeners>

      <listener class-name="com.sz.listeners.MyAnnotationsTransformer"/>

      <listener class-name="org.uncommons.reportng.HTMLReporter"/>

      <listener class-name="org.uncommons.reportng.JUnitXMLReporter"/>

  </listeners>

  

   <test verbose="10" name="USER BOOKING FLOW" preserve-order="true">

    <classes>

    <class name="com.sz.desktop.tests.DesktopUserBookingFlow"></class>

    </classes>

    </test>

</suite>





public class MyAnnotationsTransformer implements IAnnotationTransformer {

public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) {

if(testCondition(...)){

annotation.setEnabled(true);

}else{

annotation.setEnabled(false);

}

}




Test Class :


public class DesktopUserBookingFlow extends DesktopSetUp {

protected static Properties prop = new Properties();

@Test(testName="Desktop001_Login",enabled=true)

public void Desktop001_Login(){

HomePageImpl.clickOnLoginLink(driver);

LoginPageImpl.typeUsername(driver, "");

LoginPageImpl.typePassword(driver, "");

LoginPageImpl.clickLoginButton(driver);

}

@Test(testName="Desktop002_Search()",enabled=true)

public void Desktop002_Search(){

HomePageImpl.typeCityInSearchField(driver, "");

HomePageImpl.clickOnSearchButton(driver);

}



Testng failed to disable the test and through Null exception.


--
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.

--
You received this message because you are subscribed to a topic in the Google Groups "testng-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/testng-users/617xzLrgZoA/unsubscribe.
To unsubscribe from this group and all its topics, 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.

--
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.

--
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: Disabled testcases dynamically

shakun tyagi
Krishnan,

Here is the transformer class,



import java.lang.reflect.Constructor;

import java.lang.reflect.Method;


import org.testng.IAnnotationTransformer;

import org.testng.annotations.ITestAnnotation;


import com.sz.utils.Utils;


public class MyAnnotationsTransformer implements IAnnotationTransformer {

public void transform(ITestAnnotation annotation, Class testClass, Constructor  testConstructor, Method testMethod) {

try {

if(Utils.readExcelFile(testClass.getName(), testMethod.getName())){

annotation.setEnabled(true);

}else{

annotation.setEnabled(false);

}

} catch (Exception e) {

e.printStackTrace();

}

}


}


Thanks

Shakun


On Thu, Feb 9, 2017 at 10:45 AM, ⇜Krishnan Mahadevan⇝ <[hidden email]> wrote:
Your NPE is arising out of your annotation transformer.
Please share your complete annotation transformer's code. Your stubbed code that you shared earlier isn't going to be of much help.

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 Thu, Feb 9, 2017 at 10:28 AM, shakun tyagi <[hidden email]> wrote:
Hi Krishnan,


java.lang.NullPointerException

at com.sz.listeners.MyAnnotationsTransformer.transform(MyAnnotationsTransformer.java:19)

at org.testng.internal.annotations.JDK15AnnotationFinder.transform(JDK15AnnotationFinder.java:113)

at org.testng.internal.annotations.JDK15AnnotationFinder.findAnnotation(JDK15AnnotationFinder.java:179)

at org.testng.internal.annotations.JDK15AnnotationFinder.findAnnotation(JDK15AnnotationFinder.java:103)

at org.testng.internal.TestNGClassFinder.isTestNGClass(TestNGClassFinder.java:223)

at org.testng.internal.TestNGClassFinder.<init>(TestNGClassFinder.java:107)

at org.testng.TestRunner.initMethods(TestRunner.java:409)

at org.testng.TestRunner.init(TestRunner.java:235)

at org.testng.TestRunner.init(TestRunner.java:205)

at org.testng.TestRunner.<init>(TestRunner.java:153)

at org.testng.SuiteRunner$DefaultTestRunnerFactory.newTestRunner(SuiteRunner.java:536)

at org.testng.SuiteRunner.init(SuiteRunner.java:159)

at org.testng.SuiteRunner.<init>(SuiteRunner.java:113)

at org.testng.TestNG.createSuiteRunner(TestNG.java:1299)

at org.testng.TestNG.createSuiteRunners(TestNG.java:1286)

at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)

at org.testng.TestNG.run(TestNG.java:1057)

at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:281)

at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:75)

at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:121)

at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:290)

at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:242)

at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:121)


Thanks

Shakun


On Wed, Feb 8, 2017 at 7:04 PM, ⇜Krishnan Mahadevan⇝ <[hidden email]> wrote:
Stacktrace please ?

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 Wed, Feb 8, 2017 at 2:59 PM, shakun tyagi <[hidden email]> wrote:
I am trying to disable test cases dynamically using IAnnotationTransformer, 

testng.xml 

<?xml version="1.0" encoding="UTF-8"?>

<suite name="SANITYDESKTOP" parallel="false" verbose="1">

<listeners>

      <listener class-name="com.sz.listeners.MyAnnotationsTransformer"/>

      <listener class-name="org.uncommons.reportng.HTMLReporter"/>

      <listener class-name="org.uncommons.reportng.JUnitXMLReporter"/>

  </listeners>

  

   <test verbose="10" name="USER BOOKING FLOW" preserve-order="true">

    <classes>

    <class name="com.sz.desktop.tests.DesktopUserBookingFlow"></class>

    </classes>

    </test>

</suite>





public class MyAnnotationsTransformer implements IAnnotationTransformer {

public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) {

if(testCondition(...)){

annotation.setEnabled(true);

}else{

annotation.setEnabled(false);

}

}




Test Class :


public class DesktopUserBookingFlow extends DesktopSetUp {

protected static Properties prop = new Properties();

@Test(testName="Desktop001_Login",enabled=true)

public void Desktop001_Login(){

HomePageImpl.clickOnLoginLink(driver);

LoginPageImpl.typeUsername(driver, "");

LoginPageImpl.typePassword(driver, "");

LoginPageImpl.clickLoginButton(driver);

}

@Test(testName="Desktop002_Search()",enabled=true)

public void Desktop002_Search(){

HomePageImpl.typeCityInSearchField(driver, "");

HomePageImpl.clickOnSearchButton(driver);

}



Testng failed to disable the test and through Null exception.


--
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.

--
You received this message because you are subscribed to a topic in the Google Groups "testng-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/testng-users/617xzLrgZoA/unsubscribe.
To unsubscribe from this group and all its topics, 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.

--
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.

--
You received this message because you are subscribed to a topic in the Google Groups "testng-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/testng-users/617xzLrgZoA/unsubscribe.
To unsubscribe from this group and all its topics, 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.

--
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: Disabled testcases dynamically

⇜Krishnan Mahadevan⇝

You shouldn't be accessing the testClass variable or the testMethod variable without a null check.

Your code is missing that check which is why you are seeing NullPointerException.

If you look at the Java docs of this interface you would realise that these objects would be non null based on where TestNG found your annotations.

Java docs : http://testng.org/javadocs/org/testng/IAnnotationTransformer.html


On Thu, Feb 9, 2017, 10:55 shakun tyagi <[hidden email]> wrote:
Krishnan,

Here is the transformer class,



import java.lang.reflect.Constructor;

import java.lang.reflect.Method;


import org.testng.IAnnotationTransformer;

import org.testng.annotations.ITestAnnotation;


import com.sz.utils.Utils;


public class MyAnnotationsTransformer implements IAnnotationTransformer {

public void transform(ITestAnnotation annotation, Class testClass, Constructor  testConstructor, Method testMethod) {

try {

if(Utils.readExcelFile(testClass.getName(), testMethod.getName())){

annotation.setEnabled(true);

}else{

annotation.setEnabled(false);

}

} catch (Exception e) {

e.printStackTrace();

}

}


}


Thanks

Shakun


On Thu, Feb 9, 2017 at 10:45 AM, ⇜Krishnan Mahadevan⇝ <[hidden email]> wrote:
Your NPE is arising out of your annotation transformer.
Please share your complete annotation transformer's code. Your stubbed code that you shared earlier isn't going to be of much help.

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 Thu, Feb 9, 2017 at 10:28 AM, shakun tyagi <[hidden email]> wrote:
Hi Krishnan,


java.lang.NullPointerException

at com.sz.listeners.MyAnnotationsTransformer.transform(MyAnnotationsTransformer.java:19)

at org.testng.internal.annotations.JDK15AnnotationFinder.transform(JDK15AnnotationFinder.java:113)

at org.testng.internal.annotations.JDK15AnnotationFinder.findAnnotation(JDK15AnnotationFinder.java:179)

at org.testng.internal.annotations.JDK15AnnotationFinder.findAnnotation(JDK15AnnotationFinder.java:103)

at org.testng.internal.TestNGClassFinder.isTestNGClass(TestNGClassFinder.java:223)

at org.testng.internal.TestNGClassFinder.<init>(TestNGClassFinder.java:107)

at org.testng.TestRunner.initMethods(TestRunner.java:409)

at org.testng.TestRunner.init(TestRunner.java:235)

at org.testng.TestRunner.init(TestRunner.java:205)

at org.testng.TestRunner.<init>(TestRunner.java:153)

at org.testng.SuiteRunner$DefaultTestRunnerFactory.newTestRunner(SuiteRunner.java:536)

at org.testng.SuiteRunner.init(SuiteRunner.java:159)

at org.testng.SuiteRunner.<init>(SuiteRunner.java:113)

at org.testng.TestNG.createSuiteRunner(TestNG.java:1299)

at org.testng.TestNG.createSuiteRunners(TestNG.java:1286)

at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)

at org.testng.TestNG.run(TestNG.java:1057)

at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:281)

at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:75)

at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:121)

at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:290)

at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:242)

at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:121)


Thanks

Shakun


On Wed, Feb 8, 2017 at 7:04 PM, ⇜Krishnan Mahadevan⇝ <[hidden email]> wrote:
Stacktrace please ?

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 Wed, Feb 8, 2017 at 2:59 PM, shakun tyagi <[hidden email]> wrote:
I am trying to disable test cases dynamically using IAnnotationTransformer, 

testng.xml 

<?xml version="1.0" encoding="UTF-8"?>

<suite name="SANITYDESKTOP" parallel="false" verbose="1">

<listeners>

      <listener class-name="com.sz.listeners.MyAnnotationsTransformer"/>

      <listener class-name="org.uncommons.reportng.HTMLReporter"/>

      <listener class-name="org.uncommons.reportng.JUnitXMLReporter"/>

  </listeners>

  

   <test verbose="10" name="USER BOOKING FLOW" preserve-order="true">

    <classes>

    <class name="com.sz.desktop.tests.DesktopUserBookingFlow"></class>

    </classes>

    </test>

</suite>





public class MyAnnotationsTransformer implements IAnnotationTransformer {

public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) {

if(testCondition(...)){

annotation.setEnabled(true);

}else{

annotation.setEnabled(false);

}

}




Test Class :


public class DesktopUserBookingFlow extends DesktopSetUp {

protected static Properties prop = new Properties();

@Test(testName="Desktop001_Login",enabled=true)

public void Desktop001_Login(){

HomePageImpl.clickOnLoginLink(driver);

LoginPageImpl.typeUsername(driver, "");

LoginPageImpl.typePassword(driver, "");

LoginPageImpl.clickLoginButton(driver);

}

@Test(testName="Desktop002_Search()",enabled=true)

public void Desktop002_Search(){

HomePageImpl.typeCityInSearchField(driver, "");

HomePageImpl.clickOnSearchButton(driver);

}



Testng failed to disable the test and through Null exception.


--
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.

--
You received this message because you are subscribed to a topic in the Google Groups "testng-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/testng-users/617xzLrgZoA/unsubscribe.
To unsubscribe from this group and all its topics, 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.

--
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.

--
You received this message because you are subscribed to a topic in the Google Groups "testng-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/testng-users/617xzLrgZoA/unsubscribe.
To unsubscribe from this group and all its topics, 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.

--
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.
--

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 [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: Disabled testcases dynamically

shakun tyagi
Krishnan,

thanks a lot, I completely missed that note in the java doc.


Thanks
Shakun


On Thu, Feb 9, 2017 at 12:10 PM, ⇜Krishnan Mahadevan⇝ <[hidden email]> wrote:

You shouldn't be accessing the testClass variable or the testMethod variable without a null check.

Your code is missing that check which is why you are seeing NullPointerException.

If you look at the Java docs of this interface you would realise that these objects would be non null based on where TestNG found your annotations.

Java docs : http://testng.org/javadocs/org/testng/IAnnotationTransformer.html


On Thu, Feb 9, 2017, 10:55 shakun tyagi <[hidden email]> wrote:
Krishnan,

Here is the transformer class,



import java.lang.reflect.Constructor;

import java.lang.reflect.Method;


import org.testng.IAnnotationTransformer;

import org.testng.annotations.ITestAnnotation;


import com.sz.utils.Utils;


public class MyAnnotationsTransformer implements IAnnotationTransformer {

public void transform(ITestAnnotation annotation, Class testClass, Constructor  testConstructor, Method testMethod) {

try {

if(Utils.readExcelFile(testClass.getName(), testMethod.getName())){

annotation.setEnabled(true);

}else{

annotation.setEnabled(false);

}

} catch (Exception e) {

e.printStackTrace();

}

}


}


Thanks

Shakun


On Thu, Feb 9, 2017 at 10:45 AM, ⇜Krishnan Mahadevan⇝ <[hidden email]> wrote:
Your NPE is arising out of your annotation transformer.
Please share your complete annotation transformer's code. Your stubbed code that you shared earlier isn't going to be of much help.

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 Thu, Feb 9, 2017 at 10:28 AM, shakun tyagi <[hidden email]> wrote:
Hi Krishnan,


java.lang.NullPointerException

at com.sz.listeners.MyAnnotationsTransformer.transform(MyAnnotationsTransformer.java:19)

at org.testng.internal.annotations.JDK15AnnotationFinder.transform(JDK15AnnotationFinder.java:113)

at org.testng.internal.annotations.JDK15AnnotationFinder.findAnnotation(JDK15AnnotationFinder.java:179)

at org.testng.internal.annotations.JDK15AnnotationFinder.findAnnotation(JDK15AnnotationFinder.java:103)

at org.testng.internal.TestNGClassFinder.isTestNGClass(TestNGClassFinder.java:223)

at org.testng.internal.TestNGClassFinder.<init>(TestNGClassFinder.java:107)

at org.testng.TestRunner.initMethods(TestRunner.java:409)

at org.testng.TestRunner.init(TestRunner.java:235)

at org.testng.TestRunner.init(TestRunner.java:205)

at org.testng.TestRunner.<init>(TestRunner.java:153)

at org.testng.SuiteRunner$DefaultTestRunnerFactory.newTestRunner(SuiteRunner.java:536)

at org.testng.SuiteRunner.init(SuiteRunner.java:159)

at org.testng.SuiteRunner.<init>(SuiteRunner.java:113)

at org.testng.TestNG.createSuiteRunner(TestNG.java:1299)

at org.testng.TestNG.createSuiteRunners(TestNG.java:1286)

at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)

at org.testng.TestNG.run(TestNG.java:1057)

at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:281)

at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:75)

at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:121)

at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:290)

at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:242)

at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:121)


Thanks

Shakun


On Wed, Feb 8, 2017 at 7:04 PM, ⇜Krishnan Mahadevan⇝ <[hidden email]> wrote:
Stacktrace please ?

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 Wed, Feb 8, 2017 at 2:59 PM, shakun tyagi <[hidden email]> wrote:
I am trying to disable test cases dynamically using IAnnotationTransformer, 

testng.xml 

<?xml version="1.0" encoding="UTF-8"?>

<suite name="SANITYDESKTOP" parallel="false" verbose="1">

<listeners>

      <listener class-name="com.sz.listeners.MyAnnotationsTransformer"/>

      <listener class-name="org.uncommons.reportng.HTMLReporter"/>

      <listener class-name="org.uncommons.reportng.JUnitXMLReporter"/>

  </listeners>

  

   <test verbose="10" name="USER BOOKING FLOW" preserve-order="true">

    <classes>

    <class name="com.sz.desktop.tests.DesktopUserBookingFlow"></class>

    </classes>

    </test>

</suite>





public class MyAnnotationsTransformer implements IAnnotationTransformer {

public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) {

if(testCondition(...)){

annotation.setEnabled(true);

}else{

annotation.setEnabled(false);

}

}




Test Class :


public class DesktopUserBookingFlow extends DesktopSetUp {

protected static Properties prop = new Properties();

@Test(testName="Desktop001_Login",enabled=true)

public void Desktop001_Login(){

HomePageImpl.clickOnLoginLink(driver);

LoginPageImpl.typeUsername(driver, "");

LoginPageImpl.typePassword(driver, "");

LoginPageImpl.clickLoginButton(driver);

}

@Test(testName="Desktop002_Search()",enabled=true)

public void Desktop002_Search(){

HomePageImpl.typeCityInSearchField(driver, "");

HomePageImpl.clickOnSearchButton(driver);

}



Testng failed to disable the test and through Null exception.


--
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.

--
You received this message because you are subscribed to a topic in the Google Groups "testng-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/testng-users/617xzLrgZoA/unsubscribe.
To unsubscribe from this group and all its topics, 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.

--
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.

--
You received this message because you are subscribed to a topic in the Google Groups "testng-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/testng-users/617xzLrgZoA/unsubscribe.
To unsubscribe from this group and all its topics, 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.

--
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.
--

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 a topic in the Google Groups "testng-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/testng-users/617xzLrgZoA/unsubscribe.
To unsubscribe from this group and all its topics, 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.

--
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...