From 9557cad15f82e555feb57155423b3b3a47e91c97 Mon Sep 17 00:00:00 2001 From: Dan Mitchell Date: Fri, 22 Mar 2013 15:50:33 +0000 Subject: [PATCH] Updated the README.md and added the 2 classes required --- README.md | 11 +- library/MMT/TestingBot/LocatorStrategy.php | 20 ++++ library/MMT/TestingBot/WebDriverTestCase.php | 118 +++++++++++++++++++ 3 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 library/MMT/TestingBot/LocatorStrategy.php create mode 100644 library/MMT/TestingBot/WebDriverTestCase.php diff --git a/README.md b/README.md index a42e457..5846dd9 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,13 @@ testingbot-webdriver-phpunit ============================ -A library for using WebDriver based selenium tests in php with TestingBot. \ No newline at end of file +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 \ No newline at end of file diff --git a/library/MMT/TestingBot/LocatorStrategy.php b/library/MMT/TestingBot/LocatorStrategy.php new file mode 100644 index 0000000..f1ac863 --- /dev/null +++ b/library/MMT/TestingBot/LocatorStrategy.php @@ -0,0 +1,20 @@ + $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; + } +}