"Go" Appium activity analysis of server-side from boot to case completion

Source: Internet
Author: User
Tags appium

Original address: http://blog.csdn.net/zhubaitian/article/details/39474151

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.

[Java]View Plaincopy
  1. Package Majcit.com.AppiumDemo;
  2. Import Io.appium.java_client. Appiumdriver;
  3. Import Java.io.File;
  4. Import Java.net.URL;
  5. Import java.util.List;
  6. Import Org.junit.Test;
  7. Import Org.junit.After;
  8. Import Org.junit.Before;
  9. Import Org.openqa.selenium.By;
  10. Import org.openqa.selenium.WebElement;
  11. Import Org.openqa.selenium.remote.CapabilityType;
  12. Import org.openqa.selenium.remote.DesiredCapabilities;
  13. Import Org.openqa.selenium.remote.RemoteWebDriver;
  14. Import org.openqa.selenium.*;
  15. Import static org.hamcrest.matchers.*;
  16. Import static org.hamcrest.MatcherAssert.assertThat;
  17. /**
  18. * Unit test for simple App.
  19. */
  20. Public class Noetpadtest {
  21. /** 
  22. * Create the test case
  23. *
  24. * @param testname name of the test case
  25. */
  26. private Appiumdriver driver;
  27. @Before
  28. public void SetUp () throws Exception {
  29. //Set up Appium
  30. File Classpathroot = new File (System.getproperty ("User.dir"));
  31. File Appdir = new File (Classpathroot, "apps");
  32. File app = new File (Appdir, "notepad.apk");
  33. Desiredcapabilities capabilities = new Desiredcapabilities ();
  34. Capabilities.setcapability ("DeviceName","IPad Simulator");
  35. //capabilities.setcapability ("Platformversion", "4.2");
  36. Capabilities.setcapability ("PlatformName", "Android");
  37. Capabilities.setcapability ("app", App.getabsolutepath ());
  38. //capabilities.setcapability ("Apppackage", "Com.example.android.notepad");
  39. //capabilities.setcapability ("appactivity", "com.example.android.notepad.NotesList");
  40. //capabilities.setcapability ("Appactivity", ".  Noteslist ");
  41. Driver = New Appiumdriver (new URL ("Http://127.0.0.1:4723/wd/hub"), capabilities);
  42. }
  43. @After
  44. public void TearDown () throws Exception {
  45. Driver.quit ();
  46. }
  47. @Test
  48. public void Addcontact () throws interruptedexception{
  49. Driver.sendkeyevent (82);
  50. try {
  51. Thread.Sleep (3000);
  52. }catch (Exception e) {
  53. System.out.println (E.getmessage ());
  54. }
  55. Webelement el = driver.findelement (By.name ("Add note");
  56. El.click ();
  57. try {
  58. Thread.Sleep (60000);
  59. }catch (Exception e) {
  60. System.out.println (E.getmessage ());
  61. }
  62. }
  63. }

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

"Go" Appium activity analysis of server-side from boot to case completion

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.