Skip to content

Conversation

@mstrelan
Copy link
Contributor

@mstrelan mstrelan commented Aug 7, 2023

Before:

Testing /data/app/modules/custom/snsw_news/tests/src/Functional

Behat\Mink\Exception\ElementNotFoundException : Element matching css "article .tile-grid a:first-child" not found.

After:

Testing /data/app/modules/custom/snsw_news/tests/src/Functional

ErrorException : The website encountered an unexpected error. Please try again later.

Error: Call to undefined method Drupal\Core\Field\FieldItemList::viewzzz() in Drupal\snsw_profile\Entity\Node\News->build() (line 187 of profiles/custom/snsw_profile/src/Entity/Node/News.php). Drupal\snsw_profile\Handler\SnswNodeViewBuilder->getBuildDefaults() (Line: 157)

@mstrelan mstrelan requested a review from acbramley August 7, 2023 01:57
* Detects an error in the response output and fails with the error message.
*/
protected function detectErrorMessageInResponseOutput(string $response): void {
$error = 'The website encountered an unexpected error. Please try again later.';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, this won't detect Fatal Error messages, e.g. OOM. Maybe we could expand this a little.


### Usage

Once your trait is added to your test base class, you can check detect errors by overriding the `drupalGet` function.
Copy link
Contributor Author

@mstrelan mstrelan Aug 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice if this also covered form submissions and other link clicks. One way to achieve this would be to override the htmlOutput function and detect the error then. The html output contains other messages before the page content so we can't use str_starts_with anymore, and may need to strip some other cruft. Maybe it could check str_contains in the $message and then call $this->getSession()->getPage()->getContent() again to get the error to display.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants