4 Replies Latest reply on Dec 10, 2013 4:51 AM by Juraj Húska

    graphene and screenshots on remote browsers

    kelly goedert Apprentice

      Hi,

       

      When I run my tests on my local machine using my local browser, I can take screenshots using this:

       

      WebDriver driver = new FirefoxDriver();
      driver.get("http://www.google.com/");
      File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
      FileUtils.copyFile(scrFile, new File("c:\\tmp\\screenshot.png"));

       

      and it works. Now, when I try to run the same tests on a selenium hub I get this error:

       

      java.lang.ClassCastException: org.openqa.selenium.remote.RemoteWebDriver$$EnhancerByGraphene$$afa97690 cannot be cast to org.openqa.selenium.TakesScreenshot
      

       

      I found this post http://rkchunduri.blogspot.com.br/2011/11/remotewebdriver-cannot-be-cast-to.html but with the solution presented here, if I run the tests locally I get this error


      java.lang.NullPointerException
      at java.util.logging.Logger.log(Logger.java:644)
      at org.openqa.selenium.remote.RemoteWebDriver.log(RemoteWebDriver.java:607)
      at org.openqa.selenium.chrome.ChromeDriver$$EnhancerByGraphene$$afebd4da.log()
       at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:541)
       at org.openqa.selenium.chrome.ChromeDriver$$EnhancerByGraphene$$afebd4da.execute()
       at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:569)
       at org.openqa.selenium.chrome.ChromeDriver$$EnhancerByGraphene$$afebd4da.execute()
       at org.openqa.selenium.chrome.ChromeDriver.getScreenshotAs(ChromeDriver.java:173)
       at org.openqa.selenium.chrome.ChromeDriver$$EnhancerByGraphene$$afebd4da.getScreenshotAs()
      

      And when I run them in the selenium hub I get

       

      Class org.jboss.arquillian.graphene.proxy.GrapheneProxyHandler can not access a member of class org.openqa.selenium.remote.RemoteWebDriver with modifiers "protected"
      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.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.enricher.SearchContextInterceptor.intercept(SearchContextInterceptor.java:50)
      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 org.jboss.arquillian.graphene.proxy.GrapheneContextualHandler.intercept(GrapheneContextualHandler.java:229)
      at org.openqa.selenium.remote.RemoteWebDriver$$EnhancerByGraphene$$ede7958d.execute(<generated>)
      at org.openqa.selenium.remote.RemoteExecuteMethod.execute(RemoteExecuteMethod.java:32)
      at org.openqa.selenium.remote.AddTakesScreenshot$1.invoke(AddTakesScreenshot.java:36)
      at org.openqa.selenium.remote.Augmenter$CompoundHandler.intercept(Augmenter.java:286)
      at org.openqa.selenium.remote.RemoteWebDriver$$EnhancerByGraphene$$ede7958d$$EnhancerByCGLIB$$9380a5cc.getScreenshotAs(<generated>)
      

      Can anybody help with this?

        • 1. Re: graphene and screenshots on remote browsers
          Karel Piwko Master

          Hi Kelly,

           

          that's interesting because Drone is auto Augmenting all remote browsers. Can you sharer arquillian.xml, test class and version of Drone/Graphene or pom.xml file?

           

          Thanks,

           

          Karel

          • 2. Re: Re: graphene and screenshots on remote browsers
            kelly goedert Apprentice

            Pom...

             

            Graphene version - 2.0.0.Final

            Drone version - 1.2.0.Final

             

            I am using cucumber for testing and this is the method that takes the screenshot

             

            @Quando("^tira um screenshot chamado (.*)$")
              public void takeScreenshot(String filename){
              Capabilities caps = ((RemoteWebDriver) browser).getCapabilities();
              String browserName = caps.getBrowserName();
              String browserVersion = caps.getVersion();
            
              WebDriver augmentedDriver = new Augmenter().augment(browser);
            
              File scrFile = ((TakesScreenshot)augmentedDriver).getScreenshotAs(OutputType.FILE);
              String outputName = null;
              if(browserName.contains("internet"))
              outputName = "target/shots/" + browserName + "/" + browserVersion + "/" + filename;
              else
              outputName = "target/shots/" + browserName + "/" + filename;
            
            
              File outputFile = new File(outputName);
              if(outputFile.exists())
              fail("Já existe um arquivo com o nome " + filename);
              else{
              try {
              FileUtils.copyFile(scrFile, new File(outputName));
              } catch (IOException e) {
              fail();
              e.printStackTrace();
              }
              }
              }
            

             

             

            If I change the augmented driver to the regular one, it works locally, but not on remote browsers.

             

            The arquillian.xml is as follows

             

            <arquillian xmlns="http://jboss.org/schema/arquillian" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
            
              <defaultProtocol type="Servlet 3.0"/>
            
              <container qualifier="JBOSS_AS_REMOTE_7.X" default="true">
              <configuration>
              <property name="managementPort">9999</property>
              </configuration>
              </container>
              <extension qualifier="webdriver">
              <property name="browser">chrome</property>
              <property name="chromeDriverBinary">/home/kelly/Downloads/chromedriver</property> 
              <property name="firefox_binary">/home/kelly/install/firefox-23/firefox/firefox</property>
              <property name="remoteAddress">http://10.1.1.247:4444/wd/hub</property>
              <property name="remote">false</property>
              <property name="version"></property>
              <property name="dimensions">1024x768</property> 
              </extension>
            
              <extension qualifier="cucumber">
              <property name="report">true</property>
              <property name="report-directory">target/cucumber-report</property>
              </extension>
            
              <engine>
              <property name="deploymentExportPath">target</property>
              </engine>
            
            
              <testResources>
              <testResource>
              <directory>src/test/resources</directory>
              </testResource>
              <testResource>
              <directory>src/main/webapp</directory>
              </testResource>
              </testResources>
            </arquillian>
            
            • 3. Re: graphene and screenshots on remote browsers
              Rafael Pestano Novice

              Hi there, i also have this issue: TakesScreenshot RemoteWebDriver

               

              my exception is a bit different but im not using Augmenter: Caused by: java.lang.NoSuchMethodException: org.openqa.selenium.remote.RemoteWebDriver.getScreenshotAs(org.openqa.selenium.OutputType)