diff -u b/core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php b/core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php --- b/core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php +++ b/core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php @@ -30,14 +30,14 @@ public function assertWaitOnAjaxRequest($timeout = 10000, $message = 'Unable to complete AJAX request.') { $condition = <<session->getPage(); $result = $page->waitFor($timeout, function() use ($page, $selector, $locator) { - if($element = $page->find($selector, $locator)) { - return $element->isVisible(); + $element = $page->find($selector, $locator); + if (!empty($element) && $element->isVisible()) { + return $element; } return null; }); @@ -107,12 +108,14 @@ * * @param string $locator * The button ID, value or alt string. + * @param int $timeout + * (Optional) Timeout in milliseconds, defaults to 10000. * * @return \Behat\Mink\Element\NodeElement|null * The page element node if found, NULL if not. */ - public function waitForButton($locator) { - return $this->waitForElement('named', array('button', $locator)); + public function waitForButton($locator, $timeout = 10000) { + return $this->waitForElement('named', array('button', $locator), $timeout); } /** @@ -120,12 +123,14 @@ * * @param string $locator * The link ID, title, text or image alt. + * @param int $timeout + * (Optional) Timeout in milliseconds, defaults to 10000. * * @return \Behat\Mink\Element\NodeElement|null * The page element node if found, NULL if not. */ - public function waitForLink($locator) { - return $this->waitForElement('named', array('link', $locator)); + public function waitForLink($locator, $timeout = 10000) { + return $this->waitForElement('named', array('link', $locator), $timeout); } /** @@ -133,12 +138,14 @@ * * @param string $locator * The input ID, name or label for the field (input, textarea, select). + * @param int $timeout + * (Optional) Timeout in milliseconds, defaults to 10000. * * @return \Behat\Mink\Element\NodeElement|null * The page element node if found, NULL if not. */ - public function waitForField($locator) { - return $this->waitForElement('named', array('field', $locator)); + public function waitForField($locator, $timeout = 10000) { + return $this->waitForElement('named', array('field', $locator), $timeout); } /** @@ -146,12 +153,14 @@ * * @param string $id * The element ID. + * @param int $timeout + * (Optional) Timeout in milliseconds, defaults to 10000. * * @return \Behat\Mink\Element\NodeElement|null * The page element node if found, NULL if not. */ - public function waitForId($id) { - return $this->waitForElement('named', array('id', $id)); + public function waitForId($id, $timeout = 10000) { + return $this->waitForElement('named', array('id', $id), $timeout); } /** diff -u b/core/tests/Drupal/FunctionalJavascriptTests/Tests/JSWebAssertTest.php b/core/tests/Drupal/FunctionalJavascriptTests/Tests/JSWebAssertTest.php --- b/core/tests/Drupal/FunctionalJavascriptTests/Tests/JSWebAssertTest.php +++ b/core/tests/Drupal/FunctionalJavascriptTests/Tests/JSWebAssertTest.php @@ -2,6 +2,7 @@ namespace Drupal\FunctionalJavascriptTests\Tests; +use Behat\Mink\Element\NodeElement; use Drupal\FunctionalJavascriptTests\JavascriptTestBase; /** @@ -37,45 +38,51 @@ // Test the wait...() methods by first checking the fields aren't available // and then are available after the wait method. - $test_button->click(); $result = $page->findButton('Added button'); $this->assertEmpty($result); + $test_button->click(); $result = $assert_session->waitForButton('Added button'); $this->assertNotEmpty($result); + $this->assertTrue($result instanceof NodeElement); - $test_link->click(); $result = $page->findLink('Added link'); $this->assertEmpty($result); + $test_link->click(); $result = $assert_session->waitForLink('Added link'); $this->assertNotEmpty($result); + $this->assertTrue($result instanceof NodeElement); - $test_field->click(); $result = $page->findField('added_field'); $this->assertEmpty($result); + $test_field->click(); $result = $assert_session->waitForField('added_field'); $this->assertNotEmpty($result); + $this->assertTrue($result instanceof NodeElement); - $test_id->click(); $result = $page->findById('js_webassert_test_field_id'); $this->assertEmpty($result); + $test_id->click(); $result = $assert_session->waitForId('js_webassert_test_field_id'); $this->assertNotEmpty($result); + $this->assertTrue($result instanceof NodeElement); // Test waitOnAjaxRequest. Verify the element is available after the wait // and the behaviors have run on completing by checking the value. - $test_wait_on_ajax->click(); $result = $page->findField('test_assert_wait_on_ajax_input'); $this->assertEmpty($result); + $test_wait_on_ajax->click(); $assert_session->assertWaitOnAjaxRequest(); $result = $page->findField('test_assert_wait_on_ajax_input'); $this->assertNotEmpty($result); + $this->assertTrue($result instanceof NodeElement); $this->assertEquals('js_webassert_test', $result->getValue()); - $test_wait_on_element_visible->click(); $result = $page->findButton('Added WaitForElementVisible'); $this->assertEmpty($result); + $test_wait_on_element_visible->click(); $result = $assert_session->waitForElementVisible('named', array('button', 'Added WaitForElementVisible')); $this->assertNotEmpty($result); + $this->assertTrue($result instanceof NodeElement); $this->assertEquals(TRUE, $result->isVisible()); } only in patch2: unchanged: --- a/core/tests/Drupal/FunctionalJavascriptTests/EntityReference/EntityReferenceAutocompleteWidgetTest.php +++ b/core/tests/Drupal/FunctionalJavascriptTests/EntityReference/EntityReferenceAutocompleteWidgetTest.php @@ -88,7 +88,7 @@ public function testEntityReferenceAutocompleteWidget() { $page = $this->getSession()->getPage(); $autocomplete_field = $page->findField($field_name . '[0][target_id]'); - $autocomplete_field->setValue('Test'); + $autocomplete_field->setValue('Test page'); $this->getSession()->getDriver()->keyDown($autocomplete_field->getXpath(), ' '); $assert_session->waitOnAutocomplete();