Analyzing the process of a case execution by Appium Server Log

Source: Internet
Author: User
Tags appium

The purpose of this article is to deepen the understanding of the role played by Appium server by analyzing the log printed by Appium server.

This entire process is performed by a test case to the end, and the object being tested is the SDK's own notepad.apk. Test case is simple: Open the Notepad program and click on the android menu options button to bring up the "Add Note" menu button, then click the button and complete the test.

Package Majcit.com.appiumdemo;import io.appium.java_client. Appiumdriver;import java.io.file;import java.net.url;import Java.util.list;import org.junit.Test;import Org.junit.after;import Org.junit.before;import Org.openqa.selenium.by;import org.openqa.selenium.WebElement; Import Org.openqa.selenium.remote.capabilitytype;import Org.openqa.selenium.remote.desiredcapabilities;import Org.openqa.selenium.remote.remotewebdriver;import org.openqa.selenium.*;import static org.hamcrest.Matchers.*;     Import Static org.hamcrest.matcherassert.assertthat;/** * Unit test for simple App. */public class Noetpadtest {/**    * Create the test case * * @param testname name of the "test case */private Appiumdriver driver; @Before public void SetUp () throws Exception {//Set up Appium file Classpathroot = new file (system.getp        Roperty ("User.dir"));        File Appdir = new file (Classpathroot, "apps");        File app = new file (appdir, "notepad.apk"); Desiredcapabilities capabilities = new desiredcapabilities ();        Capabilities.setcapability ("DeviceName", "IPad Simulator");        Capabilities.setcapability ("Platformversion", "4.2");        Capabilities.setcapability ("PlatformName", "Android");        Capabilities.setcapability ("App", App.getabsolutepath ());        Capabilities.setcapability ("Apppackage", "Com.example.android.notepad");        Capabilities.setcapability ("Appactivity", "com.example.android.notepad.NotesList"); Capabilities.setcapability ("Appactivity", ".        Noteslist ");    Driver = new Appiumdriver (New URL ("Http://127.0.0.1:4723/wd/hub"), capabilities);    } @After public void TearDown () throws Exception {driver.quit ();                } @Test public void Addcontact () throws interruptedexception{Driver.sendkeyevent (82);        try {thread.sleep (3000);        }catch (Exception e) {System.out.println (E.getmessage ()); } webelement el = Driver.findelement (by.name("Add note");        El.click ();        try {thread.sleep (60000);        }catch (Exception e) {System.out.println (E.getmessage ()); }            }    }
Let's take a look at what the Appium server has done by analyzing log.

1. Start the rest HTTP server, which listens to the local 4723 port by default, and is used to receive command indications from the JSON format that the client (Test case+selenium/appium Driver) sent over.

2. Establish an Android sesision to maintain subsequent communication with the client based on the capabilities instructions provided by the client

3. Check if the Android phone is ready with the "ADB Devices" command

4. Use the tool "AAPT dump badging notepad.apk" to obtain NotePad PackageName and launchable activityname, note that the example code does not specify this two capabilities

5. Android phone Shell invoke command to get the machine's API level has exceeded: "Adb.exe-s ht21atd05099 shell Getprop ro.build.version.sdk"


6. Execute the appropriate shell command via ADB to check if the target app already exists: "PM List packages-3 Com.example.android.notepad"

7. Clean the target application running environment on the target machine: stop to clear the data when it is stopped

8. Establish port forwarding on the Appium server to the target machine

9. Push the appiumbootstrap.apk to the target device: This is the server running through the Uiautomator tool (framework) on the target machine to accept commands sent by the client side

10. Push settings_apk-debuug.apk and unlock_apk-debug.apk to target set: TBD

11. Ensure that the uiautomator is not already running

12. Run the Appiumbootstrap on the target machine via adb: "Uiautomator runtest appiumbootstrap.jar-c Io.appium.android.bootstrap.Rootstrap ".


13. Launch Notepad application on target machine via ADB

14. Notify the PC-side target application that the target machine has been successfully started

15. Handle the "Press the System Menu" command sent by the client: Bootstrap the received command into the queue and notifies the client to execute the result after the execution is completed


16. Position the "Add Note" menu button: Bootstrap through the uiautomator of the Uiselector class according to the text to get the menu button ID and return to the client

Bootstrap execute the "Click Add Note Menu" command


18. Test complete, Target machine simulation Click the Home button to put the target app in the background

19. Close Logcat

20. Close the Uiautomator process


Analyzing the process of a case execution by Appium Server Log

Related Article

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.