diff --git a/.gitignore b/.gitignore index 02e889d..b07d427 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,9 @@ # build folder build/ + +# system +Thumbs.db + resource/windows/php resource/windows/webdriver src/php diff --git a/src/Application.php b/src/Application.php index 5de980f..826a917 100644 --- a/src/Application.php +++ b/src/Application.php @@ -23,6 +23,11 @@ class Application { */ private $logger = null; + /** + * @var array + */ + public $config = []; + /** * @return self */ @@ -108,7 +113,8 @@ public function getTaseCase() { /** * @return void */ - public function start() { + public function start( $config = []) { + $this->config = $config; $params = $this->cliParseParams(); $this->docroot = $params['doc-root']; $this->runTests($params['path'], $params); diff --git a/src/conf.ini b/src/conf.ini new file mode 100644 index 0000000..2681b46 --- /dev/null +++ b/src/conf.ini @@ -0,0 +1,2 @@ +[Browsers] +ChromePath = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" \ No newline at end of file diff --git a/src/index.php b/src/index.php index ffd5d48..b291cd3 100644 --- a/src/index.php +++ b/src/index.php @@ -1,4 +1,5 @@ start(); \ No newline at end of file +$conf = parse_ini_file(__DIR__.'/conf.ini', true); +Application::app()->start($conf); \ No newline at end of file diff --git a/src/operators/OperatorBrowser.php b/src/operators/OperatorBrowser.php index 6b4ab60..6d5a670 100644 --- a/src/operators/OperatorBrowser.php +++ b/src/operators/OperatorBrowser.php @@ -11,6 +11,9 @@ use Facebook\WebDriver\Remote\LocalFileDetector; use app\script\Assertion; use app\script\RuntimeErrorException; +use Facebook\WebDriver\WebDriver; +use Facebook\WebDriver\Exception\NoAlertOpenException; +use Facebook\WebDriver\Exception\NoSuchAlertException; /** * */ @@ -146,11 +149,7 @@ private function startBrowserChrome() { $plarform = \Application::app()->getPlatformName(); switch ( $plarform ) { case 'windows' : - $chromePath = trim(shell_exec("where chrome.exe")); - if ( empty($chromePath) ) { - throw new \Exception("unable to find chrome.exe, please make sure you have chrome.exe in your PATH."); - } - + $chromePath = \Application::app()->config['Browsers']['ChromePath']; $chromePath = str_replace('\\', '\\\\', $chromePath); $chromeVersion = trim(shell_exec("wmic datafile where name=\"{$chromePath}\" get Version /value")); $chromeVersion = explode('.', str_replace('Version=', '', $chromeVersion)); @@ -192,7 +191,7 @@ private function startBrowserChrome() { $driverPath = \Application::app()->getPath("webdriver/chromedriver-{$driverVersion}{$driverExt}"); if ( !file_exists($driverPath) ) { - throw new \Exception("not supported browser type `{$this->browserName}-v{$this->version}`"); + throw new \Exception("not supported browser type `{$this->browserName}-v{$chromeVersion}`"); } $port = $this->findAnAvailablePort(); @@ -557,7 +556,18 @@ public function cmdWaitElemText( $selector, $text, $timeout=null ) { */ public function cmdWaitAlertPresent( $timeout=null ) { $wait = new WebDriverWait($this->driver, $timeout); - $wait->until(WebDriverExpectedCondition::alertIsPresent()); + $wait->until(function( WebDriver $driver ) { + try { + $alert = $driver->switchTo()->alert(); + $alert->getText(); + + return $alert; + } catch (NoAlertOpenException $e) { + return null; + } catch (NoSuchAlertException $e ) { + return null; + } + }); } /** diff --git a/src/script/commands/BaseCommand.php b/src/script/commands/BaseCommand.php index 19b43bf..c0222fe 100644 --- a/src/script/commands/BaseCommand.php +++ b/src/script/commands/BaseCommand.php @@ -141,9 +141,9 @@ protected function getRuntime() { */ public function exec() { $this->testcase->tick($this); + \Application::app()->log("> {$this->getRawCommand()}"); try { $this->run(); - \Application::app()->log("> {$this->getRawCommand()}"); } catch ( \Exception $e ) { $this->testcase->failed($this, $e); } diff --git a/src/script/commands/CommandLog.php b/src/script/commands/CommandLog.php index 315efdb..18dff9f 100644 --- a/src/script/commands/CommandLog.php +++ b/src/script/commands/CommandLog.php @@ -19,6 +19,8 @@ public function setCmdArgs($args) { * @see \app\script\commands\BaseCommand::run() */ protected function run() { - \Application::app()->log(implode('', $this->params)); + $message = implode(' ', $this->params); + \Application::app()->log($message); + echo $message; } } \ No newline at end of file