Appium instance Writing (1)---take contactstest.apk action as an example

Source: Internet
Author: User
Tags node server appium

For details, refer to http://www.cnblogs.com/puresoul/p/4696825.html#3326873 Practice

Objective:

Appium Environment Construction Reference Another blog: http://www.cnblogs.com/alwayswyy/p/4976933.html, mainly installs node. js, configures the various environments of the Android SDK, And the appium of installing the client.

The next step is to build a real-appium project to implement the automation of mobile apps (now with Android)!!!

I. Create a Java project in eclipse (file configuration):

 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

    • Copy and paste contactmanager.apk into the Apps folder
    • Copy and paste the following 4 jar packages into the Libs folder, and right--"build path" (very important, less a jar package will be error!!!!!! )

Selenum class Library: 1) Selenium-server-standalone-2.44.0.jar 2) Selenium-java-2.44.0.zip

Appium class Library: 1) Java-client-1.2.1.jar

Class library for Java parsing JSON: 1) Json.org.jar

Special Note: Because there is no missing Json.org.jar, the runtime Addcontact () This method error: java.lang.noclassdeffounderror:org/json/jsonexception

so pay special attention not to less this JAR package!!!

Two. Create the package and class

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

2, in the package under the new class (that is, simple Java Class): Contactstest.java, (after the Android unit test can be run),

The Contactstest.java code is as follows:

 PackageCom.wyy.demo;Importio.appium.java_client. Appiumdriver;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;ImportJava.io.File; ImportJava.net.URL; Importjava.util.List; Public classContactstest {PrivateAppiumdriver driver; @Before Public voidSetUp ()throwsException {//set the path of the APK, get the program current path System.getproperty ("User.dir"),
File Classpathroot =NewFile (System.getproperty ("User.dir")); File appdir =NewFile (Classpathroot,"Apps"); File app=NewFile (Appdir, "contactmanager.apk "); //set up automation related parameters, run platform for Android (or iOS), conflict with browser_name, cannot coexist,
Running the device for the emulator Android Emulator
Desiredcapabilities capabilities =Newdesiredcapabilities (); Capabilities.setcapability (Capabilitytype.browser_name,""); Capabilities.setcapability ("PlatformName", "Android"); Capabilities.setcapability ("DeviceName", "Android Emulator"); //set the Android version to be consistent with the emulator platform that startsCapabilities.setcapability ("platformversion", "4.3"); //Set APK pathCapabilities.setcapability ("App", App.getabsolutepath ()); //set the app's main package name and main class name, and the package name and class name later describe how to getCapabilities.setcapability ("Apppackage", "Com.example.android.contactmanager"); Capabilities.setcapability ("Appactivity", ". Contactmanager "); //Initialize, launch the install APK on the emulatorDriver =NewAppiumdriver (NewURL ("Http://127.0.0.1:4723/wd/hub"), capabilities); } @Test Public voidAddcontact () {
Add a contact to the app webelement El= Driver.findelement (By.name ("Add Contact")); El.click (); List<WebElement> textfieldslist = Driver.findelementsbyclassname ("Android.widget.EditText"); Textfieldslist.get (0). SendKeys ("Some Name")); Textfieldslist.get (2). SendKeys ("[Email protected]"); Driver.swipe (100, 500, 100, 100, 2); Driver.findelementbyname ("Save"). Click (); } @After Public voidTearDown ()throwsException {driver.quit (); }}

Once created, the project structure is as follows:

Three. Start the simulator, version 4.3

Click Eclipse's AVD, launch an emulator, version 4.3, execute cmd command after boot: ADB devices, startup success is as follows:

Four. Start Appium

Open Appium directly, click on the top of the boot triangle, start appium node server, start the successful result as follows:

Five. Run the test case

 1, in Eclipse, the project right > "Run as" > "JUnit Test", the operation of CONTACTSTEST.APK will be executed automatically, the operation process is as follows:

The first Appium project is now running successfully!!!!!!

PS: Here is a description of how to decompile get the package name (Apppackage) and class name (appactivity) of the APK

1. Download the dex2jar-0.0.9.15 (used to decompile the classes.dex into a jar file) and Jd-gui (open the Classes.dex-decompile jar file)

2. Locate the test apk, change the suffix to. zip, and unzip

3. Place the Classes.dex in the extracted directory into the Dex2jar.bat in the dex2jar-0.0.9.15 directory, keeping Classes.dex and Dex2jar.bat in the same directory

4. Run under cmd: Dex2jar.bat classes.dex to get Classes.dex.dex2jar.jar file

5. Execute Jd-gui.exe, open the anti-compiled file Classes.dex.dex2jar.jar, you can get the package name and class name

Appium instance Writing (1)---take contactstest.apk action as an example

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.