In this tutorial, we will create a mobile test using Calabash and, optionally, the Xamarin Test Cloud.
In this case, the test (specification) is initially created in Jira as a Cucumber Test and afterwards, it is exported using the UI or the REST API.
With the migration of Xamarin Test Cloud to Visual Studio App Center, some CLI tools were deprecated and/or removed; the same happened with some documentation.
Thus, this tutorial may need to be updated accordingly.
Android and iOS
For the purpose of this tutorial, we will use an Android app as basis. The only change relevant for iOS would be to use the "calabash-ios" command instead of "calabash-android".
- Android SDK (or iOS SDK)
- install the Ruby gems: "calabash-android" (or "calabash-ios"), "calabash-cucumber", "xamarin-test-cloud", "rubyzip"
The code for our test will be the code for the basic "Hello World!" application that Android Studio generates.
Create a Cucumber Test, of Cucumber Type "Scenario", in Jira. The test will validate the presence of the "Hello World!" on the device's screen.
"calabash-android" provides some steps that can be reused in order to write Cucumber Scenarios/Scenario Outlines; in other words, if you just reuse those steps, you don't have to write any code at all for your tests.
After creating the Test in Jira and associating it with requirements, etc., 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 one above, but will contain the references to the Test issue key and the covered requirement issue key.
In the project base folder, run the following command which will create a basic .feature.
Note that the
ApplicationManifest.xml must contain the "android.permission.INTERNET" permission. See example below:
Running tests locally
You can run your tests locally using a device emulator or with a real connected device.
This command will generate a Cucumber JSON report file that can be imported to Xray in the same way you would generally do for Cucumber tests, i.e., via the REST API or the Import Execution Results action within the Test Execution.
Running tests in the Cloud with Xamarin Test Cloud
First, you must execute "calabash-android" with the "build" argument.
Before submitting the application for testing, you must know the API key on the Test Cloud (obtainable under the team's section).
Afterwards, you can use the "test-cloud" utility to submit the packaged application (e.g., .apk) by identifying the following:
- API key
- Test Cloud's username (i.e., email)
- device's list ID
- series name
Cucumber config file used by the "test-cloud" utility:
Example syntax or invoking "test-cloud" for submission of the app:
As soon as the test run finishes in Xamarin's Test Cloud, the detailed report will be available on the Test Cloud's page.
Some relevant numbers are displayed, such as the total devices and tests with failures.
You can analyze a given test failure: see what step failed, the device and test logs.
Importing results to Xray
Note that Xray supports the submission of a zip file containing multiple Cucumber JSON reports, one per each device.
In order to obtain Test Cloud's results in a machine-friendly way, you need to use Test Cloud's REST API since the "test-cloud" utility does not currently provide an immediate way of obtaining the results.
However, it's possible to use the preliminary Test Cloud Ruby client SDK and API in order to produce a ZIP file containing the Cucumber JSON reports.
Below is an example of an implementation where you pass the API key and the "test-cloud" output file as arguments, and that will produce a "results.zip" file.
Creating a zip file with all Cucumber JSON reports:
After importing the results using the REST API, the execution screen details will provide information on the test run result, grouped by device.
The Context section will be by filled out with the name of the original Cucumber JSON report; in this case, it's the name/id of the device.
Please refer to Testing in BDD with Gherkin based frameworks (e.g. Cucumber) for an overview on how to use Cucumber Tests with Xray.
- Automated Tests (Import/Export)
- Exporting Cucumber Tests - REST