java-client icon indicating copy to clipboard operation
java-client copied to clipboard

'Connection Reset' exception thrown when isKeyboardShown() called (java client version:6.0.0 Appium 1.8.1. IOS)

Open JohnHuahuaZhan opened this issue 8 years ago • 4 comments

this is my code

public static void main( String[] args ) throws MalformedURLException {
        IOSDriver<IOSElement> driver = null;
        try {
            File app = new File("xxx.ipa");
            DesiredCapabilities capabilities = new DesiredCapabilities();
            capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone");
            capabilities.setCapability(MobileCapabilityType.UDID, "xxxxxxxxxxxxxx");
            capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "11.3.1");
            capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.IOS);
            capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.IOS_XCUI_TEST);
            capabilities.setCapability(MobileCapabilityType.FULL_RESET, false);
            capabilities.setCapability(MobileCapabilityType.NO_RESET, true);
            capabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 600);
            capabilities.setCapability(IOSMobileCapabilityType.XCODE_ORG_ID, "xxxxxxx");
            capabilities.setCapability(IOSMobileCapabilityType.XCODE_SIGNING_ID, "iPhone Developer");
            capabilities.setCapability(IOSMobileCapabilityType.WDA_STARTUP_RETRIES, 3);
            capabilities.setCapability(IOSMobileCapabilityType.WDA_STARTUP_RETRY_INTERVAL, 6000);

            capabilities.setCapability(IOSMobileCapabilityType.SHOW_XCODE_LOG, true);

            capabilities.setCapability(IOSMobileCapabilityType.UPDATE_WDA_BUNDLEID, "com.minglin.appium.ios");


            capabilities.setCapability(IOSMobileCapabilityType.UPDATE_WDA_BUNDLEID, "com.minglin.appium.ios");
            capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
            capabilities.setCapability(IOSMobileCapabilityType.WDA_LAUNCH_TIMEOUT, 60000);
            capabilities.setCapability(IOSMobileCapabilityType.WDA_CONNECTION_TIMEOUT, 16000);
            capabilities.setCapability(IOSMobileCapabilityType.COMMAND_TIMEOUTS, "{\"findElement\": 8000, \"findElements\": 15000, \"setValue\": 8000, \"default\": 16000}");
            driver = new IOSDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);




      
            int count = 10;
            while(count-- != 0){
                try {
                    System.out.println(driver.isKeyboardShown());
                    IOSElement cell = driver.findElement(MobileBy.iOSNsPredicateString("type == 'XCUIElementTypeTextField'"));
                    System.out.println(driver.isKeyboardShown());
                    cell.sendKeys("");
                    System.out.println(driver.isKeyboardShown());
                    IOSElement a = driver.findElement(MobileBy.iOSNsPredicateString("type == 'XCUIElementTypeApplication' AND name == 'appName'"));
                    a.click();
                    System.out.println(driver.isKeyboardShown());
                }catch (Throwable e){
                    e.printStackTrace();
                }

            }

            System.out.println(driver.isKeyboardShown());
        }catch (Throwable e){
            e.printStackTrace();
        }finally {
            driver.quit();
        }

    }

this is log

org.openqa.selenium.WebDriverException: java.net.SocketException: Connection reset
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T14:04:26.12Z'
System info: host: 'xxxxxMacBook-Pro.local', ip: 'xxxxxxxxxx', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.5', java.version: '1.8.0_171'
Driver info: driver.version: IOSDriver
	at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:233)
	at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:543)
	at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
	at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
	at io.appium.java_client.ios.IOSDriver.execute(IOSDriver.java:1)
	at io.appium.java_client.CommandExecutionHelper.execute(CommandExecutionHelper.java:27)
	at io.appium.java_client.HasOnScreenKeyboard.isKeyboardShown(HasOnScreenKeyboard.java:13)
	at ios_appium.App.main(App.java:65)
Caused by: java.net.SocketException: Connection reset
	at java.net.SocketInputStream.read(SocketInputStream.java:210)
	at java.net.SocketInputStream.read(SocketInputStream.java:141)
	at okio.Okio$2.read(Okio.java:139)
	at okio.AsyncTimeout$2.read(AsyncTimeout.java:237)
	at okio.RealBufferedSource.indexOf(RealBufferedSource.java:345)
	at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:217)
	at okhttp3.internal.http1.Http1Codec.readHeaderLine(Http1Codec.java:212)
	at okhttp3.internal.http1.Http1Codec.readResponseHeaders(Http1Codec.java:189)
	at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:88)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
	at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
	at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
	at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
	at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:125)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
	at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
	at okhttp3.RealCall.execute(RealCall.java:77)
	at org.openqa.selenium.remote.internal.OkHttpClient.execute(OkHttpClient.java:105)
	at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:155)
	at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:218)
	... 7 more
false
false
true
false
false
false
true
false
false
false
true
false
false
false
true
false
false
false
true
false
false
false
true
false
false
false
true
true
false
false
org.openqa.selenium.WebDriverException: java.net.SocketException: Connection reset
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T14:04:26.12Z'
System info: host: 'xxxxxxx-Pro.local', ip: 'xxxxxxxx', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.5', java.version: '1.8.0_171'
Driver info: driver.version: IOSDriver
	at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:233)
	at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:543)
	at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
	at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
	at io.appium.java_client.ios.IOSDriver.execute(IOSDriver.java:1)
	at io.appium.java_client.CommandExecutionHelper.execute(CommandExecutionHelper.java:27)
	at io.appium.java_client.HasOnScreenKeyboard.isKeyboardShown(HasOnScreenKeyboard.java:13)
	at ios_appium.App.main(App.java:69)
