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