microsoft / WinAppDriver

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

implicitlyWait timeout not working #1792

Open 232629 opened 1 year ago

232629 commented 1 year ago

Appium v1.22.3 Java 1.8 WinAppDriver 1.2.2009.2003

Steps

  1. Create Driver (Root)
  2. Set implicitlyWait 5 seconds
  3. Search for a non-existent element
    AppiumServiceBuilder serviceBuilderWin = new AppiumServiceBuilder();
    serviceBuilderWin.withIPAddress("127.0.0.1");
    serviceBuilderWin.usingAnyFreePort();
    serviceBuilderWin.withStartUpTimeOut(30, TimeUnit.SECONDS);
    AppiumDriverLocalService apDevWin = AppiumDriverLocalService.buildService(serviceBuilderWin);
    DesiredCapabilities capabilitiesWin = new DesiredCapabilities();
    capabilitiesWin.setCapability(APP, "Root");
    capabilitiesWin.setCapability(DEVICE_NAME, "WindowsPC");
    capabilitiesWin.setCapability(PLATFORM_NAME, "Windows");
    capabilitiesWin.setCapability(AUTOMATION_NAME, "Windows");
    capabilitiesWin.setCapability("createSessionTimeout", "10");
    capabilitiesWin.setCapability(NEW_COMMAND_TIMEOUT, 600);
    capabilitiesWin.setCapability("forceMjsonwp", true);

    winDriver = new WindowsDriver<WindowsElement>(apDevWin, capabilitiesWin);

    winDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);

    winDriver.findElementByName("BadName").click();

Issue If the element does not exist, I have to wait 240 seconds. I can't change this timeout. The existing element is working.

