2gis / Winium.Desktop

Winium.Desktop is Selenium Remote WebDriver implementation for automated testing of Windows application based on WinFroms and WPF platforms.
Mozilla Public License 2.0
403 stars 140 forks source link

Implicit and Explicit Waits in Winium #227

Open SotirisAnt opened 6 years ago

SotirisAnt commented 6 years ago

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")));

yarafath8 commented 6 years ago

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

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

nadya2712 commented 5 years ago

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

ravindrabelavekar commented 5 years ago

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

yarafath8 commented 5 years ago

@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.

ravindrabelavekar commented 5 years ago

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

mdz15 commented 5 years ago

I have the same issue, is there any fix ?

eastdenchik1 commented 5 years ago

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

eastdenchik1 commented 5 years ago

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

sangvvan commented 4 years ago

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

mikeliucc commented 3 years ago

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.

nguyenquangtay commented 3 years ago

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

nguyenquangtay commented 3 years ago

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!

marcveiga commented 2 years ago

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>
mikeliucc commented 2 years ago

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

quynhbui267 commented 1 year ago

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?

nguyenquangtay commented 1 year ago

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 :(