Calabash-Android usage
The previous section describes how to install the calabash-android test environment in windows. This article uses 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
After downloading the code, go to the project directory and enter calabash-android gen In the command line. This command will generate the directory features under the project directory. The directory structure is as follows:
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 stores user-defined features, and my_first.feature is used to write the test steps.
Basic usageScreenshots
Write the following code in my_first.feature:
Feature: Startup feature Scenario: I can start my app Then I wait for 15 seconds Then I take a screenshot
The first line indicates the name of the function test, the second line indicates the application scenario, and the third and fourth rows indicate what the Application Scenario does: Wait 15 seconds, and then take a screenshot.
EnterCalabash-android run HackNews.apkThe application will be installed in the mobile phone or simulator. After 15 seconds, the screenshot will be taken automatically and the images will be saved in the current project directory. You can also customize the saved path:
SCREENSHOT_PATH=/tmp/foo/ calabash-android run
Start the test in this way, and save the image under the/tmp/foo/directory.
Custom feature for basic usage
Create the file touch_steps.rb in step_definitions and add the following code:
# -- Touch --#Then /^I (?:press|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)endCustom feature will be parsed by the testing framework. The function name is written in/^ &/, and the parameter list is located in |. The code between Then and end is the executed statement. Then add the code in my_first.feature:
Then I touch on screen 100 from the left and 150 from the top
The code above indicates clicking the advertisement bar in the figure