findButton example

$this->drupalGet('/entity_test/delete');
    $assert = $this->assertSession();
    $assert->statusCodeEquals(200);
    $assert->elementTextContains('css', 'h1', 'Are you sure you want to delete these test entity - revisions, data table, and published interface entities?');
    $list_selector = '#entity-test-mulrevpub-delete-multiple-confirm-form > ul[data-drupal-selector="edit-entities"]';
    $assert->elementTextContains('css', $list_selector, 'entity1 (Original translation) - The following test entity - revisions, data table, and published interface translations will be deleted:');
    $assert->elementTextContains('css', $list_selector, 'entity2 spanish');
    $assert->elementTextContains('css', $list_selector, 'entity2 french');
    $assert->elementTextNotContains('css', $list_selector, 'entity3 spanish');
    $assert->elementTextContains('css', $list_selector, 'entity3 french');
    $delete_button = $this->getSession()->getPage()->findButton('Delete');
    $delete_button->click();
    $assert = $this->assertSession();
    $assert->addressEquals('/user/' . $this->account->id());
    $assert->responseContains('Deleted 6 items.');
    $assert->responseContains('1 item has not been deleted because you do not have the necessary permissions.');

    \Drupal::entityTypeManager()->getStorage('entity_test_mulrevpub')->resetCache();
    $remaining_entities = EntityTestMulRevPub::loadMultiple([$entity1->id()$entity2->id()$entity3->id()$entity4->id()]);
    $this->assertCount(3, $remaining_entities);
  }

  
protected function createNodeThroughUi($label$bundle$publish = TRUE) {
    $this->drupalGet('/node/add/' . $bundle);

    /** @var \Behat\Mink\Session $session */
    $session = $this->getSession();
    $this->assertSession()->statusCodeEquals(200);

    /** @var \Behat\Mink\Element\DocumentElement $page */
    $page = $session->getPage();
    $page->fillField('Title', $label);
    if ($publish) {
      $page->findButton('Save')->click();
    }
    else {
      $page->uncheckField('Published');
      $page->findButton('Save')->click();
    }

    $session->getPage()->hasContent("{$label} has been created");

    return $this->getOneEntityByLabel('node', $label);
  }

  

    $remote_paths = [];
    foreach ($real_paths as $path) {
      $remote_paths[] = $web_driver->uploadFileAndGetRemoteFilePath($path);
    }

    // Tests that uploading multiple remote files works with remote path.     $this->drupalGet($entity->toUrl('edit-form'));
    $multiple_field = $this->assertSession()->elementExists('xpath', '//input[@multiple]');
    $multiple_field->setValue(implode("\n", $remote_paths));
    $this->assertSession()->assertWaitOnAjaxRequest();
    $this->getSession()->getPage()->findButton('Save')->click();
    $entity = EntityTest::load($entity->id());
    $this->assertCount(3, $entity->field_file);
  }

}
// Assert the same has been added twice and remove the items again.     $this->waitForElementsCount('css', '.field--name-field-twin-media [data-media-library-item-delta]', 2);
    $assert_session->hiddenFieldValueEquals('field_twin_media[selection][0][target_id]', 4);
    $assert_session->hiddenFieldValueEquals('field_twin_media[selection][1][target_id]', 4);
    $wrapper->pressButton('Remove');
    $this->waitForText('Dog has been removed.');
    $wrapper->pressButton('Remove');
    $this->waitForText('Dog has been removed.');
    $result = $wrapper->waitFor(10, function D$wrapper) {
      /** @var \Behat\Mink\Element\NodeElement $wrapper */
      return $wrapper->findButton('Remove') == NULL;
    });
    $this->assertTrue($result);

    // Assert the selection is persistent in the media library modal, and     // the number of selected items is displayed correctly.     $this->openMediaLibraryForField('field_twin_media');
    // Assert the number of selected items is displayed correctly.     $this->assertSelectedMediaCount('0 of 2 items selected');
    // Select a media item, assert the hidden selection field contains the ID of     // the selected item.     $checkboxes = $this->getCheckboxes();
    
$page = $session->getPage();
    $assert_session = $this->assertSession();

    $field_new_storage_type = $page->findField('new_storage_type');
    $field_new_storage_type->setValue($field_type);

    $field_label = $page->findField('label');
    $this->assertTrue($field_label->isVisible());
    $field_label->setValue($label);
    $machine_name = $assert_session->waitForElementVisible('css', '[name="label"] + * .machine-name-value');
    $this->assertNotEmpty($machine_name);
    $page->findButton('Edit')->press();

    $field_field_name = $page->findField('field_name');
    $this->assertTrue($field_field_name->isVisible());
    $field_field_name->setValue($field_name);

    $page->findButton('Save and continue')->click();

    $assert_session->pageTextContains("These settings apply to the $label field everywhere it is used.");
    $breadcrumb_link = $page->findLink($label);

    // Test breadcrumb.
