microsoft / WinAppDriver

Windows Application Driver
MIT License
3.68k stars 1.4k forks source link

UnknownError: An unknown server-side error occurred while processing the command. Original error: Unable to find the given UIObject. #1852

Open zhangdahui01 opened 1 year ago

zhangdahui01 commented 1 year ago

hi, all, I installed jenkins at my aws windows server, and try to trigger jenkins jobs to run windows UI automation test after installing my UMP windows client product which is developed by my team at my aws windows server. And I use tscon to keep session alive, and create a batch script to disconnect the session, but can keep session alive:

for /f "skip=1 tokens=3" %%s in ('query user %USERNAME%') do (
  %windir%\System32\tscon.exe %%s /dest:console
)

appium: 1.22.3 winAppDriver: 1.2 My UI automation code(windows driver) for connecting with appium server is like this:

    public void start(@NotNull AutomationConfig config) {
        try{
            URL appiumUrl = new URL(config.serverHost + ":" + config.remotePort + config.remotePath);
            WindowsDriver couposSession=null;
            try{
                DesiredCapabilities capabilities = new DesiredCapabilities();
                capabilities.setCapability("app", config.appId);
                capabilities.setCapability("forceMjsonwp", true);
                capabilities.setCapability("ms:experimental-webdriver",true);
                capabilities.setCapability("ms:waitForAppLaunch",5);
                capabilities.setCapability("platformName", "Windows");
                capabilities.setCapability("deviceName", "WindowsPC");
                couposSession = new WindowsDriver(appiumUrl, capabilities);
                couposSession.manage().timeouts().implicitlyWait(Duration.ofSeconds(config.implicitlyCmdTimeout));
                windowsDriver=couposSession;
                logger.info("open the coupos client and locate it normally,start appium client--------");
            }catch (Exception e){
                logger.info("open the coupos client and occur exception: -------");
                e.printStackTrace();
                Thread.sleep(8000);
                DesiredCapabilities desktopCapabilities=new DesiredCapabilities();
                desktopCapabilities.setCapability("app","Root");
                desktopCapabilities.setCapability("platformName", "Windows");
                desktopCapabilities.setCapability("deviceName", "WindowsPC");
                WindowsDriver DesktopSession=new WindowsDriver(appiumUrl,desktopCapabilities);
                Assert.assertNotNull(DesktopSession);
                Thread.sleep(500);
                String flag_element="coupang pos";
                WebElement couposWindows=DesktopSession.findElement(By.name(flag_element));
                Thread.sleep(5000);
                String couposTopLevelWindowHandle="0x"+Integer.toHexString(Integer.decode(couposWindows.getAttribute("NativeWindowHandle"))).toString();
                DesiredCapabilities appCapabilities = new DesiredCapabilities();
                appCapabilities.setCapability("appTopLevelWindow", couposTopLevelWindowHandle);
                appCapabilities.setCapability("platformName", "Windows");
                appCapabilities.setCapability("deviceName", "WindowsPC");
                WindowsDriver windowsDriver=new WindowsDriver(appiumUrl, appCapabilities);
                windowsDriver.manage().timeouts().implicitlyWait(Duration.ofSeconds(config.implicitlyCmdTimeout));
                logger.info("start appium client--------");
            }

        }catch (Exception e){
            logger.info("start to appium client occur exception-------");
            e.printStackTrace();

        }
    }

but it failed when run the line: WindowsDriver windowsDriver=new WindowsDriver(appiumUrl, appCapabilities);

the appium server log is:

