Appium Test Cases--install APK with code

Source: Internet
Author: User
Tags appium

Create a new Apps folder on the Java project to hold the APK package being tested and drag and drop the apk into the folder:

Second, create a new class, enter the code as follows:

/* *   Install application contactmanager.apk *   Open Contactmanager, enter contact name, mailbox, click Save */package  appiumtest; import io.appium.java_client.android.AndroidDriver;import org.junit.After; import org.junit.before;import org.junit.test;import org.openqa.selenium.by;import  org.openqa.selenium.webelement;import org.openqa.selenium.remote.capabilitytype;import  Org.openqa.selenium.remote.desiredcapabilities; import java.io.file;import java.net.url;import  java.util.List; public class demo1 {    private  androiddriver driver;      @Before     public void  SetUp ()  throws exception {        // set up  appium        file classpathroot = new file ( System.getproperty ("User.dir"));    &nbSp;    file appdir = new file (classpathroot,  "apps");         file app = new file (appDir,  "ContactManager.apk") ;        desiredcapabilities capabilities = new  Desiredcapabilities ();         capabilities.setcapability ( capabilitytype.browser_name,  "");         Capabilities.setcapability ("PlatformName",  "Android");         Capabilities.setcapability ("DeviceName", "Android emulator");         capabilities.setcapability ("Platformversion",  "4.2.2");         capabilities.setcapability ("App",  app.getabsolutepath ());         capabilities.setcapability ("apppackage",  "com.Example.android.contactmanager ");         capabilities.setcapability (" Appactivity ", ". Contactmanager ");         driver = new androiddriver (new  url ("Http://127.0.0.1:4723/wd/hub"),  capabilities);    }       @After     public void teardown ()  throws exception {         driver.quit ();    }       @Test     public void addcontact () {         webelement el = driver.findelement (By.name ("Add contact"));         el.click ();        list< Webelement> textfieldslist = driver.findelementsbyclassname ("Android.widget.EditText");    &Nbsp;    textfieldslist.get (0). SendKeys ("Some name");         textfieldslist.get (2). SendKeys ("[email protected]");         //driver.swipe (100, 500, 100, 100, 2);         driver.findelementbyname ("Save"). Click ();     }}

Third, open the Android emulator, run the test case, the system automatically installs the tested contactmanager.apk, and opens, executes the test case, closes the app.

Note: If you do not want the program to be installed automatically, you can manually install it using the command (make sure your Android emulator is turned on), win+r, enter "adb install the path and name of the APK to be tested."

As I prepare the apk named "app-release0902.apk", in the computer "C:\Users\xiaoqing.he\Desktop\coding" folder, you should enter the command "adb install C:\Users\ Xiaoqing.he\desktop\coding\app-release0902.apk ", appear status, prompt success that means the installation is successful!

Appium Test Cases--install APK with code

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.