waitForElement example

// To satisfy config schema, the size setting must be an integer, not just     // a numeric value. See https://www.drupal.org/node/2885441.     $this->assertIsInt($form_display->getComponent($field_name)['settings']['size']);
    $form_display->save();
    $this->assertIsInt($form_display->getComponent($field_name)['settings']['size']);

    // Visit the node add page.     $this->drupalGet('node/add/page');
    $page = $this->getSession()->getPage();
    $assert_session = $this->assertSession();

    $autocomplete_field = $assert_session->waitForElement('css', '[name="' . $field_name . '[0][target_id]"].ui-autocomplete-input');
    $autocomplete_field->setValue('Test');
    $this->getSession()->getDriver()->keyDown($autocomplete_field->getXpath(), ' ');
    $assert_session->waitOnAutocomplete();

    $results = $page->findAll('css', '.ui-autocomplete li');

    $this->assertCount(2, $results);
    $assert_session->pageTextContains('Test page');
    $assert_session->pageTextContains('Page test');

    // Now switch the autocomplete widget to the 'STARTS_WITH' match operator.
$this->drupalLogin($this->drupalCreateUser(['administer filters']));

    $page = $this->getSession()->getPage();
    $assert_session = $this->assertSession();

    $this->createNewTextFormat($page$assert_session);
    $assert_session->assertWaitOnAjaxRequest();

    // The Style plugin settings form should not be present.     $assert_session->elementNotExists('css', '[data-drupal-selector="edit-editor-settings-plugins-ckeditor5-style"]');

    $this->assertNotEmpty($assert_session->waitForElement('css', '.ckeditor5-toolbar-item-style'));
    $this->triggerKeyUp('.ckeditor5-toolbar-item-style', 'ArrowDown');
    $assert_session->assertWaitOnAjaxRequest();

    // No validation error upon enabling the Style plugin.     $this->assertNoRealtimeValidationErrors();
    $assert_session->pageTextContains('No styles configured');

    // Still no validation error when configuring other functionality first.     $this->triggerKeyUp('.ckeditor5-toolbar-item-undo', 'ArrowDown');
    $assert_session->assertWaitOnAjaxRequest();
    $this->assertNoRealtimeValidationErrors();

    
$save_button->click();

    // Display the "Manage display" page.     $this->drupalGet($manage_display);

    // Change the formatter and check that the summary is updated.     $page = $this->getSession()->getPage();

    $field_image_type = $page->findField('fields[field_image][type]');
    $field_image_type->setValue('responsive_image');

    $summary_text = $assert_session->waitForElement('xpath', $this->cssSelectToXpath('#field-image .ajax-new-content .field-plugin-summary'));
    $this->assertEquals('Select a responsive image style. Loading attribute: lazy', $summary_text->getText());

    $page->pressButton('Save');
    $assert_session->responseContains("Select a responsive image style.");

    // Create responsive image styles.     $responsive_image_style = ResponsiveImageStyle::create([
      'id' => 'style_one',
      'label' => 'Style One',
      'breakpoint_group' => 'responsive_image_test_module',
      'fallback_image_style' => 'thumbnail',
    ]);
