Skip to content
This repository has been archived by the owner on Jun 13, 2019. It is now read-only.

goez-tools/mink-page-objects

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

75 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Page Objects Pattern for Mink

Build Status

Alpha version

Install

$ composer require goez/mink-page-objects --dev

Usage

Creating a page class for Google homepage:

use Goez\PageObjects\Page;

class Home extends Page
{
    protected $elements = [
        'SearchForm' => ['css' => 'form'],
    ];

    public function search($keyword)
    {
        return $this->getPart(SearchForm::class)
            ->search($keyword);
    }
}

Create a page class for searched result:

use Goez\PageObjects\Page;

class SearchResult extends Page
{
}

Creating an element object for searching form:

use Goez\PageObjects\Part;

class SearchForm extends Part
{
    /**
     * @param $keyword
     * @return SearchResult
     * @throws \Behat\Mink\Exception\ElementNotFoundException
     */
    public function search($keyword)
    {
        $this->element->fillField('q', $keyword);
        $this->element->submit();

        return $this->createPage(SearchResult::class);
    }
}

Instantiating a page object and verify keyword searching:

use Behat\Mink\Driver\Selenium2Driver;
use Behat\Mink\Session;
use Goez\PageObjects\Context;

class GoogleSearchTest extends PHPUnit_Framework_TestCase
{
    // Install phantomjs first
    // and you can use this trait
    // for starting phantonjs automatically
    use PhantomJSRunner;

    public function testSearchWithKeyword()
    {
        $driver = new Selenium2Driver('phantomjs');

        $session = new Session($driver);
        $session->start();

        $context = new Context($session, [
            'baseUrl' => 'https://www.google.com',
        ]);

        $context->createPage(Home::class)
            ->open()
            ->search('example')
            ->shouldContainText('Example Domain');
    }
}

License

MIT

About

Implementation of Page Objects Pattern for Mink

Resources

Stars

Watchers

Forks

Packages

No packages published