Added code to shutdown device if the device is already in booted state while erasing content and settings

The iOS Simulator sometimes hangs in the 'Booted' state and an WebDriverException is thrown by the below line
simctlCmd.executeAndWait();
which is boiled up to the client as seen in the following logs in SeLion

Caused by: org.openqa.selenium.WebDriverException: execution failed. Exit code =146 , command was: xcrun simctl erase 3E86440E-D8CB-45AA-843E-D900033CC584
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'.

So I caught the exit code '146' alone and tried to shutdown the iOS Simulator device before resetting the content and settings. The already present code does not wait for the device to change from 'Booted' to 'Shutdown' state.