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
- 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.getproperty ("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
"Go" Appium activity analysis of server-side from boot to case completion