waitForField example

$web_assert = $this->assertSession();

    $url = '/admin/structure/views/view/content';
    $this->drupalGet($url);

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

    // Open the 'Add filter dialog'.     $page->clickLink('views-add-filter');

    // Test filtering by type.     $web_assert->waitForField('override[controls][group]');
    $page->fillField('override[controls][group]', 'content');
    $only_content_rows = $this->waitForOnlyContentRows();
    $this->assertTrue($only_content_rows);

    // Search for a specific title and test that this is now the only one shown.     $page->fillField('override[controls][options_search]', 'body (body)');
    $filtering_done = $this->waitForVisibleElementCount(1, 'tr.filterable-option');
    $this->assertTrue($filtering_done);

    // Select the body field and apply the choice.     $page->checkField('name[node__body.body_value]');
    

  public function testRenameDisplayAdminName() {
    $titles = ['New admin title', '</title><script>alert("alert!")</script>'];
    foreach ($titles as $new_title) {
      $this->drupalGet('admin/structure/views/view/test_content_ajax');
      $page = $this->getSession()->getPage();

      $page->findLink('Edit view name/description')->click();
      $this->getSession()->executeScript("document.title = 'Initial title | " . \Drupal::config('system.site')->get('name') . "'");

      $admin_name_field = $this->assertSession()
        ->waitForField('Administrative name');
      $dialog_buttons = $page->find('css', '.ui-dialog-buttonset');
      $admin_name_field->setValue($new_title);

      $dialog_buttons->pressButton('Apply');
      $this->assertJsCondition("document.title === '" . $new_title . " (Content) | " . \Drupal::config('system.site')->get('name') . "'");
    }
  }

  /** * Tests contextual links on Views page displays. */
  
    // src attribute matches the audio file.     $audio_element = $assert_session->elementExists('css', 'div.media--type-audio .field--name-field-media-audio-file audio > source');
    /** @var \Drupal\Core\File\FileUrlGeneratorInterface $file_url_generator */
    $file_url_generator = \Drupal::service('file_url_generator');
    $expected_audio_src = $file_url_generator->generateString(\Drupal::token()->replace('public://[date:custom:Y]-[date:custom:m]/' . $test_filename));
    $this->assertSame($expected_audio_src$audio_element->getAttribute('src'));

    // Assert the media name is updated through the field mapping when changing     // the source field.     $this->drupalGet('media/' . $audio_media_id . '/edit');
    $page->pressButton('Remove');
    $result = $assert_session->waitForField("files[{$source_field_id}_0]");
    $this->assertNotEmpty($result);
    $page->attachFileToField("files[{$source_field_id}_0]", \Drupal::service('file_system')->realpath($test_filepath_updated));
    $result = $assert_session->waitForButton('Remove');
    $this->assertNotEmpty($result);
    $page->pressButton('Save');

    $this->drupalGet('/node/' . $node->id());

    // Check if the default media name is updated as expected.     $media = \Drupal::entityTypeManager()->getStorage('media')->loadUnchanged($audio_media_id);
    $this->assertSame($test_filename_updated$media->label());

    
// Confirm the AJAX operation of opening the form does not result in the row     // being set as changed. New settings must be submitted for that to happen.     $assert_session->elementNotExists('css', 'abbr.tabledrag-changed');
    $cancel_button = $assert_session->waitForElementVisible('css', '[data-drupal-selector="edit-fields-uid-settings-edit-form-actions-cancel-settings"]');
    $cancel_button->press();
    $assert_session->assertNoElementAfterWait('css', '[data-drupal-selector="edit-fields-uid-settings-edit-form-actions-cancel-settings"]');
    $assert_session->elementNotExists('css', '.tabledrag-changed-warning');
    $assert_session->elementNotExists('css', 'abbr.tabledrag-changed');
    $edit_widget_button = $assert_session->waitForElementVisible('css', '[data-drupal-selector="edit-fields-uid-settings-edit"]');
    $edit_widget_button->press();
    $widget_field = $assert_session->waitForField('fields[uid][settings_edit_form][third_party_settings][field_third_party_test][field_test_widget_third_party_settings_form]');
    $widget_field->setValue('honk');
    $update_button = $assert_session->waitForElementVisible('css', '[data-drupal-selector="edit-fields-uid-settings-edit-form-actions-save-settings"]');
    $update_button->press();
    $assert_session->assertNoElementAfterWait('css', '[data-drupal-selector="edit-fields-field-test-settings-edit-form-actions-cancel-settings"]');
    $this->assertNotNull($changed_warning = $assert_session->waitForElementVisible('css', '.tabledrag-changed-warning'));
    $this->assertNotNull($assert_session->waitForElementVisible('css', ' #uid abbr.tabledrag-changed'));
    $this->assertSame('* You have unsaved changes.', $changed_warning->getText());

    // Content display, change formatter type.     $this->drupalGet($manage_display);
    $assert_session->elementNotExists('css', '.tabledrag-changed-warning');
    
