Autotesting _ open-source mobile automated testing framework IQUERY getting started tutorial (1)

Source: Internet
Author: User
Tags lexer

After the previous introduction of IQUERY, some friends started to try IQUERY in the mobile phone automated testing program. As the previous introduction documents are vague, extend IQUERY to support a series of articles in multiple programming languages and add the IQUERY getting started tutorial. For more information about the previous introductory articles, see:
1. Open-source class library IQUERY android
2. Introduction to IQUERY open-source class library for control query of jquery Selector

IQUERY is an open source automated testing framework project, interested friends can download: https://github.com/vowei/iQuery/downloads

Location: https://github.com/vowei/iQuery

IQUERY for iOS simple tutorial

 

Currently, IQUERY for iOS only supports automated testing in instrument. In this tutorial, we use the following program to demonstrate how to compile automated testing cases using IQUERY for iOS:

Apps available in iPhone simulators: https://github.com/vowei/iQuery/tree/master/iOS/targetApp
Source code: https://github.com/vowei/iQuery/tree/master/iOS/targetApp/Gestures

The automated test cases demonstrated in this tutorial need to download the IQUERY for iOS Class Library:

Https://github.com/downloads/vowei/iQuery/iQuery%20for%20iOS.zip

Follow these steps to create and run an automated test case for the IOS program:
1. Start instruments on Mac:

2. In the "choose a template for the trace document" dialog box, select "Automation ".

3. Click the choose target drop-down box on instruments.

 
4. Set our demo program gestures. app as the target program.

 
5. Gestures. app requires the iOS 5 simulator to be explicitly set.

 
6. Click "create ..." Button to create a new automated test case script.

 
7. Enter the following code in the new script dialog box.
 
8. Finally, click the "run" button below to execute the automated test case script and view the result in the result dialog box.

IQUERY for Android simple tutorial


This tutorial is based on the android instrumentation testing technology. However, IQUERY for Android also supports querying controls from the view server output, the following article describes how to obtain the android activity level information from the view server:

Demo Android program in: https://github.com/vowei/iQuery/tree/master/java/Test/multiplatformdemoproject
Its source code in: https://github.com/vowei/iQuery/tree/master/java/sample

The following describes how to use IQUERY to compile the android instrument UI test:
1. Open eclipse and create a new Android project named tutorial.

 
2. IQUERY supports Android 2.2 and later versions. In this tutorial, we select the Android 2.2 platform.

 
3. Because a test project is created, no activity needs to be added.

 
4. After the project is created, update the manifest. xml file of the new project and add a new instrumentation block to specify the package name of the application to be tested.

 
5. In eclipse, right-click the Tutorial Project and choose "build path"> "Configure build path ".

 
6. In the "properties for tutorial" dialog box, click "add external jars.

 
7. Add references to the iquery-core.jar and iquery-instrumentation.jar, because IQUERY is anlr-based, you also need to add references to the antlr-runtime-3.4.jar. In this tutorial, we use robotium to capture and modify the information of the UI control and also need to add references to the robotium-solo-3.1.jar. Finally, build path should be as follows:

 
8. Create a new test case file and enter the following code.

package cc.iqa.studio.demo.test; import java.io.*; import java.util.*; import org.antlr.runtime.*; import junit.framework.Assert; import cc.iqa.iquery.*; import cc.iqa.iquery.android.*; import com.jayway.android.robotium.solo.*; import android.test.ActivityInstrumentationTestCase2; import android.view.*; @SuppressWarnings("rawtypes") public class DemoOnlyTest extends ActivityInstrumentationTestCase2 {    private static String LAUNCHER_ACTIVITY_FULL_CLASSNAME = "cc.iqa.studio.demo.MainActivity";private static String TARGET_PACKAGE_ID = "cc.iqa.studio.demo";private Solo _solo;@SuppressWarnings("unchecked")public DemoOnlyTest() throws Exception {    super(TARGET_PACKAGE_ID, Class            .forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME));}public void setUp() throws Exception {    this._solo = new Solo(this.getInstrumentation(), this.getActivity());}public void testSimplifiedAPI() throws Exception {    List<SoloTreeNode> r1 = iQuery.query(            new SoloTreeNode(_solo.getCurrentViews().get(0)),             "LinearLayout >> TextView [mText = 'Down Under']");    Assert.assertEquals(2, r1.size());              }private List<ITreeNode> parseQueryAgainst(View root, String iquery)        throws IOException, RecognitionException {    InputStream query = new ByteArrayInputStream(iquery.getBytes("utf8"));    ANTLRInputStream input = new ANTLRInputStream(query);    iQueryLexer lexer = new iQueryLexer(input);    CommonTokenStream tokens = new CommonTokenStream(lexer);    iQueryParser parser = new iQueryParser(tokens);    List<ITreeNode> candidates = new ArrayList<ITreeNode>();    candidates.add(new SoloTreeNode(root));    List<ITreeNode> result = parser.query(candidates);    return result;} }


9. Finally, install the android program used in the demo on the simulator or mobile phone and run the test case.

The complete test case file can be downloaded from here:
Https://github.com/vowei/iQuery/blob/master/java/sample/src/cc/iqa/studio/demo/test/DemoOnlyTest.java

Reprinted from: http://www.cnblogs.com/vowei/archive/2012/09/07/2674889.html

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.