-
Notifications
You must be signed in to change notification settings - Fork 277
Allow to have different base urls per suite #155
Comments
I have the same situation( I do not know how to solve this problem. |
you can always create separete profiles, and define others base_url |
I tried created separate profile but I don't see a configuration to run all test suites with behat switching automatically profile according to the current suite it is executing. This is my behat.yml. With this configuration, I would like to run all scenario with the tag club2 on club2.localhost and the other on club1.localhost. With this configuration, I can make the club2 suite work by runing the command : behat --suite=club2 --profile=club2. But I am looking for a way to run all suite in one command and automaticaly switching profile in the suite. default:
autoload:
'': %paths.base%/features/bootstrap
extensions:
Behat\Symfony2Extension: ~
SensioLabs\Behat\PageObjectExtension: ~
Behat\MinkExtension:
base_url: http://club1.localhost/
selenium2: ~
suites:
default:
contexts:
- Context\FeatureContext
- Context\SecurityContext
filters:
tags: ~@club2
club2:
contexts:
- Context\FeatureContext
- Context\SecurityContext
filters:
tags: @club2
club2:
extensions:
Behat\Symfony2Extension: ~
SensioLabs\Behat\PageObjectExtension: ~
Behat\MinkExtension:
base_url: http://club2.localhost/
selenium2: ~ I don't know if I went the right way, but I found a solution by creating a custom context which modify all context in the environment before each scenario. <?php
namespace Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
/**
* Description of MinkOverrideContext
*
* @author jobou
*/
class MinkOverrideContext extends Base\BaseMinkContext
{
protected $baseUrl;
public function __construct($base_url)
{
$this->baseUrl = $base_url;
}
/** @BeforeScenario */
public function gatherContexts(BeforeScenarioScope $scope)
{
$environment = $scope->getEnvironment();
foreach ($environment->getContexts() as $context) {
if ($context instanceof \Behat\MinkExtension\Context\RawMinkContext) {
$context->setMinkParameter('base_url', $this->baseUrl);
}
}
}
} And then loading it only for my club2 suite : suites:
club2:
contexts:
- Context\FeatureContext
- Context\SecurityContext
- Context\MinkOverrideContext:
base_url: http://club2.localhost/
filters:
tags: @club2 It seems to work but I would like to have your feedback on good and bad practice of what I am doing. |
Indeed, it seems only the |
That's the closest example that I found for v3, but even when I do the following it doesn't work: class ApiContext extends MinkContext {
public function __construct($base_url) {
$this->setMinkParameter('base_url', $base_url);
}
} |
I think it only changes the base_url parameter for the current context instance. If you look at my example #155 (comment). I was able to make it works by changing the base_url parameter in all context involved in my test suites. However I don'y know if there is a better solution. /** @BeforeScenario */
public function gatherContexts(BeforeScenarioScope $scope)
{
$environment = $scope->getEnvironment();
foreach ($environment->getContexts() as $context) {
if ($context instanceof \Behat\MinkExtension\Context\RawMinkContext) {
$context->setMinkParameter('base_url', $this->baseUrl);
}
}
} |
I have the same problem. I use a website with subdomains (two applications linked to each other), and I need to do that, by example:
I think using tags is the best way to update the base_url for each scenario. But my problem is: how? /** @BeforeScenario */
public function updateUrl(BeforeScenarioScope $scope)
{
// Here I need to access configuration
// If the tag @www1: use www1->base_url in configuration
// If the tag @www2: use www2->base_url in configuration
// But… how set the new base url and how make it works :/
} I don't want to use profiles because I want to run all tests but on different URLs. |
With MinkExtension you can call
With a definition like:
You can also call |
Combining the answers of jacquesbh and kyleferguson you could do something like this:
|
I like this solution! It's a really good idea, very simple. As simple that we didn't see it! |
BeforeScenario & setMinkParameter is setting the value correctly, but for the step Given I am on the homepage This resets the value of the base_url to the value defined in YML file |
Sorry to bump this but for us the solution of jbouzekri actually did the trick. So some context, we set a base_url in our custom In our behat.yml we added a custom parameter which we save in our FeatureContext. Behat.yml
The basic logic is that we set the base url for every scenario with the before scenario hook. If we want to change it we call an extra step Featurecontext:
I hope this can help some one else in the future since it was quite a challenge to find this out :) |
Well, this is the repo of the MinkExtension. So of course everything is about Mink. Anything else is out of the scope of this extension. |
Not sure if this aligns with your requirements, we have different domains for certain languages and organizations which again have differing permission configurations and so on, meaning we have to test them all. I made the base_url dependent on the environment variable APP_URL, which is defined with a default value used in most of the tests.
When I want to test a different domain now, I can run the suite parameterized like so:
Hope this helps. |
I've 2 suites in behat: frontend and backend. They both live on another subdomain. There should be a way to configure the base url per suite.
Does this already exists?
The text was updated successfully, but these errors were encountered: