<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # Appium自動化測試(Java版) # Appium自動化測試 ### Appium軟件配置(僅設置圖片所展示即可) ![在這里插入圖片描述](https://www.icode9.com/img/ll/?i=20201204124727442.png?,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ0NDg2NDM3,size_16,color_FFFFFF,t_70) ![在這里插入圖片描述](https://www.icode9.com/img/ll/?i=20201204124737669.png?,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ0NDg2NDM3,size_16,color_FFFFFF,t_70) ### Appium-Inspector工具配置 **Desired Capabilities屬性值配置** | 屬性名稱 | 類型 | 值 | | :-: | :-: | :-: | | deviceName | text | 127.0.0.1:62001 | | platformName | text | Android | | appPackage | text | com.smile.gifmaker | | appActivity | text | com.yxcorp.gifshow.HomeActivity | * 連接到夜神模擬器 ~~~ adb connect 127.0.0.1:62001 ~~~ * 檢測設備 ~~~ adb devices ~~~ * 獲取包名 在build-tools文件夾下,cmd中輸入命令 ~~~ aapt dump badging D:\Android\software\kuaishou.apk(軟件路徑) ~~~ ![在這里插入圖片描述](https://www.icode9.com/img/ll/?i=20201204124804881.png?,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ0NDg2NDM3,size_16,color_FFFFFF,t_70) * 獲取應用程序入口 在獲取包名的同時找launchable-activity的值 ![](https://img.kancloud.cn/ac/ab/acab07080e4af76d0b99e0831ff29645_1223x639.jpg) **配置結果** ![在這里插入圖片描述](https://www.icode9.com/img/ll/?i=20201204124821700.png?,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ0NDg2NDM3,size_16,color_FFFFFF,t_70) 啟動會話后,若出現下面結果,則配置成功。 ![在這里插入圖片描述](https://www.icode9.com/img/ll/?i=20201204124834932.png?,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ0NDg2NDM3,size_16,color_FFFFFF,t_70) ### 元素探測工具 ##### Appium Inspector工具 ![](https://img.kancloud.cn/26/da/26da346e46adbfcced85f8f3b9de883e_1920x1044.jpg) ##### UIAutomatorViewer工具(SDK提供的原生元素定位工具,不需要提供啟動參數) 該工具在Android/Android-SDK/tools/bin目錄下 ![](https://img.kancloud.cn/eb/ae/ebaeeb61e9c3fd9acbf2c83b301dd640_784x592.jpg) ### 名稱解釋 **PackageName**(包名)應用程序的唯一標識 **ActivityName**(類名)一個頁面的名字 可以通過命令 ~~~ adb shell dumpsys activity | find "mFocusedActivity" ~~~ 查看當前聚焦頁面的包名和類名 ![在這里插入圖片描述](https://www.icode9.com/img/ll/?i=2020120412491094.png?,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ0NDg2NDM3,size_16,color_FFFFFF,t_70) ### App類型對比 ![在這里插入圖片描述](https://www.icode9.com/img/ll/?i=20201204124920986.png?,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ0NDg2NDM3,size_16,color_FFFFFF,t_70) ### APP頁面布局 ![在這里插入圖片描述](https://www.icode9.com/img/ll/?i=20201204124929228.png?,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ0NDg2NDM3,size_16,color_FFFFFF,t_70) ### APP頁面控件 ![在這里插入圖片描述](https://www.icode9.com/img/ll/?i=20201204124934369.png?,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ0NDg2NDM3,size_16,color_FFFFFF,t_70) ### ADB組件 ![在這里插入圖片描述](https://www.icode9.com/img/ll/?i=20201204124942218.png?,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ0NDg2NDM3,size_16,color_FFFFFF,t_70) #### adb常用命令 * 查看幫助手冊 ~~~ adb help ~~~ * 檢測連接到電腦的安卓設備(注意模擬器的連接) ~~~ adb devices ~~~ * 從手機中拉取信息放到本地電腦上 ~~~ adb pull<手機路徑><本機路徑> ~~~ * 從本地推送信息到手機上去 ~~~ adb push<本機路徑><手機路徑> ~~~ * 登錄設備shell模式(命令行的人機界面) ~~~ adb shell ~~~ * 安裝應用 ~~~ adb install xxx.apk ~~~ * 卸載應用 ~~~ adb uninstall com.ss.android.ugc.aweme(應用程序包名) ~~~ * 查看前臺應用包名 ~~~ adb shell dumpsys activity | find "mFocusedActivity" ~~~ * 終止adb服務 ~~~ adb kill-server ~~~ * 啟動adb服務 ~~~ adb start-server ~~~ * 啟動App ~~~ adb shell am start -n com.tencent.weishi(包名)/com.tencent.oscar.module.main.MainActivity(入口) ~~~ * 清除應用的數據和緩存 ~~~ adb shell pm clear 包名 ~~~ * 坐標點擊 ~~~ adb shell input tap x軸坐標 y軸坐標 ~~~ * 列出所有包名 ~~~ adb shell pm list packages ~~~ * 打印日志 ~~~ adb logcat (ctrl+c終止抓取) ~~~ ### 初體驗 ~~~java package pers.lele; import io.appium.java_client.android.AndroidDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.remote.DesiredCapabilities; import java.net.MalformedURLException; import java.net.URL; public class FirstAppium { public static AndroidDriver<WebElement> androidDriver; public static void main(String[] args) throws MalformedURLException, InterruptedException { //1、創建配置對象 DesiredCapabilities desiredCapabilities = new DesiredCapabilities(); //2、添加配置 //deviceName:測試的設備 desiredCapabilities.setCapability("deviceName","127.0.0.1:62001"); //platformName desiredCapabilities.setCapability("platformName","Android"); //appPackage:測試的App desiredCapabilities.setCapability("appPackage","com.tencent.weishi"); //automationName:uiautomator2解決輸入框輸入不了數據 //desiredCapabilities.setCapability("automationName","uiautomator2"); //appActivity:測試App啟動入口 desiredCapabilities.setCapability("appActivity","com.tencent.oscar.module.splash.SplashActivity"); //3.創建驅動 //第一個參數:Appium通訊地址 //第二個參數:配置對象 androidDriver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"),desiredCapabilities); searchTest(); } public static void searchTest() throws InterruptedException { //等待元素加載完畢 Thread.sleep(1000*10); androidDriver.findElementById("com.tencent.weishi:id/tv_tip_close").click(); //1、找到搜索按鈕并點擊 androidDriver.findElementById("com.tencent.weishi:id/noname_base_search").click(); //2、找到搜索框,輸入路人王 androidDriver.findElementById("com.tencent.weishi:id/search_input").sendKeys("路人王"); //斷言: /* String expected = ""; String result androidDriver.currentActivity(); Assert.assertEquals(expected,result); */ //驅動銷毀 //androidDriver.quit(); } } ~~~ ### Appium元素定位 * **ID**:控件的唯一身份標識,但是可能由于app項目開發人員不嚴謹導致一個頁面有多個相同的id ### 元素等待 * 強制等待 ~~~ Thread.sleep(); ~~~ * 隱式等待 ~~~ androidDriver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS); ~~~ * 顯示等待:針對某個元素設置等待時間 ~~~ WebDriverWait webDriverWait = new WebDriverWait(androidDriver,10); WebElement webElement = webDriverWait.until(new ExpectedCondition<WebElement>() { @NullableDecl @Override public WebElement apply(@NullableDecl WebDriver webDriver) { return androidDriver.findElementById("com.tencent.weishi:id/noname_base_search"); } }); webElement.click(); ~~~ ### 手勢操作-滑動 ~~~ TouchAction touchAction = new TouchAction(androidDriver); PointOption startPoint = PointOption.point(476, 1326); PointOption endPoint = PointOption.point(414, 234); Duration duration = Duration.ofMillis(500); WaitOptions options = WaitOptions.waitOptions(duration); touchAction.press(startPoint).waitAction(options).moveTo(endPoint).release(); touchAction.perform(); ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看