1 Reply Latest reply on Dec 10, 2013 4:50 AM by Juraj Húska

    TakesScreenshot RemoteWebDriver

    Rafael Pestano Novice

      Hi guys,

      is it possible to take screenshot with remote Werbdriver?

       

      When i run my tests locally the screnshots are taken but remotelly i got this exception:

       

      0mjava.lang.RuntimeException: unexpected invocation exception during invocation of org.openqa.selenium.TakesScreenshot#getScreenshotAs(), on target 'RemoteWebDriver: firefox on XP (48ddd8bf-4960-40be-b711-9bbad2883b8c)': org.openqa.selenium.remote.RemoteWebDriver.getScreenshotAs(org.openqa.selenium.OutputType)
           at org.jboss.arquillian.graphene.proxy.GrapheneProxyHandler.invokeReal(GrapheneProxyHandler.java:135)
           at org.jboss.arquillian.graphene.proxy.GrapheneContextualHandler$1.invoke(GrapheneContextualHandler.java:159)
           at org.jboss.arquillian.graphene.enricher.SearchContextInterceptor.intercept(SearchContextInterceptor.java:50)
           at org.jboss.arquillian.graphene.proxy.InvocationContextImpl.invoke(InvocationContextImpl.java:87)
           at org.jboss.arquillian.graphene.enricher.StaleElementInterceptor$1.apply(StaleElementInterceptor.java:48)
           at org.jboss.arquillian.graphene.enricher.StaleElementInterceptor$1.apply(StaleElementInterceptor.java:44)
           at org.openqa.selenium.support.ui.FluentWait$1.apply(FluentWait.java:177)
           at org.openqa.selenium.support.ui.FluentWait$1.apply(FluentWait.java:175)
           at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:208)
           at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:175)
           at org.jboss.arquillian.graphene.wait.WebDriverWaitImpl.until(WebDriverWaitImpl.java:87)
           at org.jboss.arquillian.graphene.enricher.StaleElementInterceptor.intercept(StaleElementInterceptor.java:44)
           at org.jboss.arquillian.graphene.proxy.InvocationContextImpl.invoke(InvocationContextImpl.java:87)
           at org.jboss.arquillian.graphene.proxy.GrapheneContextualHandler$2.call(GrapheneContextualHandler.java:209)
           at org.jboss.arquillian.graphene.context.BrowserActions.performAction(BrowserActions.java:62)
           at org.jboss.arquillian.graphene.proxy.GrapheneContextualHandler.invoke(GrapheneContextualHandler.java:205)
           at $Proxy42.getScreenshotAs(Unknown Source)
           at com.procergs.test.functional.ScreenshotTestRule$1.captureScreenshot(ScreenshotTestRule.java:44)
           at com.procergs.test.functional.ScreenshotTestRule$1.evaluate(ScreenshotTestRule.java:37)
           at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
           at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
           at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
           at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
           at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
           at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
           at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
           at org.jboss.arquillian.junit.Arquillian$2.evaluate(Arquillian.java:185)
           at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:314)
           at org.jboss.arquillian.junit.Arquillian.access$100(Arquillian.java:46)
           at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:199)
           at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
           at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:147)
           at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:264)
           at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:153)
           at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:124)
           at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:200)
           at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:153)
           at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
      Caused by: java.lang.NoSuchMethodException: org.openqa.selenium.remote.RemoteWebDriver.getScreenshotAs(org.openqa.selenium.OutputType)
           at java.lang.Class.getDeclaredMethod(Class.java:1954)
           at org.jboss.arquillian.graphene.proxy.GrapheneProxyHandler.invokeReal(GrapheneProxyHandler.java:124)
               ... 37 more

      i got i bt confuse with [ARQGRA-256] Graphene RemoteWebDriver doesn't support augmentation properly - JBoss Issue Tracker whether it is possible or not.

       

      I think its not so relevant but im using junit rule to take the screenshot, here is some code:

       

      public class ScreenshotTestRule implements MethodRule {

       

          private final File screenshotDir = new File("target/screenshots/");

          TakesScreenshot takesScreenshot;

       

       

          public ScreenshotTestRule(TakesScreenshot takesScreenshot) {

              this.takesScreenshot = takesScreenshot;

          }

       

          public Statement apply(final Statement statement, final FrameworkMethod frameworkMethod, final Object o) {

              return new Statement() {

                  @Override

                  public void evaluate() throws Throwable {

                      try {

                          statement.evaluate();

                      } catch (Throwable t) {

                          captureScreenshot(frameworkMethod.getName());

                          throw t; // rethrow to allow the failure to be reported to JUnit

                      }

                  }

       

                  public void captureScreenshot(String fileName) {

                      try {

                          File tempFile = takesScreenshot.getScreenshotAs(OutputType.FILE);

                          screenshotDir.mkdirs();

                          File screenshotFile = new File(screenshotDir, "screenshot-"+fileName + ".png");

                          FileUtils.copyFile(tempFile, screenshotFile);

                      } catch (Exception e) {

                          e.printStackTrace();

                      }

                  }

              };

          }

      }

       

      and here is how i setup it:

          @Rule

          public static ScreenshotTestRule screenshotTestRule;

       

      @BeforeClass

          public static void initScreenShoter(){

         screenshotTestRule = new ScreenshotTestRule((TakesScreenshot) GrapheneContext.getContextFor(Default.class).getWebDriver(TakesScreenshot.class));

              // Augmenter doesnt help either

              //WebDriver augmentedDriver = new Augmenter().augment(GrapheneContext.getContextFor(Default.class).getWebDriver(TakesScreenshot.class));

              //screenshotTestRule = new ScreenshotTestRule((TakesScreenshot) augmentedDriver);

          }