Skip to content

Commit

Permalink
added constants to config.example file for the platform and exe paths…
Browse files Browse the repository at this point in the history
… required for windows.
  • Loading branch information
Ian Greene authored and Ian Greene committed Dec 1, 2022
1 parent 5737a06 commit 8a73e90
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/PunchTheClock.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
namespace Punch;

require_once __DIR__ . '/config.php';

use Facebook\WebDriver\Chrome\ChromeDriver;
use Punch\Punchable;
use Punch\In;
Expand All @@ -25,6 +27,10 @@ class PunchTheClock extends Punchable

public function __construct()
{
if (PLATFORM !== 'linux' && (DRIVER_EXE_PATH === '' || CHROME_EXE_PATH === '')) {
throw new \Exception("When the platform is not linux, you must specify the paths to both the Chrome browser and Chromedirver executable files in the config.php file.", 1);
}

$this->validate($_SERVER['argv']);

if (DEBUG) {
Expand Down Expand Up @@ -63,20 +69,18 @@ public function __construct()
$chromeOptions->addArguments(["--headless"]);
// force a screen size to make sure mobile layout designs don't interfere
$chromeOptions->addArguments(['--window-size=1920,1000']);
$chromeOptions->setBinary("/usr/bin/google-chrome");
$chromeOptions->setBinary(
PLATFORM !== 'linux' ? CHROME_EXE_PATH : "/usr/bin/google-chrome"
);

// Create $capabilities and add configuration from ChromeOptions
$capabilities = DesiredCapabilities::chrome();
$capabilities->setCapability(ChromeOptions::CAPABILITY_W3C, $chromeOptions);
$capabilities->setCapability('platform', 'linux');
$capabilities->setCapability('platform', PLATFORM);


// Start Chrome
//$this->driver = RemoteWebDriver::create($this->serverUrl, $capabilities);
$pathToExecutable = getenv(ChromeDriverService::CHROME_DRIVER_EXECUTABLE) ?: getenv(ChromeDriverService::CHROME_DRIVER_EXE_PROPERTY);
if ($pathToExecutable === false || $pathToExecutable === '') {
$pathToExecutable = ChromeDriverService::DEFAULT_EXECUTABLE;
}
$pathToExecutable = PLATFORM !== 'linux' ? DRIVER_EXE_PATH : 'chromedriver';
$chromeDriverservice = new ChromeDriverService($pathToExecutable, $this->port, ['--port=' . $this->port]);
$this->driver = ChromeDriver::startUsingDriverService($chromeDriverservice, $capabilities);

Expand Down
7 changes: 7 additions & 0 deletions src/config.example.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
$classLoader->addPsr4("Punch\\", __DIR__, true);
$classLoader->register();

// OS Platform
define( 'PLATFORM', 'linux');
//define('PLATFORM', 'windows');

define('DRIVER_EXE_PATH', '');
define('CHROME_EXE_PATH', '');

// Web site url used to clock in or out
define('CLOCK_URL', 'http://localhost/');

Expand Down

0 comments on commit 8a73e90

Please sign in to comment.