Skip to content

Commit

Permalink
tt
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSkrypnyk committed Nov 4, 2024
1 parent 88f4700 commit 61b8d15
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 39 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ jobs:
ports:
- 4444:4444

env:
BEHAT_JAVASCRIPT_BASE_URL: http://172.17.0.1:8888

steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down Expand Up @@ -74,8 +71,10 @@ jobs:
# run: docker compose up -d

- name: Run BDD tests
run: ./vendor/bin/behat --profile=default-ci
run: ./vendor/bin/behat
continue-on-error: ${{ vars.CI_TEST_BDD_IGNORE_FAILURE == '1' }}
env:
BEHAT_JAVASCRIPT_BASE_URL: http://172.17.0.1:8888

- name: Upload logs as artifacts
if: always()
Expand Down
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,16 @@ You may optionally specify size of browser window in the screenshot step:

### Local development setup

### Install dependencies.

```bash
composer install
```

### Start Chrome container.

```bash
composer install # Install dependencies.
docker compose up -d # Start Chrome container.
docker run -d -p 4444:4444 selenium/standalone-chromium:130.0
```

### Lint code
Expand Down
11 changes: 1 addition & 10 deletions behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ default:
contexts:
- FeatureContext:
- screenshot_dir: '%paths.base%/.logs/screenshots'
javascript_base_url: 'http://host.docker.internal:8888'
- BehatCliContext
- DrevOps\BehatScreenshotExtension\Context\ScreenshotContext
- DrevOps\BehatPhpServer\PhpServerContext:
Expand All @@ -22,7 +21,7 @@ default:
browser_name: chrome
javascript_session: selenium2
selenium2:
wd_host: "http://localhost:4445/wd/hub"
wd_host: "http://localhost:4444/wd/hub"
capabilities:
browser: chrome
extra_capabilities:
Expand Down Expand Up @@ -62,11 +61,3 @@ default:
# See @https://github.com/Behat/Behat/pull/1423
junit:
output_path: '%paths.base%/.logs/test_results/behat'

# Profile for testing in CI.
default-ci:
extensions:
Behat\MinkExtension:
base_url: http://172.17.0.1:8888
selenium2:
wd_host: "http://localhost:4444/wd/hub"
6 changes: 0 additions & 6 deletions docker-compose.yml

This file was deleted.

22 changes: 15 additions & 7 deletions src/DrevOps/BehatScreenshotExtension/Context/ScreenshotContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
*/
class ScreenshotContext extends RawMinkContext implements ScreenshotAwareContextInterface {

/**
* Screenshot step line.
*/
Expand Down Expand Up @@ -87,13 +88,13 @@ public function beforeScenarioInit(BeforeScenarioScope $scope): void {
}
catch (\Exception $exception) {
throw new \RuntimeException(
sprintf(
'Please make sure that Selenium server is running. %s',
$exception->getMessage(),
),
$exception->getCode(),
$exception,
);
sprintf(
'Please make sure that Selenium server is running. %s',
$exception->getMessage(),
),
$exception->getCode(),
$exception,
);

Check warning on line 97 in src/DrevOps/BehatScreenshotExtension/Context/ScreenshotContext.php

View check run for this annotation

Codecov / codecov/patch

src/DrevOps/BehatScreenshotExtension/Context/ScreenshotContext.php#L91-L97

Added lines #L91 - L97 were not covered by tests
}
}
}
Expand Down Expand Up @@ -299,6 +300,13 @@ protected function makeFileName(string $ext, ?string $filename = NULL, bool $fai
$url = NULL;
}

if (!empty($url) && !empty(getenv('BEHAT_SCREENSHOT_TOKEN_HOST'))) {
$host = parse_url($url, PHP_URL_HOST);
if ($host) {
$url = str_replace($host, getenv('BEHAT_SCREENSHOT_TOKEN_HOST'), $url);
}
}