// Open a modal using a link inside a dropbutton.     $page->find('css', '.dropbutton-toggle button')->click();
    $modal_link = $assert_session->waitForElementVisible('css', '.secondary-action a');
    $modal_link->click();
    $assert_session->waitForElementVisible('css', '.ui-dialog');
    $assert_session->assertVisibleInViewport('css', '.ui-dialog .ui-dialog-content');
    $page->pressButton('Close');

    // When the dialog "closes" it is still present, so wait on it switching to     // `display: none;`.     $assert_session->waitForElement('css', '.ui-dialog[style*="display: none;"]');

    // Confirm that when the modal closes, focus is moved to the first visible     // and focusable item in the contextual link container, because the original     // opener is not available.     $this->assertJsCondition('document.activeElement === document.querySelector(".dropbutton-action a")');
  }

}
public function test(): void {
    $assert_session = $this->assertSession();

    // Create test content to ensure that CKEditor 5 text editor can be     // scrolled.     $body = '';
    for ($i = 0; $i < 10; $i++) {
      $body .= '<p>' . $this->randomMachineName(32) . '</p>';
    }
    $edit_url = $this->drupalCreateNode(['type' => 'article', 'body' => ['value' => $body, 'format' => 'test_format']])->toUrl('edit-form');
    $this->drupalGet($edit_url);
    $this->assertNotEmpty($assert_session->waitForElement('css', '#toolbar-bar'));
    $this->assertNotEmpty($assert_session->waitForElement('css', '.ck-editor'));

    // Ensure the body has enough height to enable scrolling. Scroll 110px from     // top of body field to ensure CKEditor 5 toolbar is sticky.     $this->getSession()->evaluateScript('document.body.style.height = "10000px";');
    $this->getSession()->evaluateScript('location.hash = "#edit-body-0-value";');
    $this->getSession()->evaluateScript('scroll(0, document.documentElement.scrollTop + 110);');
    // Focus CKEditor 5 text editor.     $javascript = <<<JS Drupal.CKEditor5Instances.get(document.getElementById("edit-body-0-value").dataset["ckeditor5Id"]).editing.view.focus(); JS;
    
$assert_session->elementNotExists('css', 'figure.table > figcaption');

    // Enable captions and update caption content.     $caption_button = $this->getBalloonButton('Toggle caption on');
    $caption_button->click();
    $caption = $assert_session->waitForElementVisible('css', 'figure.table > figcaption');
    $this->assertEmpty($caption->getText());
    $caption->setValue($this->captionText);
    $this->assertEquals($this->captionText, $caption->getText());

    // Update table cell content.     $table_cell = $assert_session->waitForElement('css', '.ck-editor__nested-editable .ck-table-bogus-paragraph');
    $this->assertNotEmpty($table_cell);
    $table_cell->click();
    $table_cell->setValue($this->tableCellText);
    $table_cell = $page->find('css', 'figure.table > table > tbody > tr > td');
    $this->assertEquals($this->tableCellText, $table_cell->getText());

    $this->assertTableStructureInEditorData();

    // Disable caption, confirm the caption is no longer present.     $table_figure->click();
    $caption_off_button = $this->getBalloonButton('Toggle caption off');
    
// Check that the 'add more' button works.     $field_storage->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
    $field_storage->save();
    $name = $this->randomMachineName();
    $this->drupalGet('user/register');
    $this->page->fillField('edit-name', $name);
    $this->page->fillField('edit-mail', $name . '@example.com');
    $this->page->fillField('test_user_field[0][value]', $value);
    // Add two inputs.     $this->page->pressButton('test_user_field_add_more');
    $this->webAssert->waitForElement('css', 'input[name="test_user_field[1][value]"]');
    $this->page->fillField('test_user_field[1][value]', $value . '1');
    $this->page->pressButton('test_user_field_add_more');
    $this->webAssert->waitForElement('css', 'input[name="test_user_field[2][value]"]');
    $this->page->fillField('test_user_field[2][value]', $value . '2');

    // Submit with three values.     $this->page->pressButton('edit-submit');

    // Check user fields.     $accounts = $this->container->get('entity_type.manager')
      ->getStorage('user')
      
public function testToolbarStoredState() {
    $admin_user = $this->drupalCreateUser([
      'access toolbar',
      'administer site configuration',
      'access content overview',
    ]);
    $this->drupalLogin($admin_user);
    $page = $this->getSession()->getPage();
    $assert_session = $this->assertSession();

    $this->drupalGet('<front>');
    $this->assertNotEmpty($this->assertSession()->waitForElement('css', 'body.toolbar-horizontal'));
    $this->assertNotEmpty($this->assertSession()->waitForElementVisible('css', '.toolbar-tray'));
    $this->assertSession()->waitForElementRemoved('css', '.toolbar-loading');

    $page->clickLink('toolbar-item-user');
    $this->assertNotEmpty($assert_session->waitForElementVisible('css', '#toolbar-item-user.is-active'));

    // Expected state values with the user tray open with horizontal     // orientation.     $expected = [
      'orientation' => 'horizontal',
      'hasActiveTab' => TRUE,
      


  /** * Copied from parent. * * This is Drupal\Tests\field_ui\FunctionalJavascript\EntityDisplayTest::testExtraFields() * with a line changed to reflect Claro's tabledrag selector. */
  public function testExtraFields() {
    entity_test_create_bundle('bundle_with_extra_fields');
    $this->drupalGet('entity_test/structure/bundle_with_extra_fields/display');
    $this->assertSession()->waitForElement('css', '.tabledrag-handle');
    $id = $this->getSession()->getPage()->find('css', '[name="form_build_id"]')->getValue();

    $extra_field_row = $this->getSession()->getPage()->find('css', '#display-extra-field');
    $disabled_region_row = $this->getSession()->getPage()->find('css', '.region-hidden-title');

    $extra_field_row->find('css', '.js-tabledrag-handle')->dragTo($disabled_region_row);
    $this->assertSession()->assertWaitOnAjaxRequest();
    $this->assertSession()
      ->waitForElement('css', "[name='form_build_id']:not([value='$id'])");

    $this->submitForm([], 'Save');
    
// Get the preview.     $this->getPreviewAJAX('test_click_sort_ajax', 'page_1', 0);

    // Test that the header label is present.     $element = $this->assertSession()->elementExists('xpath', '//th[contains(@class, "views-field views-field-name")]/a');

    // Verify link.     $this->assertSession()->linkByHrefExists('preview/page_1?_wrapper_format=drupal_ajax&order=name&sort=desc', 0, 'The output URL is as expected.');

    // Click link to sort.     $element->click();
    $sort_link = $this->assertSession()->waitForElement('xpath', '//th[contains(@class, \'views-field views-field-name is-active\')]/a');

    $this->assertNotEmpty($sort_link);

    // Verify link.     $this->assertSession()->linkByHrefExists('preview/page_1?_wrapper_format=drupal_ajax&order=name&sort=asc', 0, 'The output URL is as expected.');
  }

  /** * Get the preview form and force an AJAX preview update. * * @param string $view_name * The view to test. * @param string $panel_id * The view panel to test. * @param int $row_count * The expected number of rows in the preview. */
/** * Tests workspace canvas can be toggled with JavaScript. */
  public function testWorkspaceCanvasToggling() {
    $page = $this->getSession()->getPage();
    $assert_session = $this->assertSession();

    // Set size for horizontal toolbar.     $this->getSession()->resizeWindow(1200, 600);
    $this->drupalGet('<front>');
    // Wait for toolbar to appear.     $this->assertNotEmpty($assert_session->waitForElement('css', 'body.toolbar-horizontal'));

    // Open workspace canvas.     $page->clickLink('Switch workspace');
    $this->waitForOffCanvasToOpen('top');
    $assert_session->elementExists('css', '.workspaces-dialog');

    // Close Canvas.     $page->pressButton('Close');
    $this->waitForOffCanvasToClose();
    $assert_session->assertNoElementAfterWait('css', '.workspaces-dialog');
  }

  
    $this->createMediaType('image', ['id' => 'image', 'label' => 'Image']);
  }

  /** * Integration test to ensure that CKEditor 5 Plugins translations are loaded. */
  public function test(): void {
    $page = $this->getSession()->getPage();
    $assert_session = $this->assertSession();

    $this->createNewTextFormat($page$assert_session);
    $this->assertNotEmpty($assert_session->waitForElement('css', '.ckeditor5-toolbar-item-drupalMedia'));
    $this->click('#edit-filters-media-embed-status');
    $assert_session->assertWaitOnAjaxRequest();
    $this->triggerKeyUp('.ckeditor5-toolbar-item-drupalMedia', 'ArrowDown');
    $assert_session->assertWaitOnAjaxRequest();
    $this->saveNewTextFormat($page$assert_session);

    $langcode = 'fr';
    ConfigurableLanguage::createFromLangcode($langcode)->save();
    $this->config('system.site')->set('default_langcode', $langcode)->save();

    // Visit a page that will trigger a JavaScript file parsing for
/** * Checks for inclusion of text in #drupal-live-announce. * * @param string $expected_message * The text expected to be present in #drupal-live-announce. * * @internal */
  protected function assertAnnounceContains(string $expected_message): void {
    $assert_session = $this->assertSession();
    $this->assertNotEmpty($assert_session->waitForElement('css', "#drupal-live-announce:contains('$expected_message')"));
  }

  /** * Checks for absence of the given text from #drupal-live-announce. * * @param string $expected_message * The text expected to be absent from #drupal-live-announce. * * @internal */
  protected function assertAnnounceNotContains(string $expected_message): void {
    
/** * Saves a layout and asserts the message is correct. */
  protected function assertSaveLayout() {
    $assert_session = $this->assertSession();
    $page = $this->getSession()->getPage();

    // Reload the page to prevent random failures.     $this->drupalGet($this->getUrl());
    $page->pressButton('Save layout');
    $this->assertNotEmpty($assert_session->waitForElement('css', '.messages--status'));

    if (stristr($this->getUrl(), 'admin/structure') === FALSE) {
      $assert_session->pageTextContains('The layout override has been saved.');
    }
    else {
      $assert_session->pageTextContains('The layout has been saved.');
    }
  }

  /** * Gets the latest block entity id. */

  public function testFieldDelete() {
    $page = $this->getSession()->getPage();
    $assert_session = $this->assertSession();

    $this->drupalGet('admin/structure/types/manage/article/fields');

    $page->find('css', '.dropbutton-toggle button')->click();
    $page->clickLink('Delete');

    // Asserts a dialog opens with the expected text.     $this->assertEquals('Are you sure you want to delete the field Body?', $assert_session->waitForElement('css', '.ui-dialog-title')->getText());

    $page->find('css', '.ui-dialog-buttonset')->pressButton('Delete');
    $assert_session->waitForText('The field Body has been deleted from the Article content type.');
  }

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