Skip to content

Commit

Permalink
Implemented Guzzle requests instead of cURL ones
Browse files Browse the repository at this point in the history
  • Loading branch information
Serge Skripchuk authored and Bergil32 committed Sep 7, 2016
1 parent 434e695 commit 63510c6
Showing 1 changed file with 50 additions and 19 deletions.
69 changes: 50 additions & 19 deletions features/bootstrap/ScreenshotContext.php
Expand Up @@ -2,14 +2,33 @@

use Behat\Testwork\Tester\Result\TestResult;
use Behat\Mink\Driver\Selenium2Driver;
use GuzzleHttp\Client;

class ScreenshotContext extends PageObjectExtension
{
protected $scenarioTitle = null;
protected static $wsendUser = null;
protected $basicScreenshotFolder = 'artifacts/screenshots';

/**
/**
* Guzzle client.
*
* @var \GuzzleHttp\Client
*/
protected $guzzle;

/**
* ScreenshotContext constructor.
*/
public function __construct()
{
parent::__construct();

// Initialize Guzzle client.
$this->guzzle = new Client();
}

/**
* @BeforeScenario
*/
public function cacheScenarioName($event)
Expand All @@ -35,7 +54,7 @@ public function takeScreenshotAfterFailedStep($event)
*/
protected function folderForScreenshots()
{
if(!is_dir($this->basicScreenshotFolder)) {
if (!is_dir($this->basicScreenshotFolder)) {
mkdir($this->basicScreenshotFolder);
}
}
Expand Down Expand Up @@ -80,27 +99,39 @@ protected function getScreenshotUrl($filename)
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);

return $output[0];
// Send screenshot to Wsend.
$response = $this->guzzle->post(
'https://wsend.net/upload_cli',
[
'multipart' => [
[
'name' => 'uid',
'contents' => ScreenshotContext::$wsendUser,
],
[
'name' => 'filehandle',
'contents' => fopen($filename, 'r'),
],
],
]
);

return $response->getBody();
}

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;
return $this
->guzzle
->post(
'https://wsend.net/createunreg',
[
'form_params' => [
'start' => 1,
],
]
)
->getBody();
}

protected function getScreenshotFilename()
Expand Down

0 comments on commit 63510c6

Please sign in to comment.