Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\FunctionalJavascriptTests\Tests;
|
Chris@0
|
4
|
Chris@0
|
5 use Behat\Mink\Element\NodeElement;
|
Chris@17
|
6 use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
|
Chris@0
|
7
|
Chris@0
|
8 /**
|
Chris@0
|
9 * Tests for the JSWebAssert class.
|
Chris@0
|
10 *
|
Chris@0
|
11 * @group javascript
|
Chris@0
|
12 */
|
Chris@17
|
13 class JSWebAssertTest extends WebDriverTestBase {
|
Chris@0
|
14
|
Chris@0
|
15 /**
|
Chris@0
|
16 * Required modules.
|
Chris@0
|
17 *
|
Chris@0
|
18 * @var array
|
Chris@0
|
19 */
|
Chris@0
|
20 public static $modules = ['js_webassert_test'];
|
Chris@0
|
21
|
Chris@0
|
22 /**
|
Chris@0
|
23 * Tests that JSWebAssert assertions work correctly.
|
Chris@0
|
24 */
|
Chris@0
|
25 public function testJsWebAssert() {
|
Chris@0
|
26 $this->drupalGet('js_webassert_test_form');
|
Chris@0
|
27
|
Chris@0
|
28 $session = $this->getSession();
|
Chris@0
|
29 $assert_session = $this->assertSession();
|
Chris@0
|
30 $page = $session->getPage();
|
Chris@0
|
31
|
Chris@0
|
32 $test_button = $page->findButton('Add button');
|
Chris@0
|
33 $test_link = $page->findButton('Add link');
|
Chris@0
|
34 $test_field = $page->findButton('Add field');
|
Chris@0
|
35 $test_id = $page->findButton('Add ID');
|
Chris@0
|
36 $test_wait_on_ajax = $page->findButton('Test assertWaitOnAjaxRequest');
|
Chris@0
|
37 $test_wait_on_element_visible = $page->findButton('Test waitForElementVisible');
|
Chris@0
|
38
|
Chris@0
|
39 // Test the wait...() methods by first checking the fields aren't available
|
Chris@0
|
40 // and then are available after the wait method.
|
Chris@0
|
41 $result = $page->findButton('Added button');
|
Chris@0
|
42 $this->assertEmpty($result);
|
Chris@0
|
43 $test_button->click();
|
Chris@0
|
44 $result = $assert_session->waitForButton('Added button');
|
Chris@0
|
45 $this->assertNotEmpty($result);
|
Chris@0
|
46 $this->assertTrue($result instanceof NodeElement);
|
Chris@0
|
47
|
Chris@0
|
48 $result = $page->findLink('Added link');
|
Chris@0
|
49 $this->assertEmpty($result);
|
Chris@0
|
50 $test_link->click();
|
Chris@0
|
51 $result = $assert_session->waitForLink('Added link');
|
Chris@0
|
52 $this->assertNotEmpty($result);
|
Chris@0
|
53 $this->assertTrue($result instanceof NodeElement);
|
Chris@0
|
54
|
Chris@0
|
55 $result = $page->findField('added_field');
|
Chris@0
|
56 $this->assertEmpty($result);
|
Chris@0
|
57 $test_field->click();
|
Chris@0
|
58 $result = $assert_session->waitForField('added_field');
|
Chris@0
|
59 $this->assertNotEmpty($result);
|
Chris@0
|
60 $this->assertTrue($result instanceof NodeElement);
|
Chris@0
|
61
|
Chris@0
|
62 $result = $page->findById('js_webassert_test_field_id');
|
Chris@0
|
63 $this->assertEmpty($result);
|
Chris@0
|
64 $test_id->click();
|
Chris@0
|
65 $result = $assert_session->waitForId('js_webassert_test_field_id');
|
Chris@0
|
66 $this->assertNotEmpty($result);
|
Chris@0
|
67 $this->assertTrue($result instanceof NodeElement);
|
Chris@0
|
68
|
Chris@0
|
69 // Test waitOnAjaxRequest. Verify the element is available after the wait
|
Chris@0
|
70 // and the behaviors have run on completing by checking the value.
|
Chris@0
|
71 $result = $page->findField('test_assert_wait_on_ajax_input');
|
Chris@0
|
72 $this->assertEmpty($result);
|
Chris@0
|
73 $test_wait_on_ajax->click();
|
Chris@0
|
74 $assert_session->assertWaitOnAjaxRequest();
|
Chris@0
|
75 $result = $page->findField('test_assert_wait_on_ajax_input');
|
Chris@0
|
76 $this->assertNotEmpty($result);
|
Chris@0
|
77 $this->assertTrue($result instanceof NodeElement);
|
Chris@0
|
78 $this->assertEquals('js_webassert_test', $result->getValue());
|
Chris@0
|
79
|
Chris@0
|
80 $result = $page->findButton('Added WaitForElementVisible');
|
Chris@0
|
81 $this->assertEmpty($result);
|
Chris@0
|
82 $test_wait_on_element_visible->click();
|
Chris@0
|
83 $result = $assert_session->waitForElementVisible('named', ['button', 'Added WaitForElementVisible']);
|
Chris@0
|
84 $this->assertNotEmpty($result);
|
Chris@0
|
85 $this->assertTrue($result instanceof NodeElement);
|
Chris@0
|
86 $this->assertEquals(TRUE, $result->isVisible());
|
Chris@0
|
87 }
|
Chris@0
|
88
|
Chris@0
|
89 }
|