You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For several weeks, we've been busy setting up behat in our big 20 year old symfony 3.4 project. During this time we made a bunch of changes to make it simpler to write behat contexts.
This is one of these changes. In order to make it possible to work with symfony autowiring of Page objects, we had to extend SymfonyPage and apply these changes.
The getUrl issue might only exist on our project, but the others should also be a problem for "clean" symfony projects.
The reason I'm opening this issue, is because I'd like to know if you are interested in these kind of changes and if we should make pull requests for something. (We also extended Element to enable us to search for html elements only within that element. Furthermore we added means to interact with Element objects on a Page object.)
<?phpnamespaceTweakers\Test\Behat\Page;
useBehat\Mink\Session;
useFriendsOfBehat\PageObjectExtension\Page\SymfonyPage;
useFriendsOfBehat\SymfonyExtension\Mink\MinkParameters;
useSymfony\Component\Routing\RouterInterface;
abstractclassBasePageextendsSymfonyPage
{
/** * $minkParameters needs to be type hinted for auto-wiring of Pages to work. */publicfunction__construct(Session$session, MinkParameters$minkParameters, RouterInterface$router)
{
parent::__construct($session, $minkParameters, $router);
}
protectedfunctiongetUrl(array$urlParameters = []): string
{
// For some reason the url contains the host part twice (e.g. http://domain.com/domain.com/page)returnstr_replace(HOST_NAME . '/' . HOST_NAME, HOST_NAME, parent::getUrl($urlParameters));
}
protectedfunctionverifyUrl(array$urlParameters = []): void
{
$this->fixSymfonyHost();
parent::verifyUrl($urlParameters);
}
privatefunctionfixSymfonyHost(): void
{
$url = $this->getDriver()->getCurrentUrl();
$host = parse_url($url, PHP_URL_HOST);
$this->router->getContext()->setHost($host);
}
}
This change allowed us to write our Domain Contexts like this snippet:
classNewsContextextendsFeatureContext
{
/** @var NewsPortalPage */private$newsPortal;
/** @var NewsArticlePage */private$articlePage;
/** @var Heading */private$heading;
publicfunction__construct(
NewsPortalPage$portal,
NewsArticlePage$articlePage,
Heading$heading
) {
$this->newsPortal = $portal;
$this->articlePage = $articlePage;
$this->heading = $heading;
}
/** * @When I visit the news portal */publicfunctioniVisitTheNewsPortal()
{
// try to open, because the news portal redirects to listing of today$this->newsPortal->tryToOpen();
}
/** * @When /^I view (this news article)$/ * @When I read the news article :newsArticle * @Given I am reading the news article :newsArticle * * @see NewsArticleTransformer::ensureNewsArticle() */publicfunctioniViewThisNewsArticle(NewsArticle$newsArticle)
{
$this->articlePage->open(['id' => $newsArticle->getId()]);
}
/** * @Then /^I should see (this news article)$/ * * @see SharedStorageTransformer::getResource() */publicfunctioniShouldSeeThisNewsArticle(NewsArticle$article)
{
expect($this->heading)->toHaveText($article->getTitle());
}
}
The text was updated successfully, but these errors were encountered:
Hello @winkbrace and thank you for this post! I've been thinking about enabling autowiring in this extension for the last days, but I had no time to do it. I would be happy to accept the PR with a sufficient change, can you open it? We can then discuss functionalities there, as it's much easier when you can refer to a specific line/block of code :) Thanks! 🚀
For several weeks, we've been busy setting up behat in our big 20 year old symfony 3.4 project. During this time we made a bunch of changes to make it simpler to write behat contexts.
This is one of these changes. In order to make it possible to work with symfony autowiring of Page objects, we had to extend SymfonyPage and apply these changes.
The getUrl issue might only exist on our project, but the others should also be a problem for "clean" symfony projects.
The reason I'm opening this issue, is because I'd like to know if you are interested in these kind of changes and if we should make pull requests for something. (We also extended Element to enable us to search for html elements only within that element. Furthermore we added means to interact with Element objects on a Page object.)
This change allowed us to write our Domain Contexts like this snippet:
The text was updated successfully, but these errors were encountered: