Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ vendor/*
attachments/*
temp/*
uploads/*
test/screenshots/
# Ignore Mac DS_Store files
.DS_Store
/vendor/
Expand Down
39 changes: 7 additions & 32 deletions test/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
class FeatureContext extends MinkContext implements Context, SnippetAcceptingContext
{
protected $scenarioTitle = null;
protected static $wsendUser = null;
private $roleData;
/**
* Initializes context.
Expand Down Expand Up @@ -151,44 +150,20 @@ public function takeAScreenshot()
$filename = $this->getScreenshotFilename();
file_put_contents($filename, $screenshot);

$url = $this->getScreenshotUrl($filename);

print sprintf("Screenshot is available :\n%s", $url);
}

protected function getScreenshotUrl($filename)
{
if (!self::$wsendUser) {
self::$wsendUser = $this->getWsendUser();
}
exec(sprintf(
'curl -F "uid=%s" -F "filehandle=@%s" %s 2>/dev/null',
self::$wsendUser,
$filename,
'https://wsend.net/upload_cli'
), $output);
return $output[0];
}

protected function getWsendUser()
{
// create a wsend anonymous user
$curl = curl_init('https://wsend.net/createunreg');
curl_setopt($curl, CURLOPT_POSTFIELDS, 'start=1');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

$wsendUser = curl_exec($curl);
curl_close($curl);

return $wsendUser;
print sprintf("Screenshot is available :\n%s\n", $filename);
}

protected function getScreenshotFilename()
{
$filename = $this->scenarioTitle;
$filename = preg_replace("#[^a-zA-Z0-9\._-]#", '_', $filename);

$directory = __DIR__ . '/../../screenshots';
if (!is_dir($directory)) {
mkdir($directory, 0777, true);
}

return sprintf('%s/%s.png', sys_get_temp_dir(), $filename);
return sprintf('%s/%s.png', $directory, $filename);
}

protected function isJavascript()
Expand Down
Loading