Skip to content

Instantly share code, notes, and snippets.

@buttflattery
Forked from jameshd/TestCase.php
Last active August 29, 2015 14:12
Show Gist options
  • Save buttflattery/bf9fc10859948f7eda1c to your computer and use it in GitHub Desktop.
Save buttflattery/bf9fc10859948f7eda1c to your computer and use it in GitHub Desktop.

Revisions

  1. James HD created this gist Jan 2, 2015.
    11 changes: 11 additions & 0 deletions TestCase.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    class E2ETestCase extends PHPUnit_Framework_TestCase
    {
    protected $driver;

    public function setUp()
    {
    $this->driver = App_Factory_RemoteWebDriver::factory();
    }

    // more here.
    }
    39 changes: 39 additions & 0 deletions WebDriverFactory.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    class App_Factory_RemoteWebDriver
    {
    public static function factory()
    {
    switch ($_SERVER['BROWSER_REQUESTED']) {
    case 'chrome':
    return self::createChrome();
    break;
    case "ie":
    throw new Exception('Not implemented');
    break;

    case 'firefox':
    default:
    return self::createFirefox();
    break;
    }
    }

    public static function createChrome()
    {
    putenv("webdriver.chrome.driver=/path/to/chromedriver");

    $service = ChromeDriverService::createDefaultService();
    $service->start();

    return ChromeDriver::start(DesiredCapabilities::chrome(), $service);
    }

    public static function createFirefox()
    {
    // these are just constants defined in bootstrap.php
    $seleniumUrl = isset($_SERVER['JENKINS_URL']) ? TEST_ENV_SELENIUM_SERVER : LOCAL_ENV_SELENIUM_SERVER;

    return RemoteWebDriver::create(
    $seleniumUrl, DesiredCapabilities::firefox()
    );
    }
    }
    1 change: 1 addition & 0 deletions command-prompt.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    export BROWSER_REQUESTED='chrome' && phpunit