statusMessageContainsAfterWait example

$theme_config->save();
      \Drupal::service('router.builder')->rebuildIfNeeded();

      $this->drupalGet('ajax-test/exception-link');
      $page = $this->getSession()->getPage();
      // We don't want the test to error out because of an expected Javascript       // console error.       $this->failOnJavascriptConsoleErrors = FALSE;
      // Click on the AJAX link.       $this->clickLink('Ajax Exception');
      $this->assertSession()
        ->statusMessageContainsAfterWait("Oops, something went wrong. Check your browser's developer console for more details.", 'error');

      if ($theme === 'olivero') {
        // Check that the message can be closed.         $this->click('.messages__close');
        $this->assertTrue($page->find('css', '.messages--error')
          ->hasClass('hidden'));
      }
    }

    // This is needed to avoid an unfinished AJAX request error from tearDown()     // because this test intentionally does not complete all AJAX requests.
fclose($file);

    // Go to the node creation form and try to upload the test file.     $this->drupalGet('node/add/article');
    $page = $session->getPage();
    $page->attachFileToField("files[field_file_0]", $this->fileSystem->realpath($invalid_file));

    // An error message should appear informing the user that the file exceeded     // the maximum file size. The error message includes the actual file size     // limit which depends on the current environment, so we check for a part     // of the message.     $this->assertSession()->statusMessageContainsAfterWait('An unrecoverable error occurred. The uploaded file likely exceeded the maximum file size', 'error');

    // Now upload a valid file and check that the error message disappears.     $valid_file = $this->generateFile('not_exceeding_post_max_size', 8, 8);
    $page->attachFileToField("files[field_file_0]", $this->fileSystem->realpath($valid_file));
    $this->assertSession()->waitForElement('named', ['id_or_name', 'field_file_0_remove_button']);
    $this->assertSession()->statusMessageNotExistsAfterWait('error');
  }

}
// Wait for toolbar to appear.     $this->assertNotEmpty($assert_session->waitForElement('css', 'body.toolbar-horizontal'));

    // Open workspace canvas.     $page->clickLink('Switch workspace');
    $this->waitForOffCanvasToOpen('top');

    // Click 'stage' workspace and confirm switch.     $page->clickLink('Stage');
    $this->assertElementVisibleAfterWait('css', '.workspace-activate-form.workspace-confirm-form');
    $page->find('css', '.ui-dialog-buttonset .button--primary')->click();
    $assert_session->statusMessageContainsAfterWait('Stage is now the active workspace.', 'status');
    // Make sure we stay on same page after switch.     $assert_session->addressEquals('admin');
  }

}


  /** * Tests methods in JsWebAssert related to status messages. */
  public function testJsStatusMessageAssertions(): void {
    $page = $this->getSession()->getPage();

    $this->drupalGet('ajax-test/message');

    $page->pressButton('Make Message In Default Location');
    $this->assertSession()->statusMessageContainsAfterWait('I am a message in the default location.');

    $page->pressButton('Make Message In Alternate Location');
    $this->assertSession()->statusMessageContainsAfterWait('I am a message in an alternate location.', 'status');

    $page->pressButton('Make Warning Message');
    $this->assertSession()->statusMessageContainsAfterWait('I am a warning message in the default location.', 'warning');

    // Reload and test some negative assertions.     $this->drupalGet('ajax-test/message');

    $page->pressButton('Make Message In Default Location');
    
Home | Imprint | This part of the site doesn't use cookies.