Winium.Desktop icon indicating copy to clipboard operation
Winium.Desktop copied to clipboard

Implicit and Explicit Waits in Winium

Open SotirisAnt opened this issue 6 years ago • 16 comments

Hello,

I have stumbled across the following issue: After having clicked on an element, I would like to wait for just 1 second. However, Winium is not waiting for a second neither using "Implicit wait" nor "Explicit wait". In the first case, an exception occurs, while in the second case, it waits for the default period of time (5 seconds) and then continues with the execution. Please see below the code I'm using and actual results

Implicit wait

driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);

org.openqa.selenium.UnsupportedCommandException: 'setTimeout' is not valid or implemented command. (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 0 milliseconds Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:26:55.152Z' System info: host: 'NRB248385-A', ip: '172.17.66.11', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_141' Driver info: org.openqa.selenium.winium.WiniumDriver Capabilities {app: C:\Users\P20009\Desktop\Tra..., args: , debugConnectToRunningApp: false, innerPort: 9998, javascriptEnabled: true, keyboardSimulator: 1, launchDelay: 0, platform: ANY, platformName: ANY} Session ID: AwesomeSession at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) 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 org.openqa.selenium.winium.WiniumDriverCommandExecutor.execute(WiniumDriverCommandExecutor.java:78) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:545) at org.openqa.selenium.remote.RemoteWebDriver$RemoteWebDriverOptions$RemoteTimeouts.implicitlyWait(RemoteWebDriver.java:779) at com.site.pages.PageBase.waitUntilText(PageBase.java:53) at com.site.pages.HomePage.openImportDialog(HomePage.java:38) at com.site.tests.TestSubstances.testSubstance1(TestSubstances.java:39) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124) at org.testng.internal.Invoker.invokeMethod(Invoker.java:580) at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:716) at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:988) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109) at org.testng.TestRunner.privateRun(TestRunner.java:648) at org.testng.TestRunner.run(TestRunner.java:505) at org.testng.SuiteRunner.runTest(SuiteRunner.java:455) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415) at org.testng.SuiteRunner.run(SuiteRunner.java:364) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208) at org.testng.TestNG.runSuitesLocally(TestNG.java:1137) at org.testng.TestNG.runSuites(TestNG.java:1049) at org.testng.TestNG.run(TestNG.java:1017) at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

Explicit wait

WebDriverWait wait = new WebDriverWait(driver, 1); wait.until(ExpectedConditions.presenceOfElementLocated(By.name("someText")));

SotirisAnt avatar Apr 13 '18 12:04 SotirisAnt

I faced the same issue. Use this fix for Implicit Wait.

https://github.com/2gis/Winium.Desktop/pull/71/commits

yarafath8 avatar Apr 25 '18 11:04 yarafath8

Hello. Can you explain me how i can use it in my project&

nadya2712 avatar Nov 20 '18 08:11 nadya2712

I faced the same issue. Use this fix for Implicit Wait.

https://github.com/2gis/Winium.Desktop/pull/71/commits

What code used in program to resolve implicit wait issue

ravindrabelavekar avatar Dec 13 '18 06:12 ravindrabelavekar

@ravindrabelavekar - I downloaded the Winium Driver source and added SetTimeoutExecutor.cs to the CS Project and used the new Winium driver in my automation project.

yarafath8 avatar Dec 13 '18 09:12 yarafath8

How to do this? Steps will be helpful. As per my knowledge last winium driver release I can see it's in 2016. After that there is no release, correct me If I am wrong

ravindrabelavekar avatar Dec 13 '18 09:12 ravindrabelavekar

I have the same issue, is there any fix ?

mdz15 avatar Feb 12 '19 11:02 mdz15

is there any fix for this problem? I have same error while using Winium and timeouts: winiumdriver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);

eastdenchik1 avatar Aug 01 '19 14:08 eastdenchik1

is there any fix for this problem? or this winium is already dead?

eastdenchik1 avatar Aug 01 '19 14:08 eastdenchik1

I faced the same issue. Anybody help for this point??? Thanks a lot

sangvvan avatar Feb 10 '20 03:02 sangvvan

Hey everyone,

Late to the party, but maybe this might help someone out there...

I did this in Java, and it works for me. Shouldn't be too hard to translate to other languages.

    protected static void updateImplicitWaitMs(WiniumDriver driver, int waitMs) throws IOException {
        if (driver == null) { return; }
        WiniumDriverCommandExecutor commandExecutor = (WiniumDriverCommandExecutor) driver.getCommandExecutor();
        URL driverUrl = commandExecutor.getAddressOfRemoteServer();
        String timeoutUrl = driverUrl.toString() + "/session/AwesomeSession/timeouts/implicit_wait";
        String postBody = "{ \"SESSIONID\":\"AwesomeSession\", \"ms\":" + waitMs + " }";
        Request.Post(timeoutUrl).bodyByteArray(postBody.getBytes()).execute().returnContent();
    }

Essentially, instead of using standard WebDriver mechanism, I send a POST request to WiniumDriver:

{ "SESSIONID": "AwesomeSession", "ms": ... }

Seems to do the trick. Hope this helps.

mikeliucc avatar Jun 05 '21 21:06 mikeliucc

Hello @mikeliucc How can I use your trick? and for the "Request.Post ..." which lib you are using (imported)? Thank you a lot!

nguyenquangtay avatar Jul 18 '21 07:07 nguyenquangtay

Yay, I did it, it works fine, thank @mikeliucc great trick! just replace the driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS) by updateImplicitWaitMs(driver, 5000) haha for the lib, I use import org.apache.http.client.fluent.Request and it works for me, regards!

nguyenquangtay avatar Jul 18 '21 07:07 nguyenquangtay

Hello @mikeliucc How can I use your trick? and for the "Request.Post ..." which lib you are using (imported)? Thank you a lot!

I´ve used this lib:

	<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/fluent-hc -->
	<dependency>
	    <groupId>org.apache.httpcomponents</groupId>
	    <artifactId>fluent-hc</artifactId>
	    <version>4.5.13</version>
	</dependency>

marcveiga avatar Aug 02 '22 18:08 marcveiga

Yes, Request class is imported from Apache HttpClient Fluent API. Your maven snippet looks right to me.

mikeliucc avatar Aug 02 '22 19:08 mikeliucc

Yay, I did it, it works fine, thank @mikeliucc great trick! just replace the driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS) by updateImplicitWaitMs(driver, 5000) haha for the lib, I use import org.apache.http.client.fluent.Request and it works for me, regards!

Hello nguyenquangtay, I'm using the same, the code does not show any error but when running, implicit wait still not working. Are you still using this solution?

quynhbui267 avatar Dec 08 '22 02:12 quynhbui267

hi @quynhbui267 Sorry for the late responses, I'm no longer with Winium anymore, the demo is over and miss the repo also, now on pywinauto , appium for desktop automation. Can't help you :(

nguyenquangtay avatar Dec 13 '22 13:12 nguyenquangtay