Calabash-Android usage, calabash-android

Source: Internet
Author: User

Calabash-Android usage, calabash-android

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)end
Custom 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


The next section describes the built-in features in calabash-android.


In Android development, how does one use Intent?

There are too many Intent things to say. If you are a beginner, you only need to understand its explicit calls. For example, you need to jump from activity1 to activity2 and execute the following statement in activity1, you can jump to activity2, and do not forget to go to manifest. define activity2 in xml.
Intent intent = new Intent (activity1.this, activity2.class );
StartActivity (intent );
This is the simplest way, of course, this method can also transmit data (from activity1 to activity2), such
Intent intent = new Intent (activity1.this, activity2.class );
Intent. putExtra ("name", "value ");
StartActivity (intent );
Then, the onResume or onCreate method is called to obtain the Intent in the location received in activity2.
Intent getIntent = getIntent ();
Bundle bundle = intent. getExtras ();
String va = bundle. getString ("name ");

The above is the basic usage of explicit calling. The essence of Intent is implicit calling. If you have any questions, please contact us.

Questions about table layout in android

Com. yarin. android. cityWeather. singleWeatherInfoView is a class. SingleWeatherInfoView inherits a class. In this class, you can override some methods to achieve the desired effect. you can paste the code of some classes.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.