I'm trying to execute an AJAX request in the browser in Codeception. There is the function
$I->executeAsyncJS(); Manual https://codeception.com/docs/modules/WebDriver#executeAsyncJS
I'm trying to understand the manual. It says:
Executes asynchronous JavaScript. A callback should be executed by JavaScript to exit from a script. Callback is passed as a last element in arguments array. Additional arguments can be passed as array in second parameter.
I just don't understand what this is saying. Here's what I have so far:
JS on Page:
const Done = {}; Done.result = function(){ return "Happy"; } Codeception Selenium WebDriver Chrome Test:
<?php class SEQuestionCest { public function itShouldReturnJoy(\AcceptanceTester $I){ $I->amOnPage("/page.php"); $happy = $I->executeJS("return Done.result();"); $I->assertEquals($happy, "Happy"); //This works $happy = $I->executeAsyncJS("setTimeout(function() { return Done.result(); }, 2000);"); //I'm doing something wrong $I->assertEquals($happy, "Happy"); } } I expected it to return after 2 seconds, but instead it just times out after about 20 seconds. I thought the timeout function would simulate an AJAX call. I'm doing something very wrong obviously.