winDriver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); Appium log

  [HTTP] --> POST /wd/hub/session/618ac378-0235-4945-b76d-3df95300a8d9/timeouts
  [HTTP] {"type":"implicit","ms":5000}
  [MJSONWP (618ac378)] Driver proxy active, passing request on via HTTP proxy
  [debug] [WD Proxy] Matched '/wd/hub/session/618ac378-0235-4945-b76d-3df95300a8d9/timeouts' to command name 'timeouts'
  [debug] [Protocol Converter] Will send the following request bodies to /timeouts: [{"type":"implicit","ms":5000}]
  [debug] [WD Proxy] Proxying [POST /wd/hub/session/618ac378-0235-4945-b76d-3df95300a8d9/timeouts] to [POST http://127.0.0.1:4724/wd/hub/session/6E320C7D-CAA5-4643-9FA4-03DA86EB30DA/timeouts] with body: {"type":"implicit","ms":5000}
  [debug] [WinAppDriver] ==========================================
  [debug] [WinAppDriver] User-Agent: appium
  [debug] [WD Proxy] Got response with status 200: {"sessionId":"6E320C7D-CAA5-4643-9FA4-03DA86EB30DA","status":0}
  [WD Proxy] Replacing sessionId 6E320C7D-CAA5-4643-9FA4-03DA86EB30DA with 618ac378-0235-4945-b76d-3df95300a8d9
  [HTTP] <-- POST /wd/hub/session/618ac378-0235-4945-b76d-3df95300a8d9/timeouts 200 5 ms - 76
  [HTTP] 
  [debug] [WinAppDriver] {"sessionId":"6E320C7D-CAA5-4643-9FA4-03DA86EB30DA","status":0}

winDriver.findElementByName("BadName").click(); Appium log

  [HTTP] --> POST /wd/hub/session/618ac378-0235-4945-b76d-3df95300a8d9/element
  [HTTP] {"using":"name","value":"BadName"}
  [debug] [MJSONWP (618ac378)] Calling AppiumDriver.findElement() with args: ["name","BadName","618ac378-0235-4945-b76d-3df95300a8d9"]
  [debug] [BaseDriver] Valid locator strategies for this request: xpath, id, name, class name, accessibility id
  [debug] [WD Proxy] Matched '/element' to command name 'findElement'
  [debug] [WD Proxy] Proxying [POST /element] to [POST http://127.0.0.1:4724/wd/hub/session/6E320C7D-CAA5-4643-9FA4-03DA86EB30DA/element] with body: {"using":"name","value":"BadName"}
  [debug] [WinAppDriver] ==========================================       
  [debug] [WinAppDriver] {"using":"name","value":"BadName"}
  [WD Proxy] Error: timeout of 240000ms exceeded
  [WD Proxy]     at createError (C:\Users\user\AppData\Roaming\npm\node_modules\appium\node_modules\axios\lib\core\createError.js:16:15)
  [WD Proxy]     at RedirectableRequest.handleRequestTimeout (C:\Users\user\AppData\Roaming\npm\node_modules\appium\node_modules\axios\lib\adapters\http.js:280:16)
  [WD Proxy]     at RedirectableRequest.emit (events.js:315:20)
  [WD Proxy]     at Timeout._onTimeout (C:\Users\user\AppData\Roaming\npm\node_modules\appium\node_modules\follow-redirects\index.js:166:12)
  [WD Proxy]     at listOnTimeout (internal/timers.js:554:17)
  [WD Proxy]     at processTimers (internal/timers.js:497:7)
  [debug] [MJSONWP (618ac378)] Encountered internal error running command: UnknownError: An unknown server-side error occurred while processing the command. Original error: Could not proxy command to the remote server. Original error: timeout of 240000ms exceeded
  [debug] [MJSONWP (618ac378)]     at WADProxy.command (C:\Users\user\AppData\Roaming\npm\node_modules\appium\node_modules\appium-base-driver\lib\jsonwp-proxy\proxy.js:274:13)
  [debug] [MJSONWP (618ac378)]     at processTicksAndRejections (internal/process/task_queues.js:93:5)
  [debug] [MJSONWP (618ac378)]     at WinAppDriver.sendCommand (C:\Users\user\AppData\Roaming\npm\node_modules\appium\node_modules\appium-windows-driver\lib\winappdriver.js:224:12)
  [debug] [MJSONWP (618ac378)]     at WindowsDriver.findElOrEls (C:\Users\user\AppData\Roaming\npm\node_modules\appium\node_modules\appium-windows-driver\lib\commands\find.js:11:10)
  [debug] [MJSONWP (618ac378)]     at WindowsDriver.findElOrElsWithProcessing (C:\Users\user\AppData\Roaming\npm\node_modules\appium\node_modules\appium-base-driver\lib\basedriver\commands\find.js:33:12)
  [debug] [MJSONWP (618ac378)]     at WindowsDriver.findElement (C:\Users\user\AppData\Roaming\npm\node_modules\appium\node_modules\appium-base-driver\lib\basedriver\commands\find.js:53:10)
  [HTTP] <-- POST /wd/hub/session/618ac378-0235-4945-b76d-3df95300a8d9/element 500 240042 ms - 261
  [HTTP] 

Error

  org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Could not proxy command to the remote server. Original error: timeout of 240000ms exceeded (WARNING: The server did not provide any stacktrace information)
  Command duration or timeout: 0 milliseconds
  Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
  System info: host: 'USER', ip: '192.168.144.2', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_281'
  Driver info: io.appium.java_client.windows.WindowsDriver
  Capabilities {app: Root, automationName: Windows, createSessionTimeout: 10, deviceName: WindowsPC, javascriptEnabled: true, newCommandTimeout: 600, platform: WINDOWS, platformName: Windows}
  Session ID: 618ac378-0235-4945-b76d-3df95300a8d9
  *** Element info: {Using=name, value=BadName}
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
      at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
      at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
      at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
      at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80)
      at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44)
      at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
      at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:250)
      at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
      at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:41)
      at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
      at io.appium.java_client.windows.WindowsDriver.execute(WindowsDriver.java:1)
      at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:323)
      at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:61)
      at io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)
      at io.appium.java_client.windows.WindowsDriver.findElement(WindowsDriver.java:1)
      at org.openqa.selenium.remote.RemoteWebDriver.findElementByName(RemoteWebDriver.java:404)
      at io.appium.java_client.DefaultGenericMobileDriver.findElementByName(DefaultGenericMobileDriver.java:117)
      at io.appium.java_client.AppiumDriver.findElementByName(AppiumDriver.java:1)
      at io.appium.java_client.windows.WindowsDriver.findElementByName(WindowsDriver.java:1)
      at com.metaquotes.tests.MetaTrader5.beforeAll(MetaTrader5.java:86)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:725)
      at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
      at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
      at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:149)
      at org.junit.jupiter.engine.extension.TimeoutExtension.interceptLifecycleMethod(TimeoutExtension.java:126)
      at org.junit.jupiter.engine.extension.TimeoutExtension.interceptBeforeAllMethod(TimeoutExtension.java:68)
      at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115)
      at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)
      at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
      at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
      at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
      at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
      at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104)
      at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98)
      at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeBeforeAllMethods$11(ClassBasedTestDescriptor.java:397)
      at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
      at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.invokeBeforeAllMethods(ClassBasedTestDescriptor.java:395)
      at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.before(ClassBasedTestDescriptor.java:209)
      at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.before(ClassBasedTestDescriptor.java:80)
      at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:148)
      at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
      at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
      at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
      at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
      at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
      at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
      at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
      at java.util.ArrayList.forEach(ArrayList.java:1259)
      at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
      at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
      at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
      at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
      at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
      at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
      at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
      at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
      at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
      at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)
      at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
      at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)
      at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:107)
      at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88)
      at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54)
      at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67)
      at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52)
      at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114)
      at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86)
      at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86)
      at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:53)
      at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:71)
      at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
      at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
      at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)
Shakevg commented 1 year ago

232629 Per your log you got WebDriverException error but findElement will return “No Such Element Exception” on timeout. Looks like some issue with your code (maybe the session is incorrect) or maybe you cannot connect to WinAppDriver.

Unfortunately, I didn't familiar with Java but can you try using code from here: https://github.com/microsoft/WinAppDriver/blob/master/Samples/Java/CalculatorTest/src/test/java/CalculatorTest.java

232629 commented 1 year ago

232629 Per your log you got WebDriverException error but findElement will return “No Such Element Exception” on timeout. Looks like some issue with your code (maybe the session is incorrect) or maybe you cannot connect to WinAppDriver.

Unfortunately, I didn't familiar with Java but can you try using code from here: https://github.com/microsoft/WinAppDriver/blob/master/Samples/Java/CalculatorTest/src/test/java/CalculatorTest.java

This code is only for a specific Windows application.

capabilities.setCapability("app", "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App");

I have no problems with it. It works.

I have a problem when working with Desktop Session. ("app", "Root") Example taken from FAQ When and how to create a Desktop Session

appCapabilities.SetCapability("app", "Root");