I've a project running with Behat 2.4
, Mink 1.4
and Behat Page Object Extension
, with this version my tests is fine, 100% passed.
But now i'm migrating to Behat 3
due to the fully integration with Browserstack, Behat 2 doesn't support BrowserStack flags and the integration is poor.
I've changed my composer file and I updated project, but when I run the tests, it is returning an Exception on Page Object Extension
.
To create pages you need to pass a factory with setPageObjectFactory() (RuntimeException)
Looking at Page Object Docs I don't see anything about setPageObjectFatory, this isn't needed.
In configuration section, only specifies factory
if you create a custom factory or/and custom class name resolver.
My composer with all dependencies is
{
"require-dev" : {
"behat/behat" : "master-dev",
"behat/mink-goutte-driver" : "master-dev",
"behat/mink-browserkit-driver" : "master-dev",
"sensiolabs/behat-page-object-extension" : "master-dev",
"behat/mink-extension" : "master-dev",
"behat/mink-selenium2-driver" : "master-dev",
"behat/mink" : "master-dev"
}
}
And my behat.yml bellow
default:
suites:
default:
contexts:
- FeatureContext
- ProductDetailsContext
- CartContext
extensions:
SensioLabs\Behat\PageObjectExtension:
namespaces:
page: [Features\Page]
element: [Features\Page\Element]
Behat\MinkExtension:
sessions:
my_session:
browser_stack:
username: my_username
access_key: my_password
capabilities:
browserName: "Chrome"
browserVersion: "35"
platform: "WIN8"
My FeatureContext extending MinkContext
<?php
use Behat\MinkExtension\Context\MinkContext;
/**
* Behat context class.
*/
class FeatureContext extends MinkContext
{
}
And ProductDetailsContext extending PageObjectContext
<?php
use SensioLabs\Behat\PageObjectExtension\Context\PageObjectContext;
/**
*
*
*/
class ProductDetailsContext extends PageObjectContext
{
/**
* @Given /^I am on product details "([^"]*)"$/
*
* @param string $url
*/
public function iAmOnProductDetails($url)
{
$this->getPage("ProductDetails")->open(array("productUrl" => $url));
}
/**
* @Given /^I am at a random product details$/
*/
public function iAmAtARandomProductDetails()
{
$catalog = $this->getPage("Catalog");
$catalog->open(array('category' => 'calcados-femininos'));
$catalog->openRandomProduct();
}
/**
* @When /^I select product size$/
*/
public function iSelectProductSize()
{
$this->getPage("ProductDetails")->selectProductSize();
}
/**
* @Then /^I add product to cart$/
*/
public function iAddProductToCart() {
$this->getPage("ProductDetails")->addProductToCart();
}
/**
* @Then /^I add product to wishlist$/
*/
public function iAddProductToWishlist()
{
$this->getPage("ProductDetails")->addProductToWishlist();
}
}
I don't know how can solve this and I need help.
The problem is because Extensions
was configured inside of suites
, put the Extensions
outside suites
and it works.
default:
suites:
default:
contexts:
- FeatureContext
- ProductDetailsContext
- CartContext
extensions:
SensioLabs\Behat\PageObjectExtension:
namespaces:
page: [Features\Page]
element: [Features\Page\Element]
Behat\MinkExtension:
sessions:
my_session:
browser_stack:
username: my_username
access_key: my_password
capabilities:
browserName: "Chrome"
browserVersion: "35"
platform: "WIN8"