$storage_type = $page->findField('edit-new-storage-type');
    $storage_type->setValue('image');

    // Set the label.     $label = $page->findField('edit-label');
    $label->setValue('Image');

    // Wait for the machine name.     $assert_session->waitForElementVisible('css', '[name="label"] + * .machine-name-value');

    // Save the current page.     $save_button = $page->findButton('Save and continue');
    $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');

    
$this->createWorkspaceThroughUi('Bears', 'bears');

    // Now edit that same workspace; We should be able to do so.     $bears = Workspace::load('bears');

    $this->drupalGet("/admin/config/workflow/workspaces/manage/{$bears->id()}/edit");
    $this->assertSession()->statusCodeEquals(200);

    $page = $this->getSession()->getPage();
    $page->fillField('label', 'Bears again');
    $page->fillField('id', 'bears');
    $page->findButton('Save')->click();
    $page->hasContent('Bears again (bears)');

    // Now login as a different user and ensure they don't have edit access,     // and vice versa.     $editor2 = $this->drupalCreateUser($permissions);

    $this->drupalLogin($editor2);
    $this->createWorkspaceThroughUi('Packers', 'packers');
    $packers = Workspace::load('packers');

    $this->drupalGet("/admin/config/workflow/workspaces/manage/{$packers->id()}/edit");
    
$link1_modal = $link1_dialog_div->find('css', '#drupal-modal');
    $this->assertNotNull($link1_modal, 'Link was used to open a dialog ( non-modal )');
    $this->assertSession()->responseContains($dialog_contents);

    $dialog_title = $link1_dialog_div->find('css', "span.ui-dialog-title:contains('AJAX Dialog & contents')");
    $this->assertNotNull($dialog_title);
    $dialog_title_amp = $link1_dialog_div->find('css', "span.ui-dialog-title:contains('AJAX Dialog & contents')");
    $this->assertNull($dialog_title_amp);

    // Close open dialog, return to the dialog links page.     $close_button = $link1_dialog_div->findButton('Close');
    $this->assertNotNull($close_button);
    $close_button->press();

    // Tests a modal with a dialog-option.     // Link 2 is similar to Link 1, except it submits additional width     // information which must be echoed in the resulting DOM update.     $this->getSession()->getPage()->clickLink('Link 2 (modal)');
    $dialog = $this->assertSession()->waitForElementVisible('css', 'div.ui-dialog');
    $this->assertNotNull($dialog, 'Link was used to open a dialog ( non-modal, with options )');
    $style = $dialog->getAttribute('style');
    $this->assertStringContainsString('width: 400px;', $stylenew FormattableMarkup('Modal respected the dialog-options width parameter. Style = style', ['%style' => $style]));

    

  public function testSwitchingWorkspaces() {
    $vultures = $this->createWorkspaceThroughUi('Vultures', 'vultures');
    $this->switchToWorkspace($vultures);

    $gravity = $this->createWorkspaceThroughUi('Gravity', 'gravity');

    $this->drupalGet('/admin/config/workflow/workspaces/manage/' . $gravity->id() . '/activate');

    $this->assertSession()->statusCodeEquals(200);
    $page = $this->getSession()->getPage();
    $page->findButton('Confirm')->click();

    // Check that WorkspaceCacheContext provides the cache context used to     // support its functionality.     $this->assertCacheContext('session');

    $page->findLink($gravity->label());
  }

  /** * Tests switching workspace via a query parameter. */
  
