Skip to content

Commit f80f944

Browse files
authored
Merge pull request #1113 from uuf6429/feature/allow-running-headfull-tests
Allow running tests in headfull mode
2 parents 71c4c6a + 38c892d commit f80f944

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

.github/CONTRIBUTING.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ composer all
6969
composer test -- --testsuite functional
7070
```
7171

72-
If you want to run tests in different browser then "htmlunit" (Chrome or Firefox), you need to setup the browser driver (Chromedriver/Geckodriver), as it is [explained in wiki](https://github.com/php-webdriver/php-webdriver/wiki/Chrome)
72+
If you want to run tests in different browser then "htmlunit" (Chrome or Firefox), you need to set up the browser driver (Chromedriver/Geckodriver), as it is [explained in wiki](https://github.com/php-webdriver/php-webdriver/wiki/Chrome)
7373
and then the `BROWSER_NAME` environment variable:
7474

7575
```sh
@@ -85,3 +85,10 @@ export GECKODRIVER=1
8585
export BROWSER_NAME="firefox"
8686
composer all
8787
```
88+
89+
To see the tests as they are happening (in the browser window), you can disable headless mode. This is useful eg. when debugging the tests or writing a new one:
90+
91+
```sh
92+
export DISABLE_HEADLESS="1"
93+
composer all
94+
```

.github/workflows/tests.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ jobs:
162162
CHROMEDRIVER_PATH: "${{ (matrix.browser == 'chrome' && !matrix.selenium-server) && '/usr/local/share/chromedriver-linux64/chromedriver' || '' }}"
163163
GECKODRIVER_PATH: "${{ (matrix.browser == 'firefox' && !matrix.selenium-server) && '/usr/local/share/gecko_driver/geckodriver' || '' }}"
164164
DISABLE_W3C_PROTOCOL: "${{ matrix.w3c && '0' || '1' }}"
165+
DISABLE_HEADLESS: '0' # We always run headless tests on GitHub Actions
165166
SELENIUM_SERVER: "${{ matrix.selenium-server && '1' || '0' }}"
166167
run: |
167168
if [ "$BROWSER_NAME" = "chrome" ]; then EXCLUDE_GROUP+="exclude-chrome,"; fi

tests/functional/WebDriverTestCase.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ protected function setUp(): void
3838
$this->setUpSauceLabs();
3939
} else {
4040
$browserName = getenv('BROWSER_NAME');
41+
$disableHeadless = filter_var(getenv('DISABLE_HEADLESS') ?: '', FILTER_VALIDATE_BOOLEAN);
4142
if ($browserName === '' || $browserName === false) {
4243
$this->markTestSkipped(
4344
'To execute functional tests browser name must be provided in BROWSER_NAME environment variable'
@@ -46,22 +47,30 @@ protected function setUp(): void
4647

4748
if ($browserName === WebDriverBrowserType::CHROME) {
4849
$chromeOptions = new ChromeOptions();
50+
4951
$chromeOptions->addArguments([
50-
'--headless=new',
5152
'--window-size=1024,768',
5253
'--no-sandbox', // workaround for https://github.com/SeleniumHQ/selenium/issues/4961
5354
'--force-color-profile=srgb',
5455
'--disable-search-engine-choice-screen',
5556
]);
5657

58+
if (!$disableHeadless) {
59+
$chromeOptions->addArguments(['--headless=new']);
60+
}
61+
5762
if (!static::isW3cProtocolBuild()) {
5863
$chromeOptions->setExperimentalOption('w3c', false);
5964
}
6065

6166
$this->desiredCapabilities->setCapability(ChromeOptions::CAPABILITY, $chromeOptions);
6267
} elseif ($browserName === WebDriverBrowserType::FIREFOX) {
6368
$firefoxOptions = new FirefoxOptions();
64-
$firefoxOptions->addArguments(['-headless']);
69+
70+
if (!$disableHeadless) {
71+
$firefoxOptions->addArguments(['-headless']);
72+
}
73+
6574
$this->desiredCapabilities->setCapability(FirefoxOptions::CAPABILITY, $firefoxOptions);
6675
}
6776

0 commit comments

Comments
 (0)