Created
August 22, 2012 21:36
-
-
Save adamgoucher/3429609 to your computer and use it in GitHub Desktop.
Revisions
-
adamgoucher revised this gist
Aug 24, 2012 . 1 changed file with 6 additions and 5 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,13 +3,14 @@ require_once('dashboard.php'); require_once(dirname(__FILE__) . '/../../../PHPWebDriver/WebDriverWait.php'); require_once(dirname(__FILE__) . '/../../../PHPWebDriver/WebDriverBy.php'); class SauceLoginPage { private $locators = array( "username" => array(\PHPWebDriver_WebDriverBy::ID, 'username'), "password" => array(\PHPWebDriver_WebDriverBy::ID, 'password'), "submit button" => array(\PHPWebDriver_WebDriverBy::ID, 'submit'), "errors" => array(\PHPWebDriver_WebDriverBy::CSS_SELECTOR, '.error') ); function __construct($session) { @@ -59,7 +60,7 @@ function($session, $extra_arguments) { } function validate() { assert('$this->title == "Login - Sauce Labs" /* title should be "Login - Sauce Labs" */'); return $this; } -
adamgoucher revised this gist
Aug 24, 2012 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -22,6 +22,8 @@ function __get($property) { list($type, $string) = $this->locators[$property]; $e = $this->session->element($type, $string); return $e->text(); case "title": return $this->session->title(); default: return $this->$property; } @@ -57,7 +59,7 @@ function($session, $extra_arguments) { } function validate() { assert('$this->title == "Login - Sauce Labs" /* title should be "Login" */'); return $this; } -
adamgoucher revised this gist
Aug 24, 2012 . 1 changed file with 25 additions and 18 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,26 +1,27 @@ <?php namespace WebDriver; require_once('dashboard.php'); require_once(dirname(__FILE__) . '/../../../PHPWebDriver/WebDriverWait.php'); class SauceLoginPage { private $locators = array( "username" => array("id", 'username'), "password" => array("id", 'password'), "submit button" => array("id", 'submit'), "errors" => array("css selector", '.error') ); function __construct($session) { $this->session = $session; } function __get($property) { switch($property) { case "errors": list($type, $string) = $this->locators[$property]; $e = $this->session->element($type, $string); return $e->text(); default: return $this->$property; } @@ -30,7 +31,8 @@ function __set($property, $value) { switch($property) { case "username": case "password": list($type, $string) = $this->locators[$property]; $e = $this->session->element($type, $string); $e->sendKeys($value); break; default: @@ -39,15 +41,16 @@ function __set($property, $value) { } function open() { $this->session->open("https://saucelabs.com/login"); return $this; } function wait_until_loaded() { $w = new \PHPWebDriver_WebDriverWait($this->session, 30, 0.5, array("locator" => $this->locators['submit button'])); $w->until( function($session, $extra_arguments) { list($type, $string) = $extra_arguments['locator']; return $session->element($type, $string); } ); return $this; @@ -61,17 +64,21 @@ function validate() { function login_as($username, $password, $success=true) { $this->username = $username; $this->password = $password; list($type, $string) = $this->locators['submit button']; $e = $this->session->element($type, $string); $e->click(); if ($success) { $p = new \DashboardPage($this->session); $p->wait_until_loaded(); return $p; } else { $w = new \PHPWebDriver_WebDriverWait($this->session, 30, 0.5, array("locator" => $this->locators['errors'])); $w->until( function($session, $extra_arguments) { list($type, $string) = $extra_arguments['locator']; $e = $session->element($type, $string); return $e->displayed(); } ); -
adamgoucher created this gist
Aug 22, 2012 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,81 @@ <?php namespace WebDriver; require_once('DashboardPage.php'); require_once('PHPWebDriver/WebDriverWait.php'); class LoginPage { private $locators = array( "username" => array("id", 'username'), "password" => array("id", 'password'), "submit button" => array("id", 'submit'), "errors" => array("css selector", 'errors') ); function __construct($session) { $this->session = $session } function __get($property) { switch($property) { case "errors": $e = $this->session->element($this->locators[$property][0], $this->locators[$property][1]); return $e->text; default: return $this->$property; } } function __set($property, $value) { switch($property) { case "username": case "password": $e = $this->session->element($this->locators[$property][0], $this->locators[$property][1]); $e->sendKeys($value); break; default: $this->$property = $value; } } function open() { self::$session->open("http://your.site.com"); return $this; } function wait_until_loaded() { $w = new PHPWebDriver_WebDriverWait($this->session); $w->until( function($session) { return $session->element($this->locators["submit button"][0], $this->locators["submit button"][1]); } ); return $this; } function validate() { assert('$this->title == "Login" /* title should be "Login" */'); return $this; } function login_as($username, $password, $success=true) { $this->username = $username; $this->password = $password; $e = $this->session->element($this->locators["submit button"][0], $this->locators["submit button"][1]); $e->click() if ($success) { $p = new DashboardPage($this->session); $p->wait_until_loaded(); return $p; } else { $w = new PHPWebDriver_WebDriverWait($this->session); $w->until( function($session) { $e = $session->element($this->locators["errors"][0], $this->locators["errors"][1]); return $e->displayed(); } ); return $this; } } }