Skip to content

Commit

Permalink
fix some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
MichalLuthor committed Apr 11, 2020
1 parent 627a22e commit bd41b4c
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 11 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# build folder
build/

# system
Thumbs.db

resource/windows/php
resource/windows/webdriver
src/php
Expand Down
8 changes: 7 additions & 1 deletion src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ class Application {
*/
private $logger = null;

/**
* @var array
*/
public $config = [];

/**
* @return self
*/
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/conf.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[Browsers]
ChromePath = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
3 changes: 2 additions & 1 deletion src/index.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
require 'vendor/autoload.php';
require 'Application.php';
Application::app()->start();
$conf = parse_ini_file(__DIR__.'/conf.ini', true);
Application::app()->start($conf);
24 changes: 17 additions & 7 deletions src/operators/OperatorBrowser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
/**
*
*/
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
});
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/script/commands/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 3 additions & 1 deletion src/script/commands/CommandLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit bd41b4c

Please sign in to comment.