2

We use Perfecto for testing our Mobile app. Our Automation code is generating exception in the step where we are trying to capture the screenshot of the Mobile screen.

We tried changing the versions of jars. Initially we had Selenium remote driver 2.48.2. We changed this to 2.53.1 and also updated all other dependent jars. With 2.48.2, we continued to get Browser unreachable exception and now with 2.53.1, we are getting timeout. I have included the exception details with version 2.48.2 (with a sample code piece). The exception with 2.53.1 has some credential details on it and I am not sure on how to share the same.

Exception detail

    org.openqa.selenium.remote.UnreachableBrowserException: Error communicating with the remote browser. It may have died.
Build info: version: '2.48.2', revision: '41bccdd10cf2c0560f637404c2d96164b67d9d67', time: '2015-10-09 13:08:06'

System info: host: 'WDAAS6302-E1087', ip: '10.86.78.84', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_172'
Driver info: driver.version: RemoteWebDriver
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:641)
    at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
    at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:206)
    at org.openqa.selenium.remote.RemoteWebDriver.getScreenshotAs(RemoteWebDriver.java:325)
    at reusable.ReusableFuncs.capture(ReusableFuncs.java:167)
    at automationFramework.Trial.main(Trial.java:160)
Caused by: java.lang.NullPointerException
    at org.openqa.selenium.remote.ErrorCodes.toStatus(ErrorCodes.java:256)
    at org.openqa.selenium.remote.JsonToBeanConverter.convert(JsonToBeanConverter.java:124)
    at org.openqa.selenium.remote.JsonToBeanConverter.convert(JsonToBeanConverter.java:42)
    at org.openqa.selenium.remote.http.JsonHttpResponseCodec.decode(JsonHttpResponseCodec.java:78)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:145)
    at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:67)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:620)
    ... 5 more

The exception is on the step - File source = ts.getScreenshotAs(OutputType.FILE);

Mobile automation is pretty new to us and we are finding it difficult to resolve the issue.

public synchronized String capture(AppiumDriver<MobileElement> driver,String screenShotName) throws IOException
    {
           TakesScreenshot ts = (TakesScreenshot)driver;

           String dest = System.getProperty("user.dir") +"\\ErrorScreenshots\\"+screenShotName+new SimpleDateFormat("yyyyMMdd_HHmm").format(new Date())+".png";
           System.out.println("destination is "+ dest);
           File source = ts.getScreenshotAs(OutputType.FILE);
           File destination = new File(dest);
           FileUtils.copyFile(source, destination);  
           destination = null;
           dest = resize(dest);
           destination = new File(dest);
           String encodedfile = null;
     try {
         FileInputStream fileInputStreamReader = new 
         FileInputStream(destination);
         byte[] bytes = new byte[(int)destination.length()];
         fileInputStreamReader.read(bytes);
         encodedfile = Base64.getEncoder().encodeToString(bytes);
         System.out.println(encodedfile);
     } catch (FileNotFoundException e) {
         e.printStackTrace();
     } catch (IOException e) {
         e.printStackTrace();
     }
  return "data:image/png;base64,"+  encodedfile;         

}
Himanshu
  • 79
  • 1
  • 6
  • Why to use _Selenium v2.48.2_ from `2015-10-09` almost half-a-decade older build? – undetected Selenium Feb 11 '19 at 17:45
  • @DebanjanB As I mentioned, we did upgrade the versions. There are some restriction with the client we work with. We use our own repository and the latest available version over there is 2.53.1. With this version, we get timeout exception – Himanshu Feb 11 '19 at 18:55

2 Answers2

0

I had raised a ticket with Perfecto support team and they suggested to add a new capability to get rid of time out.

capabilities.setCapability("host",”Cloud URL”);

Now with 2.53.1 and along with this newly added capability, we are able to capture the screenshot.

Himanshu
  • 79
  • 1
  • 6
0

I think you can try Experitest SeeTest for your mobile automation project It has inbuilt reporting mechanism which takes screenshot. It supports AppiumDriver in your case. You can have a look at the Experitest documentation

String screenshotPath = client.capture("CaptureScreenshot")

ScreenshotPath will hold the path to the captured screenshot

Carlos Cavero
  • 3,011
  • 5
  • 21
  • 41
Keerthana
  • 31
  • 4