how to send parameter 'ITestResult result' in testng xml file

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

how to send parameter 'ITestResult result' in testng xml file

Anda Spa
Hello

I want to know how to write the parameter result in my testng.xml file:

 

    @AfterSuite(alwaysRun = true)
    public void afterSuite(ITestResult result) throws EmailException, FileNotFoundException, IOException {
        // generate report
        // send the report to email
        try {
            System.out.println("result of suite  " + result.getStatus() + " result " + result.getTestName());

            if (result.isSuccess()) {

                SendEmailAtachament.SendEmail("test", "test", "Test Cases Passed", pathFile);
            } else {
                SendEmailAtachament.SendEmail("test", "test", "Test Cases Failed", pathFile);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }

    }

In my result file you see:

Exception
java.lang.IllegalArgumentException: wrong number of arguments at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84) at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:308) at org.testng.SuiteRunner.run(SuiteRunner.java:240) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224) at org.testng.TestNG.runSuitesLocally(TestNG.java:1149) at org.testng.TestNG.run(TestNG.java:1057) at org.testng.TestNG.privateMain(TestNG.java:1364) at org.testng.TestNG.main(TestNG.java:1333)




Any hint would be appreciated.

Thanks,


--
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 send parameter 'ITestResult result' in testng xml file

Krishnan Mahadevan
What exactly are you trying to do ? Please elaborate ?

Native injection in TestNG (what you are trying to do is called Native Injection) is supported as per the table here : http://testng.org/doc/documentation-main.html#native-dependency-injection

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 Tue, Jan 30, 2018 at 3:13 PM, <[hidden email]> wrote:
Hello

I want to know how to write the parameter result in my testng.xml file:

 

    @AfterSuite(alwaysRun = true)
    public void afterSuite(ITestResult result) throws EmailException, FileNotFoundException, IOException {
        // generate report
        // send the report to email
        try {
            System.out.println("result of suite  " + result.getStatus() + " result " + result.getTestName());

            if (result.isSuccess()) {

                SendEmailAtachament.SendEmail("test", "test", "Test Cases Passed", pathFile);
            } else {
                SendEmailAtachament.SendEmail("test", "test", "Test Cases Failed", pathFile);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }

    }

In my result file you see:

Exception
java.lang.IllegalArgumentException: wrong number of arguments at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84) at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:308) at org.testng.SuiteRunner.run(SuiteRunner.java:240) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224) at org.testng.TestNG.runSuitesLocally(TestNG.java:1149) at org.testng.TestNG.run(TestNG.java:1057) at org.testng.TestNG.privateMain(TestNG.java:1364) at org.testng.TestNG.main(TestNG.java:1333)




Any hint would be appreciated.

Thanks,


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

Re: how to send parameter 'ITestResult result' in testng xml file

Anda Spa
In reply to this post by Anda Spa
in my XML configuration file I want to add the parameter for afterSuite method and I don't know how.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Windows10Chrome62CreezContNou" thread-count="2" verbose="2">

    
    <test name="LoginClientLider1">
        <parameter name="url" value="http://clientlider.speedsites.ro/?page=checkout#register" />
        <parameter name="email" value="[hidden email]" />
        <parameter name="parola" value="AutNume4" />
        <classes>
            <class name="org.contentspeed.automationtesting.Lider.CreareContNouTest"/>
        </classes>
    </test>
    
    
    <test name="LoginClientLider2">
        <parameter name="url" value="" />
        <parameter name="email" value="" />
        <parameter name="parola" value="dana" />
        <classes>
            <class name="org.contentspeed.automationtesting.Lider.CreareContNouTest"/>
        </classes>
    </test>
    
     <parameter name="result" value="result.getStatus()" />
  </suite>

What value must be set for the last parameter from xml file?


Thanks again






marți, 30 ianuarie 2018, 12:17:58 UTC+2, [hidden email] a scris:
Hello

I want to know how to write the parameter result in my testng.xml file:

 

    @AfterSuite(alwaysRun = true)
    public void afterSuite(ITestResult result) throws EmailException, FileNotFoundException, IOException {
        // generate report
        // send the report to email
        try {
            System.out.println("result of suite  " + result.getStatus() + " result " + result.getTestName());

            if (result.isSuccess()) {

                SendEmailAtachament.SendEmail("test", "test", "Test Cases Passed", pathFile);
            } else {
                SendEmailAtachament.SendEmail("test", "test", "Test Cases Failed", pathFile);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }

    }

In my result file you see:

Exception
java.lang.IllegalArgumentException: wrong number of arguments at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84) at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:308) at org.testng.SuiteRunner.run(SuiteRunner.java:240) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224) at org.testng.TestNG.runSuitesLocally(TestNG.java:1149) at org.testng.TestNG.run(TestNG.java:1057) at org.testng.TestNG.privateMain(TestNG.java:1364) at org.testng.TestNG.main(TestNG.java:1333)




Any hint would be appreciated.

Thanks,


--
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 send parameter 'ITestResult result' in testng xml file

Anda Spa
In reply to this post by Anda Spa
My final aim is to send emails after that my suite runs.

I think that the simplest method is to implement the listener.

Thanks again,


marți, 30 ianuarie 2018, 12:17:58 UTC+2, [hidden email] a scris:
Hello

I want to know how to write the parameter result in my testng.xml file:

 

    @AfterSuite(alwaysRun = true)
    public void afterSuite(ITestResult result) throws EmailException, FileNotFoundException, IOException {
        // generate report
        // send the report to email
        try {
            System.out.println("result of suite  " + result.getStatus() + " result " + result.getTestName());

            if (result.isSuccess()) {

                SendEmailAtachament.SendEmail("test", "test", "Test Cases Passed", pathFile);
            } else {
                SendEmailAtachament.SendEmail("test", "test", "Test Cases Failed", pathFile);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }

    }

In my result file you see:

Exception
java.lang.IllegalArgumentException: wrong number of arguments at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84) at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:308) at org.testng.SuiteRunner.run(SuiteRunner.java:240) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224) at org.testng.TestNG.runSuitesLocally(TestNG.java:1149) at org.testng.TestNG.run(TestNG.java:1057) at org.testng.TestNG.privateMain(TestNG.java:1364) at org.testng.TestNG.main(TestNG.java:1333)




Any hint would be appreciated.

Thanks,


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