Created
February 8, 2019 15:28
-
-
Save jakzal/fa1a1000ff8be48964478cffd43144bc to your computer and use it in GitHub Desktop.
Page objects
This file contains 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
<?php declare(strict_types=1); | |
use Behat\Mink\Element\NodeElement; | |
use Behat\Mink\Session; | |
use Zalas\PageObject\Annotation\FindBy; | |
use Zalas\PageObject\Annotation\MinkSession; | |
class SearchPage | |
{ | |
/** | |
* @MinkSession() | |
* @var Session | |
*/ | |
protected $session; | |
/** | |
* @FindBy(xpath="//form[@name='f']") | |
* @var NodeElement | |
*/ | |
protected $searchForm; | |
/** | |
* @FindBy(xpath="//title") | |
* @var NodeElement | |
*/ | |
protected $title; | |
public function visit(): self | |
{ | |
$this->session->visit('https://www.google.co.uk/'); | |
return new self(); | |
} | |
public function search(string $keywords): self | |
{ | |
$this->searchForm->fillField('q', $keywords); | |
$this->searchForm->pressButton('Google Search'); | |
return new self(); | |
} | |
public function getTitle(): string | |
{ | |
return $this->title->getText(); | |
} | |
} |
This file contains 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
<?php declare(strict_types=1); | |
use PHPUnit\Framework\TestCase; | |
class PageObjectTest extends TestCase | |
{ | |
public function testSearchPage() | |
{ | |
$searchPage = (new SearchPage()) | |
->visit() | |
->search('foo'); | |
$this->assertSame('foo - Google Search', $searchPage->getTitle()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment