-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated the README.md and added the 2 classes required
- Loading branch information
Dan Mitchell
committed
Mar 22, 2013
1 parent
5423cd6
commit 9557cad
Showing
3 changed files
with
148 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,13 @@ | ||
testingbot-webdriver-phpunit | ||
============================ | ||
|
||
A library for using WebDriver based selenium tests in php with TestingBot. | ||
A library for using WebDriver based selenium tests in php with TestingBot. | ||
|
||
There are a few requirements: | ||
|
||
- PHPUnit, installed from http://pear.phpunit.de using the pear install. | ||
- The PHPUnit_Selenium package that can also be installed from http://pear.phpunit.de | ||
- Finally installing the TestingBot pear package and running the setup script included. | ||
|
||
TestingBot have a guide to get most of the requirements installed, which is located here: | ||
http://testingbot.com/support/getting-started/php.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
class MMT_TestingBot_LocatorStrategy | ||
{ | ||
const CLASS_NAME = 'class name'; | ||
|
||
const CSS_SELECTOR = 'css selector'; | ||
|
||
const ID = 'id'; | ||
|
||
const NAME = 'name'; | ||
|
||
const LINK_TEXT = 'link text'; | ||
|
||
const PARTIAL_LINK_TEXT = 'partial link text'; | ||
|
||
const TAG_NAME = 'tag name'; | ||
|
||
const XPATH = 'xpath'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<?php | ||
|
||
class MMT_TestingBot_WebDriverTestCase extends PHPUnit_Extensions_Selenium2TestCase | ||
{ | ||
/** | ||
* An array containing the API key and secret for a testing bot account. | ||
* | ||
* @var array | ||
*/ | ||
private $_clientData = null; | ||
|
||
protected function tearDown() | ||
{ | ||
$data = array( | ||
'session_id' => $this->getSessionId(), | ||
'client_key' => $this->getClientKey(), | ||
'client_secret' => $this->getClientSecret(), | ||
'status_message' => $this->getStatusMessage(), | ||
'success' => !$this->hasFailed(), | ||
'name' => $this->toString() | ||
); | ||
|
||
$this->_apiCall($data); | ||
|
||
parent::tearDown(); | ||
} | ||
|
||
/** | ||
* Send the result of a test to testing bot. | ||
* | ||
* @param array $postData | ||
* | ||
* @return void | ||
*/ | ||
protected function _apiCall(array $postData) | ||
{ | ||
$data = http_build_query($postData); | ||
$curl = curl_init(); | ||
|
||
curl_setopt($curl, CURLOPT_URL, "http://testingbot.com/hq"); | ||
curl_setopt($curl, CURLOPT_POST, true); | ||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); | ||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data); | ||
|
||
curl_exec($curl); | ||
curl_close($curl); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
private function _getClientData() | ||
{ | ||
if (is_null($this->_clientData)) | ||
{ | ||
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') | ||
{ | ||
$homeDir = substr(__FILE__, 0, 2); | ||
} | ||
else | ||
{ | ||
if (isset($_SERVER['HOME'])) | ||
{ | ||
$homeDir = $_SERVER['HOME']; | ||
} | ||
else | ||
{ | ||
$homeDir = shell_exec('echo $HOME 2>&1'); | ||
} | ||
} | ||
|
||
if (!file_exists($homeDir . DIRECTORY_SEPARATOR . '.testingbot')) | ||
{ | ||
die('Please run testingbot configure "API_KEY:API_SECRET" first.'); | ||
} | ||
|
||
$data = file_get_contents($homeDir . DIRECTORY_SEPARATOR . '.testingbot'); | ||
list($client_key, $client_secret) = explode(':', $data); | ||
|
||
$this->_clientData['client_key'] = $client_key; | ||
$this->_clientData['client_secret'] = $client_secret; | ||
} | ||
|
||
return $this->_clientData; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getClientSecret() | ||
{ | ||
$data = $this->_getClientData(); | ||
return rtrim($data['client_secret'], "\n"); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getClientKey() | ||
{ | ||
$data = $this->_getClientData(); | ||
return $data['client_key']; | ||
} | ||
|
||
/** | ||
* @param string $using | ||
* @param string $value | ||
* | ||
* @return PHPUnit_Extensions_Selenium2TestCase_ElementCriteria | ||
*/ | ||
public function getCriteria($using, $value) | ||
{ | ||
$criteria = new PHPUnit_Extensions_Selenium2TestCase_ElementCriteria($using); | ||
$criteria->value($value); | ||
|
||
return $criteria; | ||
} | ||
} |