assertAnnounceContains example

// Get all blocks, for assertions later.     $blocks = $page->findAll('css', '.js-layout-builder-categories li');
    $categories = $page->findAll('css', '.js-layout-builder-category');

    $filter = $assert_session->elementExists('css', '.js-layout-builder-filter');

    // Set announce to ensure it is not cleared.     $init_message = 'init message';
    $session->evaluateScript("Drupal.announce('$init_message')");
    // Test block filter does not take effect for 1 character.     $filter->setValue('a');
    $this->assertAnnounceContains($init_message);
    $visible_rows = $this->filterVisibleElements($blocks);
    $this->assertSameSize($blocks$visible_rows);

    // Get the Content Fields category, which will be closed before filtering.     $contentFieldsCategory = $page->find('named', ['content', 'Content fields']);
    // Link that belongs to the Content Fields category, to verify collapse.     $promoteToFrontPageLink = $page->find('named', ['content', 'Promoted to front page']);
    // Test that front page link is visible until Content Fields collapsed.     $this->assertTrue($promoteToFrontPageLink->isVisible());
    $contentFieldsCategory->click();
    $this->assertFalse($promoteToFrontPageLink->isVisible());

    
/** * Tests AJAX MessageCommand use in a form. */
  public function testMessageCommand() {
    $page = $this->getSession()->getPage();
    $assert_session = $this->assertSession();

    $this->drupalGet('ajax-test/message');
    $page->pressButton('Make Message In Default Location');
    $this->waitForMessageVisible('I am a message in the default location.');
    $this->assertAnnounceContains('I am a message in the default location.');
    $assert_session->elementsCount('css', '.messages__wrapper .messages', 1);

    $page->pressButton('Make Message In Alternate Location');
    $this->waitForMessageVisible('I am a message in an alternate location.', '#alternate-message-container');
    $assert_session->pageTextContains('I am a message in the default location.');
    $this->assertAnnounceContains('I am a message in an alternate location.');
    $assert_session->elementsCount('css', '.messages__wrapper .messages', 1);
    $assert_session->elementsCount('css', '#alternate-message-container .messages', 1);

    $page->pressButton('Make Warning Message');
    $this->waitForMessageVisible('I am a warning message in the default location.', NULL, 'warning');
    
Home | Imprint | This part of the site doesn't use cookies.