Getting Started
…
Installation
The library can be installed easily via Composer.
Define the dependencies in your
composer.json
file:
{
"require": {
"qa-tools/qa-tools": "~1.0"
}
}
Install/update your vendors:
$ curl http://getcomposer.org/installer | php
$ php composer.phar install
To verify successful installation look for the qa-tools/qa-tools
folder within /vendor/
folder of your project.
Configuration
The library can be optionally configured using following approach:
1<?php
2use Behat\Mink\Driver\Selenium2Driver;
3use Behat\Mink\Session;
4use QATools\QATools\PageObject\Config\Config;
5use QATools\QATools\PageObject\Container;
6use QATools\QATools\PageObject\PageFactory;
7
8// 1. Obtain/create Mink's session object:
9$session = new Session(new Selenium2Driver());
10
11// 2a. Either configure page factory via Config class:
12$config = new Config(array(
13 'base_url' => 'http://www.example.com',
14));
15$page_factory = new PageFactory($session, $config);
16
17// 2b. Or configure page factory via dependency injection container:
18$container = new Container();
19$container['config_options'] = array(
20 'base_url' => 'http://www.example.com',
21);
22$page_factory = new PageFactory($session, $container);
Then created PageFactory
class instance can be used to spawn Page
class instances at will.
Note
If several Mink’s sessions are used (e.g. for different browsers), then separate PageFactory
class
instance needs to be created for each of them. Configuration setting can be shared across different
PageFactory
class instances, when same container is used to create them.
Configuration Options
The following configuration options are available:
base_url
- allows to specify Base URL to be used to transform all relative urls from @page-url annotations into absolute urls.page_namespace_prefix
- array of namespaces in which the DefaultPageLocator will search for page classes. Defaults to:array('\\')
page_url_matchers
- array of classes, that are used to detect if givenPage
is currently opened. Defaults to:array( '\\QATools\\QATools\\PageObject\\PageUrlMatcher\\ExactPageUrlMatcher', '\\QATools\\QATools\\PageObject\\PageUrlMatcher\\RegexpPageUrlMatcher', '\\QATools\\QATools\\PageObject\\PageUrlMatcher\\ComponentPageUrlMatcher', )
If port is specified as part of base_url then it will be used in every built url unless specified explicitly in the @page-url annotation.
Connecting to Behat
Note
Throughout this tutorial it’s assumed that working Behat with MinkExtension is configured and connected to a project that needs to be tested.
To use library with Behat you are required to also install https://github.com/qa-tools/behat-extension.
Connecting to PHPUnit
Note
Throughout this tutorial it’s assumed that working PHPUnit is configured and connected to a project that needs to be tested.
To use library with PHPUnit you are required to also install https://github.com/qa-tools/phpunit-extension.
Important
TODO: Write about the obtaining Mink session need for PageFactory and that it can be easily done using PHPUnit-Mink.
Connecting PHPUnit-Mink
…
Creating Test Case File
…