3 namespace Drupal\FunctionalJavascriptTests\Tests;
5 use Behat\Mink\Element\NodeElement;
6 use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
9 * Tests for the JSWebAssert class.
13 class JSWebAssertTest extends JavascriptTestBase {
20 public static $modules = ['js_webassert_test'];
23 * Tests that JSWebAssert assertions work correctly.
25 public function testJsWebAssert() {
26 $this->drupalGet('js_webassert_test_form');
28 $session = $this->getSession();
29 $assert_session = $this->assertSession();
30 $page = $session->getPage();
32 $test_button = $page->findButton('Add button');
33 $test_link = $page->findButton('Add link');
34 $test_field = $page->findButton('Add field');
35 $test_id = $page->findButton('Add ID');
36 $test_wait_on_ajax = $page->findButton('Test assertWaitOnAjaxRequest');
37 $test_wait_on_element_visible = $page->findButton('Test waitForElementVisible');
39 // Test the wait...() methods by first checking the fields aren't available
40 // and then are available after the wait method.
41 $result = $page->findButton('Added button');
42 $this->assertEmpty($result);
43 $test_button->click();
44 $result = $assert_session->waitForButton('Added button');
45 $this->assertNotEmpty($result);
46 $this->assertTrue($result instanceof NodeElement);
48 $result = $page->findLink('Added link');
49 $this->assertEmpty($result);
51 $result = $assert_session->waitForLink('Added link');
52 $this->assertNotEmpty($result);
53 $this->assertTrue($result instanceof NodeElement);
55 $result = $page->findField('added_field');
56 $this->assertEmpty($result);
58 $result = $assert_session->waitForField('added_field');
59 $this->assertNotEmpty($result);
60 $this->assertTrue($result instanceof NodeElement);
62 $result = $page->findById('js_webassert_test_field_id');
63 $this->assertEmpty($result);
65 $result = $assert_session->waitForId('js_webassert_test_field_id');
66 $this->assertNotEmpty($result);
67 $this->assertTrue($result instanceof NodeElement);
69 // Test waitOnAjaxRequest. Verify the element is available after the wait
70 // and the behaviors have run on completing by checking the value.
71 $result = $page->findField('test_assert_wait_on_ajax_input');
72 $this->assertEmpty($result);
73 $test_wait_on_ajax->click();
74 $assert_session->assertWaitOnAjaxRequest();
75 $result = $page->findField('test_assert_wait_on_ajax_input');
76 $this->assertNotEmpty($result);
77 $this->assertTrue($result instanceof NodeElement);
78 $this->assertEquals('js_webassert_test', $result->getValue());
80 $result = $page->findButton('Added WaitForElementVisible');
81 $this->assertEmpty($result);
82 $test_wait_on_element_visible->click();
83 $result = $assert_session->waitForElementVisible('named', ['button', 'Added WaitForElementVisible']);
84 $this->assertNotEmpty($result);
85 $this->assertTrue($result instanceof NodeElement);
86 $this->assertEquals(TRUE, $result->isVisible());