Skip to content

Commit

Permalink
Allow exceptions to bubble through
Browse files Browse the repository at this point in the history
  • Loading branch information
tr33m4n committed Feb 9, 2020
1 parent 445b890 commit 25d2766
Showing 1 changed file with 29 additions and 31 deletions.
60 changes: 29 additions & 31 deletions src/Codeception/Module/Percy.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ public function _initialize()
/**
* Take snapshot of DOM and send to https://percy.io
*
* @throws \Codeception\Module\Percy\Exception\ClientException
* @throws \Codeception\Module\Percy\Exception\ConfigException
* @param string $name
* @param array|null $widths
* @param int|null $minHeight
Expand All @@ -92,42 +94,38 @@ public function wantToTakeAPercySnapshot(
?string $percyCss = null,
?bool $enableJavaScript = null
) : void {
try {
// Add Percy agent JS to page
$this->webDriver->executeJS($this->percyAgentJs);

$payload = Payload::from($this->getSnapshotConfig())
->withName($name)
->withUrl($this->webDriver->webDriver->getCurrentURL())
->withDomSnapshot($this->webDriver->executeJS(
sprintf(
'var percyAgentClient = new PercyAgent(%s); return percyAgentClient.snapshot(\'not used\')',
json_encode($this->_getConfig('agentConfig'))
)
))
->withClientInfo($this->infoProvider->getClientInfo())
->withEnvironmentInfo($this->infoProvider->getEnvironmentInfo());

if ($widths !== null) {
$payload = $payload->withWidths($widths);
}
// Add Percy agent JS to page
$this->webDriver->executeJS($this->percyAgentJs);

if ($minHeight !== null) {
$payload = $payload->withMinHeight($minHeight);
}
$payload = Payload::from($this->getSnapshotConfig())
->withName($name)
->withUrl($this->webDriver->webDriver->getCurrentURL())
->withDomSnapshot($this->webDriver->executeJS(
sprintf(
'var percyAgentClient = new PercyAgent(%s); return percyAgentClient.snapshot(\'not used\')',
json_encode($this->_getConfig('agentConfig'))
)
))
->withClientInfo($this->infoProvider->getClientInfo())
->withEnvironmentInfo($this->infoProvider->getEnvironmentInfo());

if ($percyCss !== null) {
$payload = $payload->withPercyCss($percyCss);
}
if ($widths !== null) {
$payload = $payload->withWidths($widths);
}

if ($enableJavaScript !== null) {
$payload = $payload->withEnableJavaScript($enableJavaScript);
}
if ($minHeight !== null) {
$payload = $payload->withMinHeight($minHeight);
}

Client::fromUrl($this->buildUrl($this->_getConfig('agentPostPath')))->withPayload($payload)->post();
} catch (Exception $exception) {
$this->debugSection('percy', $exception->getMessage());
if ($percyCss !== null) {
$payload = $payload->withPercyCss($percyCss);
}

if ($enableJavaScript !== null) {
$payload = $payload->withEnableJavaScript($enableJavaScript);
}

Client::fromUrl($this->buildUrl($this->_getConfig('agentPostPath')))->withPayload($payload)->post();
}

/**
Expand Down

0 comments on commit 25d2766

Please sign in to comment.