Created
January 2, 2015 08:34
-
-
Save jameshd/9758c6cf607be21736d0 to your computer and use it in GitHub Desktop.
WebDriver Factory Class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export BROWSER_REQUESTED='chrome' && phpunit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class E2ETestCase extends PHPUnit_Framework_TestCase | |
{ | |
protected $driver; | |
public function setUp() | |
{ | |
$this->driver = App_Factory_RemoteWebDriver::factory(); | |
} | |
// more here. | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment