Overview
In this tutorial, we will create a test in Cucumber for Ruby in order to validate a simple mobile application using Appium and BrowserStack for cloud testing.
The test (specification) is initially created in Jira as a Cucumber Test and a Pre-Condition; later on it is exported using the UI or the REST API.
Requirements
- Install Ruby (or JRuby)
- Install the "cucumber" gem
Description
This tutorial is based on BrowserStack's own tutorial for Appium/Cucumber/Ruby.
You may start by cloning the repository https://github.com/browserstack/cucumber-ruby-appium-app-browserstack .
git clone https://github.com/browserstack/cucumber-ruby-appium-app-browserstack
We'll use the Android example folder as basis and the "parallel" task that runs the tests in parallel.
We have to make some changes in order to make Cucumber generate a distinct JSON report per each device.
Rakefile was "hacked" in order to process the devices configured for the "parallel" task and related configuration file (i.e. config/parallel.config.yml).
The number of parallel jobs must be equal to the number of configured devices.
require 'rake' require 'parallel' require 'cucumber/rake/task' require 'yaml' Cucumber::Rake::Task.new(:cukesingle) do |task| ENV['CONFIG_NAME'] ||= "single" task.cucumber_opts = ["--format=pretty -f json -o results.json", 'features/single.feature'] end task :default => :single Cucumber::Rake::Task.new(:local) do |task| task.cucumber_opts = ["--format=pretty -f json -o results.json", 'features/local.feature', 'CONFIG_NAME=local'] end task :single, [:device] do |task,args| device = (args[:device] || "").gsub(' ','_') cuke_task = Cucumber::Rake::Task.new cuke_task.cucumber_opts = ["--format=pretty -f json -o device_#{device}.json", 'features/single.feature'] cuke_task.runner.run end task :parallel do |t, args| @num_parallel = 2 Parallel.map([*1..@num_parallel], :in_processes => @num_parallel) do |task_id| ENV["TASK_ID"] = (task_id - 1).to_s ENV['name'] = "parallel_test" ENV['CONFIG_NAME'] = "parallel" TASK_ID = (ENV['TASK_ID'] || 0).to_i CONFIG_NAME = ENV['CONFIG_NAME'] CONFIG = YAML.load(File.read(File.join(File.dirname(__FILE__), "./config/#{CONFIG_NAME}.config.yml"))) caps = CONFIG['browser_caps'][(task_id-1)] ENV['DEVICE'] = caps['device'] Rake::Task["single"].invoke(caps['device']) Rake::Task["single"].reenable end end task :test do |t, args| Rake::Task["single"].invoke Rake::Task["single"].reenable Rake::Task["local"].invoke Rake::Task["parallel"].invoke end
You need to configure the BrowserStack user/key along with desired browser capabilities/devices.
server: "hub-cloud.browserstack.com" user: "sergiofreire1" key: "Q75qUuWwumyKvpXq6Kg4" common_caps: "build": "cucumber-browserstack" "browserstack.debug": true browser_caps: - "device": "Google Pixel" "app": "bs://6c31566b71e1ee4c5f7f5298c702c0de4c590000" "name": "parallel_test" - "device": "Google Nexus 6" "app": "bs://6c31566b71e1ee4c5f7f5298c702c0de4c590000" "name": "parallel_test"
In this tutorial we're using a wikipedia sample application from BrowserStack, that must be uploaded beforehand to BrowserStack. The hashed app id must be configured accordingly on the previous configuration file.
After creating a Cucumber Test, of Cucumber Type "Scenario Outline", in Jira, you can export the specification of the test to a Cucumber .feature file via the REST API or the Export to Cucumber UI action from within the Test Execution issue.
The created file will be similar to the following:
@CALC-2130 @REQ_CALC-2131 Feature: As a user, I can search in Wikipedia App Background: #@CALC-2133 Given I try to search using Wikipedia App @TEST_CALC-2132 Scenario: Search for a term When I type in "BrowserStack" Then I should see results
After running the tests and generating the Cucumber JSON report (e.g., data.json), it can be imported to Xray via the REST API or the Import Execution Results action within the Test Execution.
bundle exec rake parallel
The execution screen details will not only provide information on the test run result, but also of each of the examples provided in the Scenario Outline.
The Cucumber Scenarios Example/Result details (i.e., Hooks, Backgrounds and Steps) are only available for executions done in Xray v2.2.0 and above.
The icon
represents the evidences ("embeddings") for each Hook, Background and Steps, but is only available for executions done in Xray v2.3.0 and above.Learn more
Please see Testing with Cucumber for an overview on how to use Cucumber Tests with Xray.
References
- https://cucumber.io/docs/reference/ruby
- https://www.browserstack.com/app-automate/appium-cucumber
- Testing with Cucumber
- Exporting Cucumber Tests - REST
- Import Execution Results - REST