您好,登錄后才能下訂單哦!
所謂Launcher,指的是安卓的桌面管理程序,所有的應用圖標都放在launcher上面。其實這是一個很簡單的例子,只是為了驗證幾點想法而已。
做這個試驗的目的有二
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 test case */ private AndroidDriver 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","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 are 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); //本來想通過判斷屏幕上的幾個小圓點來判斷究竟有多少個屏幕的,但發覺xPath根本不起效,父目錄感覺根本起不了定位作用,只有最后的//android.widget.ImageView起效,所以一下找出75個元素。 /* 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(); } }步驟說明大概如下:
作者 | 自主博客 | 微信 | CSDN |
天地會珠海分舵 | http://techgogogo.com | 服務號:TechGoGoGo 掃描碼:
| 向AI問一下細節 推薦閱讀:
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。 猜你喜歡最新資訊相關推薦相關標簽AI
助 手
称多县|
北京市|
门头沟区|
内江市|
浪卡子县|
桂东县|
二连浩特市|
饶河县|
乌拉特中旗|
贵阳市|
正镶白旗|
竹北市|
营口市|
江北区|
德清县|
兴文县|
奎屯市|
和龙市|
儋州市|
东莞市|
南川市|
三穗县|
华坪县|
阿克苏市|
长海县|
杭锦后旗|
沈阳市|
吴旗县|
横山县|
沙坪坝区|
淮滨县|
辽阳市|
永善县|
长葛市|
宁化县|
巴林右旗|
彰化市|
新丰县|
灯塔市|
汝阳县|
安新县|
|