简体   繁体   中英

iOS app wont launch when appium server is started programmatically

It's a bit of a weird situation. If I manually start the appium GUI server and run my appium java test, iOS simulator opens and the app launches as expected. The problem is when the server is started from java code, the connection is successful, the simulator opens, but the app doesn't launch, even though it can be seen sitting there on the simulator.

The test fails with the error:

org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: simctl error running 'uninstall': An error was encountered processing the command (domain=LSApplicationWorkspaceErrorDomain, code=111):
The operation couldn’t be completed. (LSApplicationWorkspaceErrorDomain error 111.)

CoreSimulator.log shows the error:

<Error>: uninstallApplication:withOptions:error:: Error Domain=LSApplicationWorkspaceErrorDomain Code=111 "(null)" UserInfo={optionsDict={
        SimulatorRootPath = "/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 10.3.simruntime/Contents/Resources/RuntimeRoot";
        SimulatorUserPath = "/Users/Library/Developer/CoreSimulator/Devices/4C54BEC0-5A37-418A-8C32-CC9168538FBF/data";
    }, CFBundleIdentifier=com.apple.test.WebDriverAgentRunner-Runner}

My code:

  private AppiumDriverLocalService service; 
     WebDriver driver;

@BeforeClass(alwaysRun=true)
public void startServer() throws InterruptedException, MalformedURLException {

AppiumDriverLocalService service = AppiumDriverLocalService
                            .buildService(new AppiumServiceBuilder().usingDriverExecutable(new File("/usr/local/Cellar/node/8.5.0/bin/node"))
                            .withAppiumJS(new File("/Users/node_modules/appium/build/lib/main.js"))
                            .withLogFile(new File("./AppiumServerlog.txt")));
                    service.start();

                }

 @Test
 public void testStartPage() throws InterruptedException, MalformedURLException {



DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability("platformName", "iOS");
cap.setCapability("platformVersion", "10.3");
cap.setCapability("deviceName", "iPhone 7");
cap.setCapability("browserName", "");
cap.setCapability("app", "/path/to/file");
cap.setCapability("noReset", true);

driver = new RemoteWebDriver(new URL("http://0.0.0.0:4723/wd/hub"), cap);


@AfterClass(alwaysRun=true)
public void tearDown() {
service.stop(); 
driver.quit();


 }

The Appium server needs few seconds to start, so provide delay next line of the server start command.

driver = new RemoteWebDriver(new URL("http://0.0.0.0:4723/wd/hub"), cap);
Thread.sleep(10000);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM