How can I restart device?

I set AppiumDriverLocalService + AndroidDriver,.
My test should check my app after device reboot, but here my issue, I loose connection to device !
there is a way to restart device without close appium + android drivers ?

Thanks for help

@selenUser
Try “adb reboot” command in your test case using java code with java.lang.Runtime class.

I tried but driver loosing connection of device

I’m not sure there is a way to reboot a device without losing the connection. By design, wouldn’t the device shut down all existing connections when it reboots?

The only thing I can think of right now is to write some custom code to poll for the device using adb and re-instantiate the driver once adb reports the device is available.

Good luck.

When the device reboots, write a custom code which will create a new instance for driver, also make sure to restart the appium server.

@selenUser Here is the working sample code for rebooting the device and initializing it in the same script without failing. You can try this out.
This is very good use case of telecommunication companies as their use case contains frequent rebooting of the device which leads to device disconnection. This sample script might help there.