$data = [
'ext' => $ext,
'step_name' => $step->getText(),
Expand Down
6 changes: 4 additions & 2 deletions tests/behat/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ class FeatureContext extends MinkContext implements Context {
*/
public function __construct(array $parameters) {
$this->screenshotInitParams($parameters);

$this->javascriptBaseUrl = getenv('BEHAT_JAVASCRIPT_BASE_URL') ?: $parameters['javascript_base_url'] ?: 'http://host.docker.internal:8888';
// Set the screenshot token host to override any real host.
putenv('BEHAT_SCREENSHOT_TOKEN_HOST=example.com');
// Set the JavaScript override base URL.
$this->javascriptBaseUrl = getenv('BEHAT_JAVASCRIPT_BASE_URL') ?: 'http://host.docker.internal:8888';
}

/**
Expand Down
16 changes: 8 additions & 8 deletions tests/behat/features/selenium.feature
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@ Feature: Selenium screenshots
Scenario: Capture a screenshot with name using Selenium driver
Given I am on the screenshot test page
When I save screenshot with name "test.{url_domain}.{url_path}.{ext}"
Then file wildcard "*.host\.docker\.internal\.screenshot\.html\.png" should exist
And file wildcard "*.host\.docker\.internal\.screenshot\.html\.html" should exist
Then file wildcard "*.example\.com.screenshot\.html\.png" should exist
And file wildcard "*.example\.com.screenshot\.html\.html" should exist

@phpserver @javascript
Scenario: Capture a screenshot with name using Selenium driver
Given I am on the screenshot test page
When I save screenshot with name "test.{url_origin}.{ext}"
Then file wildcard "*.http%3A%2F%2Fhost\.docker\.internal\.png" should exist
And file wildcard "*.http%3A%2F%2Fhost\.docker\.internal\.html" should exist
Then file wildcard "*.http%3A%2F%2Fexample\.com\.png" should exist
And file wildcard "*.http%3A%2F%2Fexample\.com\.html" should exist

@phpserver @javascript
Scenario: Capture a screenshot with name using Selenium driver
Given I am on the screenshot test page
When I save screenshot with name "test.{url}.{ext}"
Then file wildcard "*.http%3A%2F%2Fhost\.docker\.internal%3A8888%2Fscreenshot.html.png" should exist
And file wildcard "*.http%3A%2F%2Fhost\.docker\.internal%3A8888%2Fscreenshot.html.html" should exist
Then file wildcard "*.http%3A%2F%2Fexample\.com%3A8888%2Fscreenshot.html.png" should exist
And file wildcard "*.http%3A%2F%2Fexample\.com%3A8888%2Fscreenshot.html.html" should exist

@phpserver @javascript
Scenario: Capture a screenshot with name using Selenium driver
Expand All @@ -59,8 +59,8 @@ Feature: Selenium screenshots
Scenario: Capture a screenshot with name using Selenium driver
Given I am on the screenshot test page with query "foo=test-foo" and fragment "foo-fragment"
When I save screenshot with name "test.{url}.{ext}"
Then file wildcard "*.http%3A%2F%2Fhost\.docker\.internal%3A8888%2Fscreenshot.html%3Ffoo%3Dtest-foo%23foo-fragment.png" should exist
And file wildcard "*.http%3A%2F%2Fhost\.docker\.internal%3A8888%2Fscreenshot.html%3Ffoo%3Dtest-foo%23foo-fragment.html" should exist
Then file wildcard "*.http%3A%2F%2Fexample\.com%3A8888%2Fscreenshot.html%3Ffoo%3Dtest-foo%23foo-fragment.png" should exist
And file wildcard "*.http%3A%2F%2Fexample\.com%3A8888%2Fscreenshot.html%3Ffoo%3Dtest-foo%23foo-fragment.html" should exist

@phpserver @javascript
Scenario: Capture a screenshot with name using Selenium driver
Expand Down

0 comments on commit 61b8d15

Please sign in to comment.