Je voulais implémenter la gestion du temps d'exécution du script, mais je suis tombé sur ce problème. Si je conçois le script de webdriver à exécuter de la manière suivante, il renvoie une variable avec succès, mais il ne déclenche pas ScriptTimeoutException comme il se doit. Des idées pourquoi? Je l'ai adopté ce script de webdriver's javadoc exempleexecuteAsyncScript de ChromeDriver ne déclenche pas ScriptTimeoutException correctement
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());
}