assertElementExistsAfterWait example

$this->waitForFieldExists($locator);
    $page->attachFileToField($locator$path);
  }

  /** * Clicks "Save and select||insert" button and waits for AJAX completion. * * @param string $operation * The final word of the button to be clicked. */
  protected function saveAnd($operation) {
    $this->assertElementExistsAfterWait('css', '.ui-dialog-buttonpane')->pressButton("Save and $operation");

    // assertWaitOnAjaxRequest() required for input "id" attributes to     // consistently match their label's "for" attribute.     $this->assertSession()->assertWaitOnAjaxRequest();
  }

  /** * Clicks "Save" button and waits for AJAX completion. * * @param bool $expect_errors * Whether validation errors are expected after the "Save" button is * pressed. Defaults to FALSE. */
'bundle' => 'type_one',
      'field_media_test' => 'Mosquito',
      'status' => FALSE,
    ]);
    $unpublished_media->save();
    // Visit a node create page.     $this->drupalGet('node/add/basic_page');
    // Set the hidden value and trigger the mousedown event on the button via     // JavaScript since the field and button are hidden.     $session->executeScript("jQuery('[data-media-library-widget-value=\"field_unlimited_media\"]').val('1,2,{$unpublished_media->id()}')");
    $session->executeScript("jQuery('[data-media-library-widget-update=\"field_unlimited_media\"]').trigger('mousedown')");
    $this->assertElementExistsAfterWait('css', '.js-media-library-item');
    // Assert the published items are selected and the unpublished item is not     // selected.     $assert_session->pageTextContains('Horse');
    $assert_session->pageTextContains('Bear');
    $assert_session->pageTextNotContains('Mosquito');
    $this->drupalLogout();

    $role = Role::load(RoleInterface::ANONYMOUS_ID);
    $role->revokePermission('view media');
    $role->save();

    
$this->drupalLogin($user);

    $this->drupalGet('/admin/structure/types/manage/article/fields/add-field');
    $page->selectFieldOption('new_storage_type', 'field_ui:entity_reference:media');
    $this->assertNotNull($assert_session->waitForField('label'));
    $page->fillField('label', 'Shatner');
    $this->waitForText('field_shatner');
    $page->pressButton('Save and continue');
    $page->pressButton('Save field settings');
    $assert_session->pageTextNotContains('Undefined index: target_bundles');
    $this->waitForFieldExists('Type One')->check();
    $this->assertElementExistsAfterWait('css', '[name="settings[handler_settings][target_bundles][type_one]"][checked="checked"]');
    $page->checkField('settings[handler_settings][target_bundles][type_two]');
    $this->assertElementExistsAfterWait('css', '[name="settings[handler_settings][target_bundles][type_two]"][checked="checked"]');
    $page->checkField('settings[handler_settings][target_bundles][type_three]');
    $this->assertElementExistsAfterWait('css', '[name="settings[handler_settings][target_bundles][type_three]"][checked="checked"]');
    $page->pressButton('Save settings');
    $assert_session->pageTextContains('Saved Shatner configuration.');

    $this->drupalGet('/admin/structure/types/manage/article/fields/node.article.field_shatner');
    $assert_session->checkboxNotChecked('set_default_value');
    $page->checkField('set_default_value');
    $this->assertElementExistsAfterWait('css', "#field_shatner-media-library-wrapper-default_value_input")
      
public function testFocusNotAppliedWithoutSelectionChange() {
    // Create a node with the maximum number of values for the field_twin_media     // field.     $node = $this->drupalCreateNode([
      'type' => 'basic_page',
      'field_twin_media' => [
        $this->mediaItems['Horse'],
        $this->mediaItems['Bear'],
      ],
    ]);
    $this->drupalGet($node->toUrl('edit-form'));
    $open_button = $this->assertElementExistsAfterWait('css', '.js-media-library-open-button[name^="field_twin_media"]');
    // The open button should be disabled, but not have the     // 'data-disabled-focus' attribute.     $this->assertFalse($open_button->hasAttribute('data-disabled-focus'));
    $this->assertTrue($open_button->hasAttribute('disabled'));
    // The button should be disabled.     $this->assertJsCondition('jQuery("#field_twin_media-media-library-wrapper .js-media-library-open-button").is(":disabled")');
    // The button should not have focus.     $this->assertJsCondition('jQuery("#field_twin_media-media-library-wrapper .js-media-library-open-button").not(":focus")');
  }

  /** * Tests that the Media library's widget works as expected. */
Home | Imprint | This part of the site doesn't use cookies.