Last active
April 6, 2026 03:35
-
-
Save edutrul/f226799a0add28991e7789291737ee91 to your computer and use it in GitHub Desktop.
Best practices for SeleniumTestDriver which unfortunately there's no support yet in DTT as that should use the new driver WebDriver instead. So here's a workaround.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| declare(strict_types=1); | |
| namespace Drupal\Tests\server_general\ExistingSite; | |
| use Symfony\Component\HttpFoundation\Response; | |
| /** | |
| * Tests for the Homepage. | |
| */ | |
| final class HomepageTest extends WebdriverTestBase { | |
| /** | |
| * Test the featured content carousel on homepage. | |
| */ | |
| public function testFeaturedContentCarousel(): void { | |
| $this->drupalGet('<front>'); | |
| $web_assert = $this->assertSession(); | |
| $featured_content = $web_assert->waitForElement('css', '.paragraph--type--related-content'); | |
| $this->assertNotNull($featured_content); | |
| $web_assert->elementTextContains('css', '.paragraph--type--related-content h2', 'Featured Content'); | |
| $carousel = $web_assert->waitForElement('css', '.paragraph--type--related-content .carousel-wrapper.slick-initialized'); | |
| $this->assertNotNull($carousel); | |
| $dots_2 = $carousel->find('css', '.slick-dots li:nth-child(2)'); | |
| $this->assertNotNull($dots_2); | |
| $dots_2->click(); | |
| $this->getSession()->wait(500); | |
| $web_assert->elementTextContains('css', '.paragraph--type--related-content .carousel-slide.slick-current', 'Pandemic Moves Education Online'); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <env name="DTT_WEBDRIVER_HOSTNAME" value="selenium-chrome"/> | |
| <env name="DTT_WEBDRIVER_PORT" value="4444"/> | |
| <!-- The Chrome capabilities (--headless, --no-sandbox, etc.) and the binary path stay in WebdriverTestBase since they can't be configured via DTT_MINK_DRIVER_ARGS anyway — that's the whole reason the base class exists. --> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| declare(strict_types=1); | |
| namespace Drupal\Tests\server_general\ExistingSite; | |
| use Behat\Mink\Driver\DriverInterface; | |
| use Mink\WebdriverClassicDriver\WebdriverClassicDriver; | |
| use weitzman\DrupalTestTraits\ExistingSiteSelenium2DriverTestBase; | |
| /** | |
| * Base class for ExistingSite tests requiring JavaScript support. | |
| * | |
| * Uses WebdriverClassicDriver for Selenium 4 W3C protocol compatibility. | |
| * Extend this class instead of ExistingSiteSelenium2DriverTestBase. | |
| */ | |
| abstract class WebdriverTestBase extends ExistingSiteSelenium2DriverTestBase { | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| protected function getDriverInstance(): DriverInterface { | |
| if (!isset($this->driver)) { | |
| $hostname = getenv('DTT_WEBDRIVER_HOSTNAME') ?: 'selenium-chrome'; | |
| $port = getenv('DTT_WEBDRIVER_PORT') ?: '4444'; | |
| $this->driver = new WebdriverClassicDriver('chrome', [ | |
| 'goog:chromeOptions' => [ | |
| 'binary' => '/usr/bin/chromium', | |
| 'args' => [ | |
| '--disable-dev-shm-usage', | |
| '--disable-gpu', | |
| '--headless', | |
| '--no-sandbox', | |
| ], | |
| ], | |
| ], "http://{$hostname}:{$port}"); | |
| } | |
| return $this->driver; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment