Appium Environment Construction has been written in the blog
Http://www.cnblogs.com/feimaoyuzhubaobao/p/5057832.html
Then this blog mainly introduces the Java version of the Appium starter demo. Before starting the demo, the Android emulator to install, in fact, the simulator is the simulator real machine, in addition to not call and send messages, the other should be OK. Simulator words can also be installed here genymotion, in fact, it is not a common simulator, strictly speaking, genymotion is a virtual machine, is defined as the network simulator. If you want to install this simulator. I am here to provide the installation file address Http://yun.baidu.com/s/1pJC6ve7 and my own account number and password on the official online register: Feimao, feimao12345. Genymotion installation files are more, the effect is indeed faster than the previous AVD.exe simulator. I will not repeat the simulator, the following began the formal Appium introduction demo.
Create a case project with eclipse
1. open Eclipse, "File"--"New"--"Project"
2. Select "Java Project"--"Next"
3. Enter the project name Appiumdemo, click "Finish"
4. Right click on Project New-folder, create two new folders: Apps and Libs, directory structure as follows:
Class Library for importing tests
Because Appium drives Apple's UIAutomation library and Android's uiautomator framework, the Selenium webdriver JSON protocol is used. So the Selenium class library is to be imported.
1.Selenum2 class Library: Http://seleniumhq.org/downlod
The friend who has done selenium automation this piece should be familiar, don't say more.
2.Appium class Library: http://appium.io/downloads.html
3. Right click on the project blank and select "Build Path"--"Configure Build Path"
Selenium class library I import compared to Doha, does not affect.
Download Test APK
1. Download the test file
contactmanager.apk Https://github.com/appium/sample-code/tree/master/sample-code/apps/ContactManager
2. copy and paste the downloaded apk directly into the project's Apps directory
Establish Package packages and Case Files
1. Right-click on the src folder, "New"--"package", enter the bundle name: Com.feimao.demo, click "Finish"
2. new class under the package: Contactstest.java
As follows:
Https://github.com/appium/sample-code/tree/master/sample-code/examples/java/junit/src/test/java/com/saucelabs/appium
The code is as follows:
PackageCom.feimao.demo;ImportJava.io.File;ImportJava.net.URL;Importjava.util.List;ImportOrg.junit.After;ImportOrg.junit.Before;Importorg.junit.Test;Importorg.openqa.selenium.By;Importorg.openqa.selenium.WebElement;ImportOrg.openqa.selenium.remote.CapabilityType;Importorg.openqa.selenium.remote.DesiredCapabilities;Importio.appium.java_client. Appiumdriver;ImportIo.appium.java_client.android.AndroidDriver; Public classContacttest {PrivateAndroiddriver driver; @Before Public voidSetUp ()throwsException {//set the path of the APKFile Classpathroot =NewFile (System.getproperty ("User.dir")); File Appdir=NewFile (Classpathroot, "apps"); File app=NewFile (Appdir, "contactmanager.apk"); //setting Automation-related parametersDesiredcapabilities capabilities =Newdesiredcapabilities (); Capabilities.setcapability (Capabilitytype.browser_name,""); Capabilities.setcapability ("PlatformName", "Android"); Capabilities.setcapability ("DeviceName", "Android Emulator"); //setting up the Android system versionCapabilities.setcapability ("Platformversion", "4.4.2"); //Set APK pathCapabilities.setcapability ("App", App.getabsolutepath ()); //set the app's main package name and main class nameCapabilities.setcapability ("Apppackage", "Com.example.android.contactmanager"); Capabilities.setcapability ("Appactivity", ". Contactmanager "); //InitializeDriver =NewAndroiddriver (NewURL ("Http://127.0.0.1:4723/wd/hub"), capabilities); } @Test Public voidaddcontact () {webelement El= Driver.findelement (By.name ("Add Contact")); El.click (); List<WebElement> textfieldslist = Driver.findelementsbyclassname ("Android.widget.EditText"); Textfieldslist.get (0). SendKeys ("Feimaoyuzhubaobao"); Textfieldslist.get (2). SendKeys ("Forever Together"); Driver.swipe (100, 500, 100, 100, 2); Driver.findelementbyname ("Save"). Click (); } @After Public voidTearDown ()throwsException {driver.quit (); }}
Start Android Simulator (can also connect to the real machine)
1.cmd input: Android AVD, select Simulator, click "Start". If you have integrated plug-ins in eclipse, you can also start directly in Eclipse.
2. after starting, cmd input: adb devices, determine if the device is connected, such as a successful connection:
Start Appium
1. since the Appium was previously installed, double-click it and then click the Start button
2.cmd command, appium start
Run Appium Getting Started Demo
1. in Eclipse, the project right-click > "Run as" > "JUnit Test", run the following procedure:
Here Appium's introductory demo has all been written, this is just a mock call contact example, and then can simulate this demo, write login ah, positioning elements ah and so on. There are 9 ways to locate elements in Appium, and the following will write some examples of work and ways to solve appium problems. In addition, you can also go to the official web download source code to see its principle, look at its API, technology is so, nothing difficult, for their own refueling ~
appium-Introduction Demo