This article describes how to install the Calabash-android test environment in Windows, using an example to introduce the basic usage of calabash-android.
The source generation used in this article is located in: https://github.com/bigconvience/HackerNews
Once the code is downloaded, enter the project directory and enter it at the command line: Calabash-android Gen, this command generates directory features in the project directory, such as the following directory structure:
features|_support| |_app_installation_hooks.rb| |_app_life_cycle_hooks.rb| |_env.rb| |_hooks.rb|_step_definitions| | _calabash_steps.rb|_my_first.feature
The Step_definions directory contains user-defined features, my_first.feature the steps to write the test.
Screenshot of basic usage
Write down the following code in the My_first.feature
Feature:startup Feature scenario:i can start my app then I wait for the seconds then I take a screenshot
The first line represents the name of the functional test, the second line represents the scenario, the third row and the fourth behavior of the scenario: wait 15 seconds, then the screenshot.
Enter calabash-android run hacknews.apkon the command line, the application will be installed in the phone or simulator, after 15 seconds, will automatically screenshot, the picture is saved in the current project directory. You can also customize the saved path:
SCREENSHOT_PATH=/tmp/foo/ calabash-android run
To start the test in this way, the picture is saved below the directory/tmp/foo/.
Custom feature of basic usage
To create a new file touch_steps.rb in Step_definitions, add the following code:
#--Touch--#Then/^i (?:p ress|touch) on screen (\d+) from the left and (\d+) from the top$/do |x, Y|touch (nil, {: offset = = {: x = x.to_i,: y = = y.to_i}}) sleep (3) End
The custom feature will be parsed by the test framework. The function name is written in the/^ &/, the parameter list is located in | | In The code in the middle of then and end is the executed statement. Then add the code in the My_first.feature:
Then I touch on screens from the left and the top
The above code indicates a click on the ad bar in the graph
The next one will detail the built-in features in calabash-android
Getting Started with calabash-android usage