assertWaitPageContains example

public function testAjaxCommands() {
    $session = $this->getSession();
    $page = $this->getSession()->getPage();

    $form_path = 'ajax_forms_test_ajax_commands_form';
    $web_user = $this->drupalCreateUser(['access content']);
    $this->drupalLogin($web_user);
    $this->drupalGet($form_path);

    // Tests the 'add_css' command.     $page->pressButton("AJAX 'add_css' command");
    $this->assertWaitPageContains('my/file.css');

    // Tests the 'after' command.     $page->pressButton("AJAX 'After': Click to put something after the div");
    $this->assertWaitPageContains('<div id="after_div">Something can be inserted after this</div>This will be placed after');

    // Tests the 'alert' command.     $page->pressButton("AJAX 'Alert': Click to alert");
    // Wait for the alert to appear.     $page->waitFor(10, function D) use ($session) {
      try {
        $session->getDriver()->getWebDriverSession()->getAlert_text();
        

  public function assertInsert(string $render_type, string $expected, string $script = ''): void {
    // Check insert to block element.     $this->drupalGet('ajax-test/insert-block-wrapper');
    $this->getSession()->executeScript($script);
    $this->clickLink("Link html $render_type");
    $this->assertWaitPageContains('<div class="ajax-target-wrapper"><div id="ajax-target">' . $expected . '</div></div>');

    $this->drupalGet('ajax-test/insert-block-wrapper');
    $this->getSession()->executeScript($script);
    $this->clickLink("Link replaceWith $render_type");
    $this->assertWaitPageContains('<div class="ajax-target-wrapper">' . $expected . '</div>');

    // Check insert to inline element.     $this->drupalGet('ajax-test/insert-inline-wrapper');
    $this->getSession()->executeScript($script);
    $this->clickLink("Link html $render_type");
    $this->assertWaitPageContains('<div class="ajax-target-wrapper"><span id="ajax-target-inline">' . $expected . '</span></div>');

    
Home | Imprint | This part of the site doesn't use cookies.