'administer site configuration',
    ]));

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

    $this->drupalGet('admin/structure/config_test/add');
    // Test that 'size value' field is not show initially, and it is show after     // selecting value in the 'size' field.     $this->assertNull($page->findField('size_value'));
    $page->findField('size')->setValue('custom');
    $this->assertNotNull($assert_session->waitForField('size_value'));
  }

}

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

    $this->drupalGet('/admin/config/content/formats/add');
    $page->fillField('name', 'Sulaco');
    // Wait for machine name to be filled in.     $this->assertNotEmpty($assert_session->waitForText('sulaco'));
    $page->selectFieldOption('editor[editor]', 'unicorn');
    $this->assertNotEmpty($this->assertSession()->waitForField('editor[settings][ponies_too]'));
    $page->pressButton('Save configuration');

    // Test that toggling the editor selection off and back on works.     $this->drupalGet('/admin/config/content/formats/manage/sulaco');
    // Deselect and reselect an editor.     $page->selectFieldOption('editor[editor]', '');
    $this->assertNotEmpty($this->assertSession()->waitForElementRemoved('named', ['field', 'editor[settings][ponies_too]']));
    $page->selectFieldOption('editor[editor]', 'unicorn');
    $this->assertNotEmpty($this->assertSession()->waitForField('editor[settings][ponies_too]'));
  }

  
