Skip to content
Snippets Groups Projects
Commit f4a1c020 authored by Adam G-H's avatar Adam G-H Committed by Chris Wells
Browse files

Issue #3508090 by phenaproxima, tim.plunkett: Add assertElementIsVisible() as...

Issue #3508090 by phenaproxima, tim.plunkett: Add assertElementIsVisible() as a more assertive waitForElementVisible()
parent 9c6b2157
No related branches found
No related tags found
1 merge request!741Create a more assertive waitForElementVisible() and use it everywhere
Pipeline #430928 failed
......@@ -51,7 +51,7 @@ class ProjectBrowserExamplePluginTest extends WebDriverTestBase {
$this->drupalGet('admin/modules/browse/project_browser_source_example');
$this->svelteInitHelper('css', '#project-browser .pb-project--grid');
$this->assertEquals('Grid', $this->getElementText('#project-browser .pb-display__button[value="Grid"]'));
$assert_session->waitForElementVisible('css', '#project-browser .pb-project');
$this->assertElementIsVisible('css', '#project-browser .pb-project');
$this->assertTrue($assert_session->waitForText('Project 1'));
$assert_session->pageTextNotContains('No modules found');
$this->svelteInitHelper('css', '.pb-filter__checkbox');
......
......@@ -93,13 +93,10 @@ class ProjectBrowserInstallerUiTest extends WebDriverTestBase {
* such as via the terminal with Compose or a direct file addition.
*/
public function testInstallModuleAlreadyInFilesystem(): void {
$assert_session = $this->assertSession();
$this->drupalGet('admin/modules/browse/project_browser_test_mock');
$this->waitForProject('Pinky and the Brain')
->pressButton('Install Pinky and the Brain');
$popup = $assert_session->waitForElementVisible('css', '.project-browser-popup');
$this->assertNotEmpty($popup);
$popup = $this->assertElementIsVisible('css', '.project-browser-popup');
// The Pinky and the Brain module doesn't actually exist in the filesystem,
// but the test activator pretends it does, in order to test the presence
// of the "Install" button as opposed vs. the default "Add and Install"
......@@ -123,7 +120,7 @@ class ProjectBrowserInstallerUiTest extends WebDriverTestBase {
$this->drupalGet('admin/modules/browse/recipes');
$this->svelteInitHelper('css', '.pb-projects-list');
$this->inputSearchField('image', TRUE);
$assert_session->waitForElementVisible('css', ".search__search-submit")->click();
$this->assertElementIsVisible('css', ".search__search-submit")->click();
// Apply a recipe that ships with core.
$card = $this->waitForProject('Image media type');
......@@ -133,8 +130,7 @@ class ProjectBrowserInstallerUiTest extends WebDriverTestBase {
// If we reload, the installation status should be remembered.
$this->getSession()->reload();
$this->inputSearchField('image', TRUE);
$assert_session->waitForElementVisible('css', ".search__search-submit")
?->click();
$this->assertElementIsVisible('css', ".search__search-submit")->click();
$card = $this->waitForProject('Image media type');
$this->waitForProjectToBeInstalled($card);
......@@ -144,7 +140,7 @@ class ProjectBrowserInstallerUiTest extends WebDriverTestBase {
$this->markTestSkipped('This test cannot continue because this version of Drupal does not support collecting recipe input.');
}
$this->inputSearchField('test', TRUE);
$assert_session->waitForElementVisible('css', ".search__search-submit")->click();
$this->assertElementIsVisible('css', ".search__search-submit")->click();
$this->waitForProject('Test Recipe')->pressButton('Install');
$field = $assert_session->waitForField('test_recipe[new_name]');
$this->assertNotEmpty($field);
......@@ -152,7 +148,7 @@ class ProjectBrowserInstallerUiTest extends WebDriverTestBase {
$page->pressButton('Continue');
$this->checkForMetaRefresh();
$this->inputSearchField('test', TRUE);
$assert_session->waitForElementVisible('css', ".search__search-submit")?->click();
$this->assertElementIsVisible('css', ".search__search-submit")->click();
$this->waitForProjectToBeInstalled('Test Recipe');
$this->assertSame('Y halo thar!', $this->config('system.site')->get('name'));
}
......
......@@ -59,7 +59,7 @@ class ProjectBrowserPluginTest extends WebDriverTestBase {
$this->drupalGet('admin/modules/browse/random_data');
$this->svelteInitHelper('css', '#project-browser .pb-project--grid');
$this->assertEquals('Grid', $this->getElementText('#project-browser .pb-display__button[value="Grid"]'));
$assert_session->waitForElementVisible('css', '#project-browser .pb-project');
$this->assertElementIsVisible('css', '#project-browser .pb-project');
$this->assertTrue($assert_session->waitForText('Results'));
$assert_session->pageTextNotContains('No modules found');
}
......@@ -155,15 +155,13 @@ class ProjectBrowserPluginTest extends WebDriverTestBase {
*/
public function testDetailPageRandomDataPlugin(): void {
$assert_session = $this->assertSession();
$page = $this->getSession()->getPage();
$this->drupalGet('admin/modules/browse/random_data');
$this->assertNotEmpty($assert_session->waitForElementVisible('css', '#project-browser .pb-project'));
$this->assertElementIsVisible('css', '#project-browser .pb-project');
$this->assertTrue($assert_session->waitForText('Results'));
$assert_session->waitForElementVisible('css', '.pb-project .pb-project__title');
$first_project_selector = $page->find('css', '.pb-project .pb-project__title .pb-project__link');
$first_project_selector?->click();
$this->assertElementIsVisible('css', '.pb-project .pb-project__title .pb-project__link')
->click();
$this->assertTrue($assert_session->waitForText('sites report using this module'));
}
......
This diff is collapsed.
......@@ -74,22 +74,22 @@ class ProjectBrowserUiTestJsonApi extends WebDriverTestBase {
$this->getSession()->resizeWindow(1250, 1000);
$this->drupalGet('admin/modules/browse/drupalorg_jsonapi');
$this->svelteInitHelper('css', '.pb-project.pb-project--grid');
$assert_session->waitForElementVisible('css', '#project-browser .pb-display__button[value="Grid"]');
$this->assertElementIsVisible('css', '#project-browser .pb-display__button[value="Grid"]');
$grid_text = $this->getElementText('#project-browser .pb-display__button[value="Grid"]');
$this->assertEquals('Grid', $grid_text);
$this->assertTrue($assert_session->waitForText('Results'));
$assert_session->pageTextNotContains('No records available');
$page->pressButton('List');
$this->assertNotNull($assert_session->waitForElementVisible('css', '#project-browser .pb-project.pb-project--list'));
$this->assertElementIsVisible('css', '#project-browser .pb-project.pb-project--list');
$assert_session->elementsCount('css', '#project-browser .pb-project.pb-project--list', 12);
$page->pressButton('Grid');
$this->assertNotNull($assert_session->waitForElementVisible('css', '#project-browser .pb-project.pb-project--grid'));
$this->assertElementIsVisible('css', '#project-browser .pb-project.pb-project--grid');
$this->getSession()->resizeWindow(1100, 1000);
$assert_session->assertNoElementAfterWait('css', '.toggle.list-button');
$this->assertNotNull($assert_session->waitForElementVisible('css', '#project-browser .pb-project.pb-project--list'));
$this->assertElementIsVisible('css', '#project-browser .pb-project.pb-project--list');
$assert_session->elementsCount('css', '#project-browser .pb-project.pb-project--list', 12);
$this->getSession()->resizeWindow(1210, 1210);
$this->assertNotNull($assert_session->waitForElementVisible('css', '#project-browser .pb-project.pb-project--grid'));
$this->assertElementIsVisible('css', '#project-browser .pb-project.pb-project--grid');
$assert_session->elementsCount('css', '#project-browser .pb-project.pb-project--grid', 12);
}
......@@ -249,7 +249,7 @@ class ProjectBrowserUiTestJsonApi extends WebDriverTestBase {
$assert_session->pageTextNotContains(' 0 Results');
// Click the Active filter.
$assert_session->waitForElementVisible('css', self::DEVELOPMENT_OPTION_SELECTOR);
$this->assertElementIsVisible('css', self::DEVELOPMENT_OPTION_SELECTOR);
$this->clickWithWait(self::DEVELOPMENT_OPTION_SELECTOR . self::OPTION_FIRST_CHILD);
// Make sure the correct filter was applied.
......@@ -353,11 +353,11 @@ class ProjectBrowserUiTestJsonApi extends WebDriverTestBase {
$this->drupalGet('admin/modules/browse/project_browser_test_mock');
// Drupal.org test mock defines only two filters (actively maintained filter
// and security coverage filter).
$assert_session->waitForElementVisible('css', '.search__form-filters-container');
$this->assertElementIsVisible('css', '.search__form-filters-container');
$this->assertTrue($assert_session->waitForText('Maintenance status'));
$assert_session->waitForElementVisible('css', self::MAINTENANCE_OPTION_SELECTOR);
$this->assertElementIsVisible('css', self::MAINTENANCE_OPTION_SELECTOR);
$this->assertTrue($assert_session->waitForText('Security advisory coverage'));
$assert_session->waitForElementVisible('css', self::SECURITY_OPTION_SELECTOR);
$this->assertElementIsVisible('css', self::SECURITY_OPTION_SELECTOR);
// Make sure no other filters are displayed.
$this->assertFalse($assert_session->waitForText('Development status'));
$this->assertNull($assert_session->waitForElementVisible('css', self::DEVELOPMENT_OPTION_SELECTOR));
......@@ -412,7 +412,6 @@ class ProjectBrowserUiTestJsonApi extends WebDriverTestBase {
$this->assertCount(2, $local_tasks);
// Verify that the mocked source is first tab.
$this->assertSame('Contrib modules', $local_tasks[0]->getText());
$assert_session->waitForElementVisible('css', '.pb-display__button');
// Re-order plugins.
$this->drupalGet('admin/config/development/project_browser');
......@@ -426,8 +425,7 @@ class ProjectBrowserUiTestJsonApi extends WebDriverTestBase {
// Verify that Random data is first tab.
$this->drupalGet('admin/modules/browse/drupalorg_jsonapi');
$assert_session->waitForElementVisible('css', '#project-browser .pb-project');
$first_tab = $page->find('css', '.pb-tabs__link:nth-child(1)');
$this->assertElementIsVisible('css', '#project-browser .pb-project');
$this->assertSame('Random data', $local_tasks[0]->getText());
// Disable the mock plugin.
......
......@@ -11,6 +11,21 @@ use Behat\Mink\Element\NodeElement;
*/
trait ProjectBrowserUiTestTrait {
/**
* Waits for an element to be visible, and returns it.
*
* @param mixed ...$arguments
* Arguments to pass to JSWebAssert::waitForElementVisible().
*
* @return \Behat\Mink\Element\NodeElement
* The element we were waiting for.
*/
protected function assertElementIsVisible(mixed ...$arguments): NodeElement {
$element = $this->assertSession()->waitForElementVisible(...$arguments);
$this->assertInstanceOf(NodeElement::class, $element);
return $element;
}
/**
* Installs a specific project.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment