The so-called launcher, refers to the Android Desktop management program, all the application icons are placed on the launcher above. In fact, this is a very simple example, just to verify a few ideas.
1. Purpose of the experiment
The purpose of this experiment is two.
- Try the use of the form sliding function swipe
- Wondering if you can normally test the launcher of Android with the assigned package and activity.
2. The experimental background process is intended to use Appium to start the launcher and then slide the window to get the SDK app "Notes" on the third desktop. As shown
3. Test Step 3.1 Get Launcher's package and activity two capabilities can be viewed directly through Hierarchyviewer
3.2 Encoding Implementation
Package Majcit.com.appiumdemo;import Io.appium.java_client.android.androiddriver;import Java.net.URL;import Org.junit.test;import Org.junit.after;import Org.junit.before;import Org.openqa.selenium.dimension;import Org.openqa.selenium.nosuchelementexception;import Org.openqa.selenium.point;import Org.openqa.selenium.webelement;import Org.openqa.selenium.remote.desiredcapabilities;import Static Org.hamcrest.matchers.*;import Static org.hamcrest.matcherassert.assertthat;/** * Unit test for simple App. */public Class Launchertest {/** * Create the test case * * @param testname name of the the test case */private and Roiddriver driver; @Before public void SetUp () throws Exception {//Set up appium//file classpathroot = new File (system.ge Tproperty ("User.dir")); File Appdir = new file (Classpathroot, "apps"); File app = new file (appdir, "notepad.apk"); Desiredcapabilities capabilities = new Desiredcapabilities (); Capabilities. Setcapability ("DeviceName", "Android"); Capabilities.setcapability ("Platformversion", "4.2"); Capabilities.setcapability ("PlatformName", "Android"); Capabilities.setcapability ("App", App.getabsolutepath ()); Capabilities.setcapability ("Apppackage", "com.miui.home"); Capabilities.setcapability ("Appactivity", "Com.miui.home.launcher.Launcher"); Capabilities.setcapability ("Appactivity", ". Noteslist "); Capabilities.setcapability ("AutoLaunch", "false"); Capabilities.setcapability ("NoReset", true); 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 Launchnotepad () throws interruptedexception{webelement el = null; Webelement screen = null; Point point = NULL; Dimension size = null; Boolean found = false; int pagecount = 3; Assume that there is tOtally 3 screens to be swiped. int xstart =-1; int ystart =-1; int xEnd =-1; int yend =-1; Get the start and end coordinates for swipe thread.sleep (3000); Screen = Driver.findelementbyid ("Com.miui.home:id/cell_layout"); Point = Screen.getlocation (); Size = Screen.getsize (); XEnd = Point.getx (); Yend = point.gety () + size.getheight ()/2; Xstart = Point.getx () + size.getwidth ()-5; Ystart = yend; System.out.println ("Starx:" + Xstart + "\nstarty:" + Ystart + "\nendx:" + xEnd + "\nendy:" + yend); Originally wanted to judge the screen by a few small dots to determine exactly how many screens, but found that the XPath does not work, the parent directory does not feel at all the role of positioning, only the last//android.widget.imageview effect, so find out 75 elements. /* List<webelement> pageimages = Driver.findelementsbyxpath ("//android.view.view/android.widget.linearlayout /android.widget.imageview "); Assertthat (Pageimages.size (), is (3)); for (Webelement e:pageimages) {E.click (); } *///swipe All screens till get the expected control int currentpage = 0; while (found = = False && CurrentPage < PageCount) {found = true; CurrentPage + = 1; try {el = driver.findelementbyname ("Notes"); }catch (nosuchelementexception e) {found = false; System.out.println (e); } if (found = = true) break; Driver.swipe (Xstart, Ystart, XEnd, yend, 100); Thread.Sleep (1000); } assertthat (Found,is (true)); Assertthat (El,notnullvalue ()); El.click (); } }The steps are described as follows:
- Prepare the required capabilities to the Appium server, and note the app, as we do not need to reinstall the launcher
- Locate the control that represents the entire screen, and then calculate the coordinates for the start and end of the slide by getting its location and size property. Note that the starting coordinate is the screen boundary, you need to adjust the next pixel (minus 5 pixels in the example) in case of an error.
- Slide through each page until you find the target control.
Appium Test Android Launcher to get the target app with sliding form