I've got a set of cucumber tests I'm running using ruby/capybara. I have the tests outputting to Browserstack but it only outputs the session ID which isn't of much use to me and want to replace with the test/scenario name.

When I try and set the scenario name using scenario.name and assigning to a variable in the before hook it does this, but only for the first run. Each test then uses the same scenario name.

I've done some investigative work and can see that the browserstack config is only initialized once at the beginning of the entire test suite run. Even if I try and initialize it each time in the before hook it doesn't run for each scenario/test.

Any help is appreciated.


Take a look at the following example of caps object in capabilities which I use on my tests:

            'automationName'=> 'Appium',
            'browserstack.appium_version' => '1.11.1',
            'project' => 'my-project-name',
            'build' => "1.5.15",
            'name' => "#{scenario.name}",
            'device' => 'Google Nexus 6',
            'real_mobile' => 'true',
            'os' => 'android',
            'os_version' =>  '6.0',
            'browserstack.debug' => true,
            'autoGrantPermissions' => true,
            'app' => 'my-app-name'

The value for build groups all tests (scenarios) and you have to start a new browser on Before hooks.

Review the value you are passing to name becasue it could be the same in every execution. Ensure you are overwriting it in each execution.

  • Hi, thanks for your reply. I've tried passing in scenario.name in the capabilities and it errors. For some reason the only place I can set it is in the hooks.rb. This works, but I can't access it in the capabilities. The only way I've been able to do this is to create a constant such as 'SCENARIO_NAME = scenario.name', but this outputs the same scenario name for each scenario. – QABoy Jun 12 '19 at 15:47
  • Sure, in hooks.rb, specially inside a block of a Before hook is where you can use it, because the scenario object is passed to the block. Consider the following snippet. Suppose you have a class to create caps called MyCapabilities Before do |scenario| # scenario is an object passed to the block by this hook. caps = MyCapabilities.new(scenario.name).caps # end – roman Jun 13 '19 at 17:25
  • Roman, Thank you. I am going to try this out next time I have the time to try this and I will get back to you :) – QABoy Jun 17 '19 at 8:12
  • Hi Roman, I have done as you suggested. However I don't think this is the problem. Having set it up so I can step through, I am seeing that Capybara.register_driver :browserstack is only getting called once when the test suite runs. This means that no matter where I set scenario.name, because the register.driver only happens once It uses whatever was set for the initial scenario for all scenarios. I'm sure the solution must be simple, but I can't see it! – QABoy Jun 20 '19 at 10:16
  • I think you should have something like Capybara.register_driver :browserstack do |app| .... where browser is started with a line like: Capybara::Selenium::Driver.new(app,:browser => :remote,:url => "http://...:desired_capabilities => @caps) You have to call this statement inside Before hook. I mean, every time before a scenario start, you have to initialize the browser with the new caps, which contain the first answer using scenario.name on caps ('name' => "#{scenario.name}" – roman Jun 22 '19 at 19:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.