ngauthier/hydra

Hydra and Cucumber using wire protocol (cuke4php)

andrewhavens opened this issue · 3 comments

Hello,

My co-worker and I spent some time trying to use hydra out of the box with our current Cucumber setup and couldn't get it to work right so we gave up using it. We hacked together a script that sort of runs scenarios in parallel, which involves tagging all of our scenarios with a unique tag, but it isn't the best solution. I'd like to fill you in on our current setup and see if you plan to support it, or if it is currently supported, how we can configure Hydra to work with our project.

Here's a list of the libraries we are using:

  • Cucumber
  • Cuke4PHP wire protocol server
  • Capybara
  • Selenium-Webdriver talking to a remote Selenium server

We are testing a PHP project which is why we are using cuke4php. Cuke4PHP implements the Cucumber wire protocol so we can implement step definitions in PHP. Here's how the process would work running in sequence:

  1. run cuke4php path/to/features from the command line
  2. Cuke4Php then starts up it's server on an available port and specifies an environment variable for Cucumber to know which port the server is running on. Then it calls cucumber path/to/features.
  3. Cucumber runs as normal. Whenever it can't find a step definition, it asks the wire if a step definition is implemented on that side.
  4. Since we're testing a web application, we generate a new database (and virtual host) before each cucumber scenario and destroy it after each cucumber scenario. Capybara uses Selenium to open a remote browser and navigate to the virtual host we created.

Here are some things that we learned when creating our own forking script. Cuke4Php server will only work for one scenario at a time. So if we want to run Cucumber in parallel, we need a Cuke4Php server running for each fork. This is easy to do and happens automatically by running cuke4php from the command line. The problem is Hydra (as far as I know) does not have any way to configure how it works. The hydra:cucumber rake task does a bunch of magic behind the scenes. If we could configure some "before" and "after" tasks, that would probably suffice, but I don't know what the best approach to this would be.

Does Hydra support anything like this? Is there any workarounds we can do until it does? What do you recommend?

When you have external services (in your case, selenium) all the Hydra processes will connect to the same instance of the service, which would definitely not work out well with selenium. (It does, however, work well with a database in transactional mode).

Your best shot is making a file in the root of the project 'hydra_worker_init.rb'. See:
https://github.com/ngauthier/hydra/blob/master/lib/hydra/worker.rb#L32

When workers boot at the beginning of the cycle, they run that file. Here, you could disconnect from those common services and reconnect to separate ones.

Although, Hydra was meant to be easier in simple scenarios, at the cost of being robust in complex ones. You may have better luck with your own solution.

-Nick

Regarding Selenium...the selenium server can accept multiple connections. So when the scenarios are running in parallel, they are all connecting to the same selenium server (which is fine). All we need to do is specify a different base URL for each scenario (since we set up each scenario to have a different subdomain, and a different database):

Before do |scenario|
testName = get_test_name(scenario)
if (testName.length > 0)
    Capybara.app_host = "https://#{testName}.ourwebsite.com"
end
end

Could you send me a link to an example 'hydra_worker_init.rb' file? The link you sent was just showing where the file gets included, but not what the file is supposed to look like.

Thanks!

Hey Andrew,

Sorry I don't have an example. That was written by another contributor, who wrote it for their own purposes, which were what you are trying to do.

-Nick