Behat / MinkExtension

Mink extension (tight integration and configuration) for Behat
MIT License
636 stars 277 forks source link

Hardcoded saucelabs/Jenkins pipeline env variables don't work with new Jenkins pipeline #272

Open angelsk opened 7 years ago

angelsk commented 7 years ago

Hi, so we've started using BlueOcean on Jenkins to configure pipelines, which is awesome. However, the SauceLabsFactory and Selenium2Factory have hardcoded values which mean that we have to creatively add configuration to get it to work properly.

Basically, SauceConnect randomly picks an open port, and generates a tunnel identifier, and sticks them in env variables. Changed in v1.142

SaucelabsFactory:L48 - could we use SELENIUM_PORT if it's set please, as the default in Jenkins is no longer 4445 Selenium2Factory:L72 - could we use TUNNEL_IDENTIFIER if it's set please (as JOB_NAME has spaces, and changes per branch)

Currently we get around this by hardcoding a double port, by it's a bit hacky (but in case anyone else experiences the same issue)

sauceconnect(options: '-P 4445 -i my_hardcoded_tunnel', useGeneratedTunnelIdentifier: false, verboseLogging: true) {
// Run tests
}

Logs: Command line arguments: /home/jenkins/sc/bin/sc -u username -k **** -P 37501 -P 4445 -i my_hardcoded_tunnel

and then specifying the tunnel-identifier in the capabilities configuration.

But I would love a proper solution.

stof commented 7 years ago

if you use Symfony DependencyInjection 3.2+ in your project when running Behat (probably won't work if you use the phar, as it embeds its own version of the component and I think it is older), you may try to use the new %env(TUNNEL_IDENTIFIER)%. I'm curious to see whether it works to use your env variables in the config.

angelsk commented 7 years ago

Yeah - the port is the main problem; and there's no way to change that. I can look into the DI component, but it may be worth updating the plugin/bundle either way, as the Jenkins plugin has been updated :)

EDIT: Plus SELENIUM_PORT should be backwards compatible with older versions of the Jenkins plugin. I'm not sure what effect it'll have on Travis though.

SvenRtbg commented 6 years ago

We encountered a completely different, but related problem in our usage of Behat with Jenkins Pipelines. Our branches use slashes for separation, and Jenkins escaped the slash inside the environment variables BUILD_TAG, JOB_NAME and JOB_BASE_NAME with the sequence %2f. That works with behat if only ONE slash is in the branch name, but Symfony DI will bail out with an exception if we use TWO slashes.

The Selenium2Factory fetches the first two environment variables and puts them into a DI Definition class. Symfony DI sees %variable% inside the string and tries to expand this, but fails because such a variable has not been defined.

With a branch name of test/with/slashes the error produced is

[Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException]
You have requested a non-existent parameter "2fwith".

Our software does not use any Symfony otherwise, this is only related to "behat/mink-extension" version 2.3.1.

SvenRtbg commented 6 years ago

I found this issue: https://github.com/symfony/symfony-standard/issues/1084

It seems like behat/mink-extension is missing to properly escape the strings it is passing into Symfony di.

Now this developed into really being a different issue. I will open my own ticket.