executeAsyncScript doesn't trigger ScriptTimeoutException properly

32 વાર જોવામાં આવી
વાંચ્યા વિનાના પહેલા સંદેશ પર જાઓ

Serhii iLchenko

વાંચ્યા વગરની,
26 સપ્ટે, 2017 12:50:41 AM26/9/17
થી webdriver
I wanted to implement script execution time handling, but stumbled upon this issue. 
If I design webdriver's script to execute in following manner, it successfully returns a variable, but it doesn't trigger ScriptTimeoutException as it should be. 
Any ideas why? I've adopted this script from webdriver's javadoc example

System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
//---setting script timeout to 1ns to force ScriptTimeoutException
driver.manage().timeouts().setScriptTimeout(1, TimeUnit.NANOSECONDS);

//this script works fine, ScriptTimeoutException is triggered
String script1 = "window.setTimeout(arguments[arguments.length - 1], 500);";

//this script is able to pass his return variable back to Java, but doesn't triggers ScriptTimeoutException
String script2 = "var callback = arguments[arguments.length - 1];" +
        "var stringVar = 'abcd';" + 
        "callback(stringVar);";

while (true) {
    Instant beforeScript = Instant.now();
    //((JavascriptExecutor) driver).executeAsyncScript(script1);
    String result = (String) ((JavascriptExecutor) driver).executeAsyncScript(script2);
    System.out.println(result + " " + Duration.between(beforeScript, Instant.now()).toMillis());
}
Using webdriver 3.53 with ChromeDriver 2.32. Also same result with GeckoDriver 0.19 on windows 7 x64
બધાને જવાબ આપો
લેખકને જવાબ આપો
ફૉરવર્ડ કરો
0 નવો સંદેશ