tzander / page-factory
Php PageFactory for Selenium2
Installs: 5 080
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 3
Forks: 2
Open Issues: 0
Requires
- php: >=5.3
This package is not auto-updated.
Last update: 2024-11-09 14:12:01 UTC
README
Supports the PageObject pattern for PHP with Selenium2
Installation
Install with composer
{ "require": { "tzander/page-factory": "dev-master" } }
Example
You need to include the Autoload.php and create a page class.
require_once __DIR__ . '/library/Autoload.php'; class BingSearchPage { /** * @var PHPUnit_Extensions_Selenium2TestCase_Element */ public $sb_form_q; public function search() { $this->sb_form_q->value('selenium'); $this->sb_form_q->submit(); return PageFactory::initElements($this->getTestCase(), 'SearchResultPage'); } }
The property must be public and either the name or the id attribute of the element.
Now in order to have an initialized object to return we need to to the following:
class SearchTest{ public function shouldfindSelenium(){ $page = PageFactory::initElements($this, 'BingSearchPage'); $resultPage = $page->search(); $this->assertInstanceOf('SearchResultPage', $resultPage); } }
Using Annotation
You can also use the @find annotations in order to locate the element.
/** * @find byXpath='a[@class=test]' */ public $link;
Or any of these find methods:
byId, byName, byXpath, byCssSelector ,byClassName.