protected $defaultTheme = 'stark';

  /** * Tests image buttons can be operated with the keyboard ENTER key. */
  public function testAjaxImageButtonKeypressEnter() {
    // Get a Field UI manage-display page.     $this->drupalGet('ajax_forms_image_button_form');
    $assertSession = $this->assertSession();
    $session = $this->getSession();

    $button = $session->getPage()->findButton('Edit');
    $button->keyPress(13);

    $this->assertNotEmpty($assertSession->waitForElementVisible('css', '#ajax-1-more-div'), 'Page updated after image button pressed');
  }

  /** * Tests image buttons can be operated with the keyboard SPACE key. */
  public function testAjaxImageButtonKeypressSpace() {
    // Get a Field UI manage-display page.     $this->drupalGet('ajax_forms_image_button_form');
    
$this->assertSession()->pageTextContains(new FormattableMarkup('Updated book @book.', ['@book' => $book->getTitle()]));

    // Check that page reordering was done in the backend for drag-n-drop.     $page1 = Node::load($page1->id());
    $page2 = Node::load($page2->id());
    $this->assertGreaterThan($page2->book['weight']$page1->book['weight']);

    // Check again that '2nd page' is on top after form submit in the UI.     $this->assertOrderInPage(['2nd page', '1st page']);

    // Toggle row weight selects as visible.     $page->findButton('Show row weights')->click();

    // Check that rows weight selects are visible.     $this->assertTrue($weight_select1->isVisible());
    $this->assertTrue($weight_select2->isVisible());

    // Check that '1st page' row became heavier than '2nd page' row.     $this->assertGreaterThan($weight_select2->getValue()$weight_select1->getValue());

    // Reverse again using the weight fields. Use the current values so the test     // doesn't rely on knowing the values in the select boxes.     $value1 = $weight_select1->getValue();
    
$this->drupalLogin($this->drupalCreateUser([
      'access contextual links',
      'configure any layout',
    ]));
    $this->drupalGet('node/1/layout');
    $page->findLink('Add block')->click();
    $this->assertNotEmpty($assert_session->waitForElementVisible('css', '#drupal-off-canvas .block-categories'));
    $page->findLink('Powered by Drupal')->click();
    $this->assertNotEmpty($assert_session->waitForElementVisible('css', '#drupal-off-canvas [name="settings[label]"]'));
    $page->findField('Title')->setValue('');
    $page->findButton('Add block')->click();
    $this->assertMessagesDisplayed();
    $page->findField('Title')->setValue('New title');
    $page->pressButton('Add block');
    $block_css_locator = '#layout-builder .block-system-powered-by-block';
    $this->assertNotEmpty($assert_session->waitForElementVisible('css', $block_css_locator));

    $assert_session->assertNoElementAfterWait('css', '#drupal-off-canvas');
    $assert_session->assertWaitOnAjaxRequest();
    $this->drupalGet($this->getUrl());
    $page->findButton('Save layout')->click();
    $this->assertNotEmpty($assert_session->waitForElement('css', 'div:contains("The layout override has been saved")'));

    
$setting_value = $display_options['settings'][$setting_name];

    // Display the "Manage display" screen and check that the expected formatter     // is selected.     $this->drupalGet($manage_display);

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

    // Find commonly used elements in this test.     $button_save = $page->findButton('Save');
    $field_test_format_type = $page->findField('fields[field_test][type]');
    $field_test_drag_handle = $page->find('css', '#field-test .tabledrag-handle');
    $field_test_settings = $page->find('css', 'input[name="field_test_settings_edit"]');
    $weight_toggle = $page->find('css', '.tabledrag-toggle-weight');

    // Assert the format type field is visible and contains the expected     // formatter.     $this->assertTrue($field_test_format_type->isVisible());
    $this->assertEquals($format$field_test_format_type->getValue());
    $assert_session->responseContains("$setting_name: $setting_value");

    
    $this->getSession()->resizeWindow(1200, 600);
    $this->drupalGet('<front>');
    $this->assertNotEmpty($this->assertSession()->waitForElement('css', 'body.toolbar-horizontal'));
    $this->assertNotEmpty($this->assertSession()->waitForElementVisible('css', '.toolbar-tray'));

    // Test that the orientation toggle does not appear.     $page = $this->getSession()->getPage();
    $tray = $page->findById('toolbar-item-administration-tray');
    $this->assertTrue($tray->hasClass('toolbar-tray-horizontal'), 'Toolbar tray is horizontally oriented by default.');
    $this->assertSession()->elementNotExists('css', '#toolbar-item-administration-tray .toolbar-menu');
    $this->assertSession()->elementNotExists('css', '#toolbar-item-administration-tray .toolbar-toggle-orientation');
    $button = $page->findButton('Vertical orientation');
    $this->assertFalse($button->isVisible(), 'Orientation toggle from other tray is not visible');
  }

}
/** * Finds the show/hide weight toggle element. * * @param string $expected_text * The expected text on the element. * * @return \Behat\Mink\Element\NodeElement * The toggle element. */
  protected function findWeightsToggle($expected_text) {
    $toggle = $this->getSession()->getPage()->findButton($expected_text);
    $this->assertNotEmpty($toggle);
    return $toggle;
  }

  /** * Moves a row through the keyboard. * * @param \Behat\Mink\Element\NodeElement $row * The row to move. * @param string $arrow * The arrow button to use to move the row. Either one of 'left', 'right', * 'up' or 'down'. * @param int $repeat * (optional) How many times to press the arrow button. Defaults to 1. */
Home | Imprint | This part of the site doesn't use cookies.