How to capture information for skipped tests

classic Classic list List threaded Threaded
5 messages Options
SPS
Reply | Threaded
Open this post in threaded view
|

How to capture information for skipped tests

SPS
Hello all,
I need some help on how to capture information when test skips.I want to capture dataRow for my reporting purpose when  testB skips on failure of testA. Now it reports as null for testB in  my listener. If somebody can help me resolve this, that will be great

Thanks

public classA {


public classA(){
  dataRow = 1;
}


@Test
public void testA(){
   Reporter.getcurrentTestResult().setAttribute("datrow",datarow)
}

@Test { dependson ="testA"}
public void testB(){
   Reporter.getcurrentTestResult().setAttribute("datrow",datarow)
}



}

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

Re: How to capture information for skipped tests

Krishnan Mahadevan
Sneha,

You should be able to get this done by plugging in an implementation for org.testng.ITestListener (TestNG Listener) to your test.

You can learn more about listeners by referring to this blog post of mine :



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 Sun, Aug 7, 2016 at 5:23 PM, SPS <[hidden email]> wrote:
Hello all,
I need some help on how to capture information when test skips.I want to capture dataRow for my reporting purpose when  testB skips on failure of testA. Now it reports as null for testB in  my listener. If somebody can help me resolve this, that will be great

Thanks

public classA {


public classA(){
  dataRow = 1;
}


@Test
public void testA(){
   Reporter.getcurrentTestResult().setAttribute("datrow",datarow)
}

@Test { dependson ="testA"}
public void testB(){
   Reporter.getcurrentTestResult().setAttribute("datrow",datarow)
}



}

--
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.
SPS
Reply | Threaded
Open this post in threaded view
|

Re: How to capture information for skipped tests

SPS
In reply to this post by SPS
Yeah, I try to gather information in listener. the problem is if testA fails then testB skips. TestResult object for testB has datarow as null. we want data row as 1. We use factory method as datarow indicates the data lines

On Sunday, August 7, 2016 at 6:53:14 AM UTC-5, SPS wrote:
Hello all,
I need some help on how to capture information when test skips.I want to capture dataRow for my reporting purpose when  testB skips on failure of testA. Now it reports as null for testB in  my listener. If somebody can help me resolve this, that will be great

Thanks

public classA {


public classA(){
  dataRow = 1;
}


@Test
public void testA(){
   Reporter.getcurrentTestResult().setAttribute("datrow",datarow)
}

@Test { dependson ="testA"}
public void testB(){
   Reporter.getcurrentTestResult().setAttribute("datrow",datarow)
}



}

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

Re: How to capture information for skipped tests

Krishnan Mahadevan
Sneha,
Since you mention factories, you can do something like below :

Define an interface which will expose the data that is passed to your test class instance.
Have your test class implement this interface so that it can be invoked from outside.
In your onSkipped() implementation of your listener you can now invoke this interface method to get this data.
Here's a sample implementation which shows what I am talking about.

public interface RowInfo {
int getRowId();
}
@Listeners (InfoOnSkippedTests.TestDetailsListener.class)
public class InfoOnSkippedTests implements RowInfo {
private int rowId;

@Factory (dataProvider = "dp")
public InfoOnSkippedTests(int rowId) {
this.rowId = rowId;
}

@DataProvider (name = "dp")
public static Object[][] getData() {
return new Object[][] {
{1},
{2}
};
}

@Test
public void testMethod1() {
System.err.println("Hello from testMethod1()");
throw new RuntimeException("Failing testMethod1()");
}

@Test (dependsOnMethods = "testMethod1")
public void testMethod2() {
System.err.println("This is never going to be executed");

}

@Override
public int getRowId() {
return rowId;
}

public static class TestDetailsListener extends TestListenerAdapter {

@Override
public void onTestSkipped(ITestResult result) {
Object instance = result.getMethod().getInstance();
if (! (instance instanceof RowInfo)) {
return;
}
int rowId = ((RowInfo) instance).getRowId();
System.err.println("Test Method " + result.getMethod().getConstructorOrMethod().getName()
            + "() skipped for rowId: " + rowId);
}
}
}

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 Mon, Aug 8, 2016 at 1:48 AM, SPS <[hidden email]> wrote:
Yeah, I try to gather information in listener. the problem is if testA fails then testB skips. TestResult object for testB has datarow as null. we want data row as 1. We use factory method as datarow indicates the data lines

On Sunday, August 7, 2016 at 6:53:14 AM UTC-5, SPS wrote:
Hello all,
I need some help on how to capture information when test skips.I want to capture dataRow for my reporting purpose when  testB skips on failure of testA. Now it reports as null for testB in  my listener. If somebody can help me resolve this, that will be great

Thanks

public classA {


public classA(){
  dataRow = 1;
}


@Test
public void testA(){
   Reporter.getcurrentTestResult().setAttribute("datrow",datarow)
}

@Test { dependson ="testA"}
public void testB(){
   Reporter.getcurrentTestResult().setAttribute("datrow",datarow)
}



}

--
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.
SPS
Reply | Threaded
Open this post in threaded view
|

Re: How to capture information for skipped tests

SPS
In reply to this post by SPS
Thanks Krishnan. It works.

On Sunday, August 7, 2016 at 6:53:14 AM UTC-5, SPS wrote:
Hello all,
I need some help on how to capture information when test skips.I want to capture dataRow for my reporting purpose when  testB skips on failure of testA. Now it reports as null for testB in  my listener. If somebody can help me resolve this, that will be great

Thanks

public classA {


public classA(){
  dataRow = 1;
}


@Test
public void testA(){
   Reporter.getcurrentTestResult().setAttribute("datrow",datarow)
}

@Test { dependson ="testA"}
public void testB(){
   Reporter.getcurrentTestResult().setAttribute("datrow",datarow)
}



}

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