Appium error 'Cannot read property 'shell' of null' raised during driver.getScreenshotAs(xxx) method call

Hi everybody,

I don’t understand why this error message ‘ERROR running Appium command: Cannot read property ‘shell’ of null’ is raised during this method call:
File scrFile2 = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);

Context: ‘getScreenshotAs’ method is called just after a closeApp() method.
If i do
((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
before the ‘closeApp()’ method call, no error is raised. The test works fine.

My current code:

File scrFile1= ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
driver.closeApp();
File scrFile2 = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);

Thanks you in advance for your help

@Mague: What version of appium server are you using?
In the earlier version of appium server, the closeApp goes through the shutdown cycle. But from v1.5.x, it has changed. Kindly verify.

Thanks you @email@vimalraj, my Appium version is 1.4.13.

IIRC, closeApp also destroys and cleans up the driver session, so if you take a screenshot after calling closeApp, you’ll run into an error.

If you need to return to the home screen before taking a screenshot, you can send in the Android keycode the Android home button. Check the Appium Javadocs for the constant representing the home key.

1 Like