Caused by: java.net.SocketException: Connection reset
	at java.net.SocketInputStream.read(SocketInputStream.java:210)
	at java.net.SocketInputStream.read(SocketInputStream.java:141)
	at okio.Okio$2.read(Okio.java:139)
	at okio.AsyncTimeout$2.read(AsyncTimeout.java:237)
	at okio.RealBufferedSource.indexOf(RealBufferedSource.java:345)
	at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:217)
	at okhttp3.internal.http1.Http1Codec.readHeaderLine(Http1Codec.java:212)
	at okhttp3.internal.http1.Http1Codec.readResponseHeaders(Http1Codec.java:189)
	at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:88)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
	at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
	at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
	at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
	at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:125)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
	at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
	at okhttp3.RealCall.execute(RealCall.java:77)
	at org.openqa.selenium.remote.internal.OkHttpClient.execute(OkHttpClient.java:105)
	at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:155)
	at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:218)
	... 7 more
true
true
true
false
false

when the first time i called isKeyboardShown() after a session started, the 'Connection reset' exception was always thrown. after that, the same exception was thrown randomly

JohnHuahuaZhan avatar Jun 11 '18 04:06 JohnHuahuaZhan

I assume it is a problem on the XCTest side. There is nothing much that can be done there

mykola-mokhnach avatar Jun 11 '18 18:06 mykola-mokhnach

@mykola-mokhnach qq20180612-104359

[debug] [W3C] Calling AppiumDriver.isKeyboardShown() with args: ["e2085a8e-ffbc-4773-9226-6eb9cdaf180b"]
[debug] [XCUITest] Executing command 'isKeyboardShown'
[debug] [BaseDriver] Waiting up to 0 ms for condition
[debug] [XCUITest] Setting custom timeout to 8000 ms for 'findElement' command
[debug] [JSONWP Proxy] Proxying [POST /element] to [POST http://localhost:8100/session/49DDD385-A99F-46E5-93EB-9E6007D6DE97/element] with body: {"using":"class name","value":"XCUIElementTypeKeyboard"}
[debug] [JSONWP Proxy] Got response with status 200: {"value":{"using":"class name","value":"XCUIElementTypeKeyboard","description":"unable to find an element"},"sessionId":"49DDD385-A99F-46E5-93EB-9E6007D6DE97","status":7}
[debug] [W3C] Responding to client with driver.isKeyboardShown() result: false
[HTTP] <-- GET /wd/hub/session/e2085a8e-ffbc-4773-9226-6eb9cdaf180b/appium/device/is_keyboard_shown 200 168 ms - 15
[HTTP] 
[debug] [XCUITest] Connection to WDA timed out
[debug] [iProxy] recv failed: Operation not permitted
[HTTP] --> GET /wd/hub/session/e2085a8e-ffbc-4773-9226-6eb9cdaf180b/appium/device/is_keyboard_shown
[HTTP] {}
[debug] [W3C] Calling AppiumDriver.isKeyboardShown() with args: ["e2085a8e-ffbc-4773-9226-6eb9cdaf180b"]
[debug] [XCUITest] Executing command 'isKeyboardShown'
[debug] [BaseDriver] Waiting up to 0 ms for condition
[debug] [XCUITest] Setting custom timeout to 8000 ms for 'findElement' command
[debug] [JSONWP Proxy] Proxying [POST /element] to [POST http://localhost:8100/session/49DDD385-A99F-46E5-93EB-9E6007D6DE97/element] with body: {"using":"class name","value":"XCUIElementTypeKeyboard"}
[debug] [JSONWP Proxy] Got response with status 200: {"value":{"using":"class name","value":"XCUIElementTypeKeyboard","description":"unable to find an element"},"sessionId":"49DDD385-A99F-46E5-93EB-9E6007D6DE97","status":7}
[debug] [W3C] Responding to client with driver.isKeyboardShown() result: false
[HTTP] <-- GET /wd/hub/session/e2085a8e-ffbc-4773-9226-6eb9cdaf180b/appium/device/is_keyboard_shown 200 165 ms - 15
[HTTP] 
[debug] [XCUITest] Connection to WDA timed out
[debug] [iProxy] recv failed: Operation not permitted

as you can see:

  1. I called isKeyboardShown normally and it returned successfully
  2. after I stoped at the breakpoint for a while,appium server showed some logs to me
[debug] [XCUITest] Connection to WDA timed out
[debug] [iProxy] recv failed: Operation not permitted

3、I called isKeyboardShown again,'Connection Reset' exception thrown

since isKeyboardShown() returns successfully , why Appium server gives me some 'Connection to WDA timed out' log

JohnHuahuaZhan avatar Jun 12 '18 02:06 JohnHuahuaZhan

@mykola-mokhnach this method is realized by myself and it works well.

public static boolean isKeyboardShown(IOSDriver<IOSElement> driver){
        List<IOSElement> list = driver.findElementsByClassName("XCUIElementTypeKeyboard");
        return Optional.ofNullable(!list.isEmpty()).orElse(false);
    }

JohnHuahuaZhan avatar Jun 12 '18 03:06 JohnHuahuaZhan

Exactly the same thing is done internally:

commands.isKeyboardShown = async function () {
  try {
    await this.findNativeElementOrElements('class name', 'XCUIElementTypeKeyboard', false);
    return true;
  } catch (ign) {
    return false;
  }
};

Although we have no idea on why webdriver dies unexpectedly like I said above. Perhaps, it does not like if this is called too frequently.

mykola-mokhnach avatar Jun 12 '18 05:06 mykola-mokhnach