如何解决[MJSONWP]遇到内部在使用Appium和iOS进行自动化时20次尝试错误后无法连接到有效的应用程序?

时间:2017-12-19 10:37:29

标签: java ios selenium-webdriver ios-simulator appium-ios

我正在尝试使用Appium 1.7.1和Java,iOS模拟器自动化混合应用程序.Xcode 8.3

到目前为止,我能够启动应用程序并删除弹出的通知,但在尝试获取上下文时,Appium中会抛出错误:

  

[MJSONWP]遇到内部错误运行命令:错误:尝试20次后无法连接到有效的应用程序。       at Object.wrappedLogger.errorAndThrow(/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-support/lib/logging.js:63:13)       在RemoteDebugger.selectApp $(/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-remote-debugger/lib/remote-debugger.js:259:6)       在tryCatch(/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)       在GeneratorFunctionPrototype.invoke [as _invoke](/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)       在GeneratorFunctionPrototype.prototype。(匿名函数)[as throw](/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)       在GeneratorFunctionPrototype.invoke(/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)   [HTTP]< - GET / wd / hub / session / c59dd263-05e2-439a-9f1e-c37389e38ada / contexts 500 136 ms - 219

在IDE上:

  

org.openqa.selenium.WebDriverException:处理命令时发生未知的服务器端错误。原始错误:20次尝试后无法连接到有效的应用程序。 (警告:服务器未提供任何堆栈跟踪信息)   命令持续时间或超时:0毫秒

代码:

package XYZ;

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.ios.IOSDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import jdk.internal.instrumentation.Logger;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import java.net.URL;
import java.util.Set;


/**
 * Created by on 28/11/2017.
 */
public class AppSimulatorLaunch {




    public AppiumDriver<MobileElement> driver;

    @Before
    public void setup() throws Exception {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPad Air 2");
        capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "iOS");
        capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "10.3");
        capabilities.setCapability("nativeWebTap", true);
        capabilities.setCapability("automationName", "XCUITest");
        capabilities.setCapability("xcodeOrgId", "xyz");
        capabilities.setCapability("xcodeSigningId", "iPhone Developer");
        capabilities.setCapability("newCommandTimeout", "120");
        capabilities.setCapability(MobileCapabilityType.APP, "/Users/user/Documents/xyz.app");

        driver = new IOSDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

        driver.switchTo().alert().accept();


    }

    @After
    public void tearDown() {

      // driver.quit();
    }


    @Test
    public void testCheckWebsite() throws InterruptedException {
        Thread.sleep(5000);
        Set<String> contextNames = driver.getContextHandles();
        System.out.println("about to print the context list");
        System.out.println(contextNames);

         driver.context((String) contextNames.toArray()[1]);

        driver.findElement(By.xpath("//*[@id=\"USER\"]")).sendKeys("t334658");
        driver.findElement(By.xpath("//*[@id=\"PASSWORD\"]")).sendKeys("geenidee01");
        driver.findElement(By.xpath("//*[@id=\"bouton1\"]")).click();

    }

}

知道如何解决这个问题吗?我已经尝试添加了https://github.com/appium/appium/issues/6825中提到的thread.sleep,但它似乎也没有用。

AutoTig

1 个答案:

答案 0 :(得分:0)

经过一些调查后,问题显然是使用Xcode 8.3和Appium 1.7.1运行脚本。 使用Xcode 9似乎可行。