Quantcast

error if I pass "ITestResult" to @AfterClass

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

error if I pass "ITestResult" to @AfterClass

goran gasparini
Hi guys,

Originally,  methods launchBrowser and closeBrowser where included in the @BeforeMethod/@AfterMethod ( and working just fine) .But I need to include these actions in the @BeforeClass/@AfterClass

But, if I change this , the close browser causes an error

Seems that the parameter ITestResult  (public void closeBrowser(ITestResult result) throws IOException ) is not recognized but I dont understand why?!

Any help? I'm not a java guru :-)


CODE:

@BeforeSuite
   @Parameters("appURL")
   public void setEnv(
         @Optional("http://aaa.bbb.ccc") String appURL) {
      SelTestCase.appURL = appURL;
      Reporter.log("beforesuite  " );
   }

   @BeforeClass()
   @Parameters("browser")
   public void launchBrowser(@Optional("FF") String browser) throws Exception {

      if (browser.equalsIgnoreCase("Chrome")) {
         System.setProperty("webdriver.chrome.driver",);
         driver = new ChromeDriver();
      } else if (browser.equalsIgnoreCase("FF")) {
         driver = new FirefoxDriver(Help.getFirefoxProfile() );
         driver.get(appURL);
      } else {
         driver =new InternetExplorerDriver();
         driver.get(appURL);
         Reporter.log("Start browser beforeclass" );
        
      }
   }

  
   @AfterClass()
   public void closeBrowser(ITestResult result) throws IOException {
      System.out.print("AFTER CLASS->close browser");
      if (!result.isSuccess()) {
         File imageFile = ((TakesScreenshot) new Augmenter().augment(driver))
               .getScreenshotAs(OutputType.FILE);
         String failureImageFileName = result.getMethod().getMethodName()+ new SimpleDateFormat("MM-dd-yyyy_HH-ss").format(new GregorianCalendar().getTime())
               + ".png";
         File failureImageFile = new File(failureImageFileName);
         FileUtils.moveFile(imageFile, failureImageFile);
         System.out.print(failureImageFileName);
         Reporter.log("Close browser afterclass " );
      }
     
      driver.close();
      Reporter.log("Close browser afterclass " );
   }
  
}



ERROR MESSAGE:

java.lang.IllegalArgumentException: wrong number of arguments
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   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.internal.TestMethodWorker.invokeAfterClassMethods(TestMethodWorker.java:225)
   at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:114)
   at org.testng.TestRunner.privateRun(TestRunner.java:767)
   at org.testng.TestRunner.run(TestRunner.java:617)
   at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
   at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
   at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
   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.remote.RemoteTestNG.run(RemoteTestNG.java:111)
   at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
   at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)

--
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 http://groups.google.com/group/testng-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: error if I pass "ITestResult" to @AfterClass

Petter Isberg
Hi!

According to the TestNG documentation about native dependency injection (http://testng.org/doc/documentation-main.html#native-dependency-injection) only @AfterMethod takes the ITestResult parameter. This seems to be because the ITestResult contains information about the executed test method. When you try to get the isSucess result in @AfterClass there is no telling from which test method you want the result. The documentation however states that an @AfterClass method can take a XMLTest parameter, unless you want to have an instance variable in your class letting you know of the result (can be set in @AfterMethod for example), I guess you can get the desired information out of the XMLTest object.

I guess you have to try it. Let us know if it works :)

Regards
Petter

--
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 http://groups.google.com/group/testng-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: error if I pass "ITestResult" to @AfterClass

Suba Narayanan
Hi,

 I've added ITestResult parameter to the @AfterMethod,and driver.quit() to @AfterClass. No Error and the screenshot was taken in case of failure.

Thanks,
Suba





On Sunday, May 26, 2013 at 1:53:11 PM UTC+5:30, Petter Isberg wrote:
Hi!

According to the TestNG documentation about native dependency injection (<a href="http://testng.org/doc/documentation-main.html#native-dependency-injection" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Ftestng.org%2Fdoc%2Fdocumentation-main.html%23native-dependency-injection\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGezhC1wUSDaui0PSu9qt8csftgTA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Ftestng.org%2Fdoc%2Fdocumentation-main.html%23native-dependency-injection\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGezhC1wUSDaui0PSu9qt8csftgTA&#39;;return true;">http://testng.org/doc/documentation-main.html#native-dependency-injection) only @AfterMethod takes the ITestResult parameter. This seems to be because the ITestResult contains information about the executed test method. When you try to get the isSucess result in @AfterClass there is no telling from which test method you want the result. The documentation however states that an @AfterClass method can take a XMLTest parameter, unless you want to have an instance variable in your class letting you know of the result (can be set in @AfterMethod for example), I guess you can get the desired information out of the XMLTest object.

I guess you have to try it. Let us know if it works :)

Regards
Petter

--
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: error if I pass "ITestResult" to @AfterClass

⇜Krishnan Mahadevan⇝
Suba,

Since you revived a nearly 3 year old thread, and since you haven't added much of context in terms of what information you are trying to add to this thread, may I request you to please add some sample source code which would show what you have done ?
That way in the future, if anyone stumbles into this thread they would get some better context in terms of how this was solved.


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 7:36 PM, Suba Narayanan <[hidden email]> wrote:
Hi,

 I've added ITestResult parameter to the @AfterMethod,and driver.quit() to @AfterClass. No Error and the screenshot was taken in case of failure.

Thanks,
Suba





On Sunday, May 26, 2013 at 1:53:11 PM UTC+5:30, Petter Isberg wrote:
Hi!

According to the TestNG documentation about native dependency injection (http://testng.org/doc/documentation-main.html#native-dependency-injection) only @AfterMethod takes the ITestResult parameter. This seems to be because the ITestResult contains information about the executed test method. When you try to get the isSucess result in @AfterClass there is no telling from which test method you want the result. The documentation however states that an @AfterClass method can take a XMLTest parameter, unless you want to have an instance variable in your class letting you know of the result (can be set in @AfterMethod for example), I guess you can get the desired information out of the XMLTest object.

I guess you have to try it. Let us know if it works :)

Regards
Petter

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