Hybrid app builds an automated test development environment with Appium

Source: Internet
Author: User
Tags appium

Appium

Official website: http://appium.io/

Chinese community: http://testerhome.com/

(provided by Testerhome Community): Http://pan.baidu.com/s/1jGvAISu#dir

1. Download the latest version Appiumserver 1.2.0, after decompression, enter the directory to find Appium.exe, run can, this program as Appnium and the device under test communication between the server

The following interface is shown to start successfully

2. Connect the real machine to the PC side

3. I use eclipse as a development IDE to create a MAVEN engineering Appium-demo that references the Selenium core project in the company framework in Pom, which eliminates the process of adding selenium dependencies

, and find the Appium package in the central repository of MAVEN, and reference

Appium's MAVEN reference

GroupId:io.appium

Artifactid:java-client

version:1.5.0

4. Once the project is established, it is possible to write the test code and create a JUnit test class Test1.java in the project with the following code:

Package Com.example.hello;import io.appium.java_client. Appiumdriver;import java.io.file;import java.net.malformedurlexception;import Java.net.URL;import java.util.Set; Import Junit.framework.testcase;import org.junit.after;import Org.junit.before;import Org.junit.Test;import Org.junit.runner.runwith;import Org.junit.runners.blockjunit4classrunner;import Org.openqa.selenium.By;import Org.openqa.selenium.javascriptexecutor;import Org.openqa.selenium.webelement;import Org.openqa.selenium.remote.DesiredCapabilities, @RunWith (blockjunit4classrunner.class) public class Test1 extends    TestCase {private Appiumdriver driver; @Before public void Start () throws Malformedurlexception {//Hybrid app path packaged with phonegap String AppPath =        "D:\\WORK\\CODES\\HANDS\\HANDS-HELLO-PHONEGAP\\PLATFORMS\\ANDROID\\BIN\\HELLOWORLD.APK";        Initialize Appniumdriver desiredcapabilities capabilities = new Desiredcapabilities (); Capabilities.setcapability ("DeviceName", "nx403a");//real Machine test aNdroid device capabilities.setcapability ("Platformversion", "4.2.2");//Real Machine Android version 4.2.2 Capabilities.setcapabil ity ("PlatformName", "Android");//real machine for Android system capabilities.setcapability ("app", AppPath);//Beta app apk package location C Apabilities.setcapability ("Apppackage", "Com.example.hello");//The Activity class of the app being tested capabilities.setcapability (" Appactivity ",". HelloWorld ");//The Activity class of the app Capabilities.setcapability (" Automationname "," selendroid ");//Because the real machine is version 4.2, so use Selen The Droid//Http://127.0.0.1:4723/wd/hub address is Appiumserver's address driver = new Appiumdriver (The new URL ("http://127.0.0.1    : 4723/wd/hub "), capabilities);            } @Test public void Main () {try {set<string> contextnames = Driver.getcontexthandles (); for (String contextname:contextnames) {System.out.println (contextname);//used to return the app being tested is NATIVE_AP           P or WebView, if both have a hybrid app} thread.sleep (5000);//wait for it for a while Driver.context ("Webview_0");//Let appium switch to WEBVIEW mode to find web elements webelement text_baidusearch = Driver.findelement (B            Y.id ("word"));             Text_baidusearch.click ();//Click Baidu's Search Input box (web Element)/* * Appium does not support Chinese input reference robotium the way to set value directly for an element in JS mode * Use selenium Webdriver execution JS method to achieve Chinese input */javascriptexecutor JSE = (javascriptexecutor) driv            Er            Jse.executescript ("document.getElementById (' word '). Value= ' Input method ');        Thread.Sleep (10000);//Wait a while to observe the effect} catch (Interruptedexception e) {e.printstacktrace ();    }} @After public void Stop () {driver.quit (); }}

The engineering structure is as follows

5. Keep the device under test unlocked, although Appium has a unlock function, but sometimes it doesn't work, so it's best to turn the lock screen off. Run Test1.java to get the following results

Hybrid app builds an automated test development environment with Appium

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.