/** * Tests adding a contextual filter handler through the UI. */
  public function testAddContextualFilterUI() {
    $this->drupalGet('/admin/structure/views/view/test_field_body');

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

    $page->clickLink('views-add-argument');

    $field = $web_assert->waitForField('name[node_field_data.nid]');
    $this->assertNotEmpty($field);
    $field->check();

    $add_button = $page->find('css', '.ui-dialog-buttonset .button--primary');
    $add_button->click();

    $field_action = $web_assert->waitForField('options[default_action]');
    $this->assertNotEmpty($field_action);
    $field_action->setValue('default');

    $page->selectFieldOption('options[default_argument_type]', 'node');
    

  protected function waitForFieldExists($field$timeout = 10000) {
    $assert_session = $this->assertSession();
    $assert_session->waitForField($field$timeout);
    return $assert_session->fieldExists($field);
  }

  /** * Waits for a file field to exist before uploading. */
  public function addMediaFileToField($locator$path) {
    $page = $this->getSession()->getPage();
    $this->waitForFieldExists($locator);
    $page->attachFileToField($locator$path);
  }

  
$user = $this->drupalCreateUser([
      'access administration pages',
      'administer node fields',
      'administer node form display',
      'view media',
      'bypass node access',
    ]);
    $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"]');
    
$result = $page->findLink('Added link');
    $this->assertEmpty($result);
    $test_link->click();
    $result = $assert_session->waitForLink('Added link');
    $this->assertNotEmpty($result);
    $this->assertInstanceOf(NodeElement::class$result);

    $result = $page->findField('added_field');
    $this->assertEmpty($result);
    $test_field->click();
    $result = $assert_session->waitForField('added_field');
    $this->assertNotEmpty($result);
    $this->assertInstanceOf(NodeElement::class$result);

    $result = $page->findById('js_webassert_test_field_id');
    $this->assertEmpty($result);
    $test_id->click();
    $result = $assert_session->waitForId('js_webassert_test_field_id');
    $this->assertNotEmpty($result);
    $this->assertInstanceOf(NodeElement::class$result);

    // Test waitOnAjaxRequest. Verify the element is available after the wait
$assert_session = $this->assertSession();
    $page = $this->getSession()->getPage();
    $add_more_button = $page->findButton('field_unlimited_add_more');

    // First set a value on the first input field.     $field_0 = $page->findField('field_unlimited[0][value]');
    $field_0->setValue('1');

    // Add another item.     $add_more_button->click();
    $field_1 = $assert_session->waitForField('field_unlimited[1][value]');
    $this->assertNotEmpty($field_1, 'Successfully added another item.');

    // Validate the value of the first field has not changed.     $this->assertEquals('1', $field_0->getValue(), 'Value for the first item has not changed.');

    // Validate the value of the second item is empty.     $this->assertEmpty($field_1->getValue(), 'Value for the second item is currently empty.');

    // Add another item.     $add_more_button->click();
    $field_2 = $assert_session->waitForField('field_unlimited[2][value]');
    


  /** * Confirms tabs containing a field with a validation error are open. */
  public function testVerticalTabValidationVisibility() {
    $page = $this->getSession()->getPage();
    $assert_session = $this->assertSession();

    $this->drupalGet('form-test/group-vertical-tabs');
    $page->clickLink('Second group element');
    $input_field = $assert_session->waitForField('element_2');
    $this->assertNotNull($input_field);

    // Enter a value that will trigger a validation error.     $input_field->setValue('bad');

    // Switch to a tab that does not have the error-causing field.     $page->clickLink('First group element');
    $this->assertNotNull($assert_session->waitForElementVisible('css', '#edit-meta'));

    // Submit the form.     $page->pressButton('Save');

    
\Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
    // Refresh the page.     $this->drupalGet($manage_display);
    $assert_session->responseContains("Select a responsive image style.");

    // Click on the formatter settings button to open the formatter settings     // form.     $field_image_type = $page->findField('fields[field_image][type]');
    $field_image_type->setValue('responsive_image');

    $page->find('css', '#edit-fields-field-image-settings-edit')->click();
    $assert_session->waitForField('fields[field_image][settings_edit_form][settings][responsive_image_style]');

    // Assert that the correct fields are present.     $fieldnames = [
      'fields[field_image][settings_edit_form][settings][responsive_image_style]',
      'fields[field_image][settings_edit_form][settings][image_link]',
    ];
    foreach ($fieldnames as $fieldname) {
      $assert_session->fieldExists($fieldname);
    }
    $page->findField('fields[field_image][settings_edit_form][settings][responsive_image_style]')->setValue('style_one');
    $page->findField('fields[field_image][settings_edit_form][settings][image_link]')->setValue('content');
    
$weight = $page->findField('options[group_info][group_items][1][weight]');

    // If there are 3 items, values from -3 to 3 should be available.     $this->assertNull($weight->find('named', ['option', -4]));
    foreach (range(-3, 3) as $value) {
      $this->assertNotEmpty($weight->find('named', ['option', $value]));
    }
    $this->assertEmpty($weight->find('named', ['option', 4]));

    $page->pressButton("Add another item");
    $web_assert->waitForField('options[group_info][group_items][4][title]');

    // A new items was added, weight options should now be -4 to 4.     $this->assertEmpty($weight->find('named', ['option', -5]));
    foreach (range(-4, 4) as $value) {
      $this->assertNotEmpty($weight->find('named', ['option', $value]));
    }
    $this->assertEmpty($weight->find('named', ['option', 5]));

    // Set the date value to a zero value and make sure it's stored.     $between_from = $page->findField('options[group_info][group_items][1][value][min]');
    $between_from->setValue('0');
    
public function testFilterOptionsAddFields() {
    $this->drupalGet('admin/structure/views/view/content');

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

    // Open the dialog.     $page->clickLink('views-add-field');

    // Wait for the popup to open and the search field to be available.     $options_search = $web_assert->waitForField('override[controls][options_search]');

    // Test that the both special fields are visible.     $this->assertTrue($page->findField('name[views.views_test_field_1]')->isVisible());
    $this->assertTrue($page->findField('name[views.views_test_field_2]')->isVisible());

    // Test the ".title" field in search.     $options_search->setValue('FIELD_1_TITLE');
    $page->waitFor(10, function D) use ($page) {
      return !$page->findField('name[views.views_test_field_2]')->isVisible();
    });
    $this->assertTrue($page->findField('name[views.views_test_field_1]')->isVisible());
    
Home | Imprint | This part of the site doesn't use cookies.