Request DefaultHttpRequest(decodeResult: success, version: HTTP/1.1)
    POST /wd/hub/session HTTP/1.1
    X-Idempotency-Key: 99d9ebe2-f195-479b-9a1c-ccc8d182cf77
    User-Agent: selenium/4.4.0 (java windows)
    Content-Length: 256
    Content-Type: application/json; charset=utf-8
    host: 10.248.22.92:4723
    accept: */*

    Response DefaultHttpResponse(decodeResult: success, version: HTTP/1.1)
    HTTP/1.1 500 Internal Server Error
    X-Powered-By: Express
    Access-Control-Allow-Origin: *
    Access-Control-Allow-Methods: GET, POST, PUT, OPTIONS, DELETE
    Access-Control-Allow-Headers: Cache-Control, Pragma, Origin, X-Requested-With, Content-Type, Accept, User-Agent
    Vary: X-HTTP-Method-Override
    Content-Type: application/json; charset=utf-8
    ETag: W/"bc4-TgXfrOvCuRcBH/z/YBw5bZx+IdQ"
    Date: Thu, 19 Jan 2023 06:48:33 GMT
    Connection: keep-alive
    Keep-Alive: timeout=600
    content-length: 3012

    06:48:33.204 [AsyncHttpClient-1-2] DEBUG org.asynchttpclient.netty.channel.ChannelManager - Adding key: http://10.248.22.92:4723/ for channel [id: 0xd03f36b5, L:/10.248.22.92:60360 - R:/10.248.22.92:4723]
    [INFO][06:48:33] start to appium client occur exception-------

Test-Suite-butter-UI-Automation STANDARD_ERROR
    org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: An unknown server-side error occurred while processing the command. Original error: Unable to find the given UIObject.
    Search criteria:'ClassName = Windows.UI.Core.CoreWindow'
    Search domain:'A collection of MS.Internal.Mita.Foundation.UIObject instances in the set defined as Children of '{coupang pos, ApplicationFrameWindow, 42.918302}' ('[Unknown UICondition]') matching: Condition: 'True'..'
    Build info: version: '4.4.0', revision: 'e5c75ed026a'
    System info: host: 'EC2AMAZ-QQ6TRN7', ip: '10.248.22.92', os.name: 'Windows Server 2019', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.5'
    Driver info: io.appium.java_client.windows.WindowsDriver
    Command: [null, newSession {capabilities=[{appium:appTopLevelWindow=0xe031e, appium:automationName=Windows, appium:deviceName=WindowsPC, platformName=WINDOWS}], desiredCapabilities=Capabilities {appTopLevelWindow: 0xe031e, appium:automationName: Windows, deviceName: WindowsPC, platformName: WINDOWS}}]
    Capabilities {}
        at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:144)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at io.appium.java_client.remote.AppiumProtocolHandshake.createSession(AppiumProtocolHandshake.java:126)
        at io.appium.java_client.remote.AppiumProtocolHandshake.createSession(AppiumProtocolHandshake.java:102)
        at io.appium.java_client.remote.AppiumCommandExecutor.createSession(AppiumCommandExecutor.java:155)
        at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:189)
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:547)
        at io.appium.java_client.AppiumDriver.startSession(AppiumDriver.java:229)
        at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:157)
        at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:80)
        at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:92)
        at io.appium.java_client.windows.WindowsDriver.<init>(WindowsDriver.java:49)
        at com.coupang.mobile.infra.automation.driver.WindowsAppiumDriver.start(WindowsAppiumDriver.java:67)
        at com.coupang.mobile.infra.automation.MobileAutomation.start(MobileAutomation.java:163)
        at com.coupang.butter.automation.hook.AutomationHook.beforeAll(AutomationHook.java:43)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at org.testng.internal.invokers.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:135)
        at org.testng.internal.invokers.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:65)
        at org.testng.internal.invokers.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:381)
        at org.testng.internal.invokers.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:319)
        at org.testng.SuiteRunner.privateRun(SuiteRunner.java:368)
        at org.testng.SuiteRunner.run(SuiteRunner.java:326)
        at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
        at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:95)
        at org.testng.TestNG.runSuitesSequentially(TestNG.java:1249)
        at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
        at org.testng.TestNG.runSuites(TestNG.java:1092)
        at org.testng.TestNG.run(TestNG.java:1060)
        at org.gradle.api.internal.tasks.testing.testng.TestNGTestClassProcessor.runTests(TestNGTestClassProcessor.java:141)
        at org.gradle.api.internal.tasks.testing.testng.TestNGTestClassProcessor.stop(TestNGTestClassProcessor.java:90)
        at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
        at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
        at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
        at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
        at jdk.proxy1/jdk.proxy1.$Proxy2.stop(Unknown Source)
        at org.gradle.api.internal.tasks.testing.worker.TestWorker$3.run(TestWorker.java:193)
        at org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintainThreadName(TestWorker.java:129)
        at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:100)
        at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:60)
        at org.gradle.process.internal.worker.child.ActionExecutionWorker.execute(ActionExecutionWorker.java:56)
        at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:133)
        at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:71)
        at worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:69)
        at worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74)

I checked when i start the app window driver at the first time, my windows client coupos has been opened, but winAppDriver response 500:

[ERROR][13:03:30] Could not start a new session. Response code 500. Message: An unknown server-side error occurred while processing the command. Original error: Failed to locate opened application window with appId: 5a10779b-789b-4137-a88d-2c3d88b2e9a5_4mpdf3wfgwn9w!App, and processId: 7728
    Build info: version: '4.4.0', revision: 'e5c75ed026a'

so i add the exception logic code, to attach an opened exist app windows like the page(https://github.com/Microsoft/WinAppDriver/blob/v1.0-RC2/README.md#attaching-to-an-existing-app-window), but it still failed, because the winAppDriver response 500, like the above log. so Why? how to resolve the issue? i don't know what is the meaning of the error log:

2023-01-19 06:48:33:193 [WinAppDriver] {"status":13,"value":{"error":"unknown error","message":"Unable to find the given UIObject.\r\nSearch criteria:'ClassName = Windows.UI.Core.CoreWindow'\r\nSearch domain:'A collection of MS.Internal.Mita.Foundation.UIObject instances in the set defined as Children of '{coupang pos, ApplicationFrameWindow, 42.918302}' ('[Unknown UICondition]') matching: Condition: 'True'..'"}}
2023-01-19 06:48:33:198 [WinAppDriver] WinAppDriver exited with code null, signal SIGTERM
2023-01-19 06:48:33:199 [BaseDriver] Event 'newSessionStarted' logged at 1674110913198 (06:48:33 GMT+0000 (Coordinated Universal Time))
2023-01-19 06:48:33:199 [W3C] Encountered internal error running command: UnknownError: An unknown server-side error occurred while processing the command. Original error: Unable to find the given UIObject.

who can help me? thanks! @timotiusmargo can you help me? i read your issue solution https://github.com/microsoft/WinAppDriver/issues/283, but it failed when i accept it

anunay1 commented 1 year ago

What is the version of the windows server?

zhangdahui01 commented 1 year ago

windows server 2019

张大慧

@.*** |

---- Replied Message ---- | From | ANUNAYA @.> | | Date | 01/20/2023 16:12 | | To | @.> | | Cc | @.>@.> | | Subject | Re: [microsoft/WinAppDriver] UnknownError: An unknown server-side error occurred while processing the command. Original error: Unable to find the given UIObject. (Issue #1852) |

What is the version of the windows server?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

anunay1 commented 1 year ago

It will not work with 2019 can you try with 2016