Appium Getting Started example (Java)

Source: Internet
Author: User
Tags appium

first, the environment preparation :

See me in another article: http://www.cnblogs.com/sunny-sl/p/6519604.html

II. Create a case project directly with Eclipse

  1. Open Eclipse, "File"--"New"--"Project"

2. Select "Java Project"--"Next"

3, enter the project name Appium_demo, click "Finish"

4, right click on the project New-folder, new two folders: Apps and Libs, directory structure as follows:

Third, the class library of the import test

  1, Import Selenum class library: http://docs.seleniumhq.org/download/

1) Selenium-server-standalone-2.44.0.jar

2) Selenium-java-2.44.0.zip

2. Import the Appium class library:

1) Java-client-1.2.1.jar

3, right click on the project blank, select "Build Path"--"Configure Build Path"

four . Download Test apk

1, download the test file Contactmanager.apk:https://github.com/appium/sample-code/tree/master/sample-code/apps/contactmanager

2. Put the downloaded apk into the project's Apps directory

V. Building package packages and case files

  1. Right-click on the src folder, "New"--"package", enter the bundle name: Com.dan.demo, click "Finish"

2, in the package under the new class: Demo1.java, as follows:  

  : Https://github.com/appium/sample-code/tree/master/sample-code/examples/java/junit/src/test/java/com/saucelabs/appium

Package Com.dan.demo;

Import java.net.MalformedURLException;
Import Java.net.URL;
Import java.util.List;
Import Java.util.concurrent.TimeUnit;

Import Org.openqa.selenium.By;
Import org.openqa.selenium.remote.DesiredCapabilities;

Import Io.appium.java_client.android.AndroidDriver;
Import io.appium.java_client.android.AndroidElement;

public class Demo1 {

public static void Main (string[] args) throws Exception {
Androiddriver driver;
Desiredcapabilities cap=new desiredcapabilities ();
Cap.setcapability ("Automationname", "Appium");//appium do automation
Cap.setcapability ("App", "c:\\software\\jrtt.apk");//install APK
Cap.setcapability ("Browsername", "Chrome");//Set HTML5 Automation to open Google Chrome
Cap.setcapability ("DeviceName", "S4");//Device name
Cap.setcapability ("PlatformName", "Android"); Android Automation or iOS automation
Cap.setcapability ("Platformversion", "4.4"); Android OS version
Cap.setcapability ("Udid", "192.168.56.101:5555"); Udid of the equipment (ADB devices See)
Cap.setcapability ("Apppackage", "Com.android.calculator2");//package name of the app under test
Cap.setcapability ("Appactivity", ". Calculator ");//The entry activity name of the app being tested
Cap.setcapability ("Unicodekeyboard", "True"); Support Chinese input
Cap.setcapability ("Resetkeyboard", "True"); Support Chinese input, must be configured in two bar
Cap.setcapability ("NoSign", "True"); Do not re-sign apk
Cap.setcapability ("Newcommandtimeout", "30"); No new commands, appium30 seconds out
Driver = new Androiddriver (New URL ("Http://127.0.0.1:4723/wd/hub"), cap);//upload the above configuration to the Appium server and connect the phone
Driver.manage (). Timeouts (). Implicitlywait (Ten, timeunit.seconds);//implicit waiting
Locating elements by resource name
Driver.findelement (By.name ("1")). Click ();
Driver.findelement (By.name ("+")). Click ();
Driver.findelement (By.name ("1")). Click ();
Driver.findelement (by.name ("=")). Click ();
}

}

six . Start the Android emulator (you can also connect the real machine)

  1. cmd input: Android AVD, select Simulator, click "Start".

2, start well, cmd input: adb devices, determine whether the device is connected, such as the successful connection:

Seven, start Appium

  Method One: cmd input: Appium

  

Method Two:

1. Double-click the Appium GUI icon directly (for example):

  

2. Click the Start button in the top right corner to start the log as follows:

  

Eight, run the test case:

1. In Eclipse, Project right > "Run as" > "JUnit Test"

2. Appium Operation Result:

 

Appium Getting Started example (Java)

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.