<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智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                [TOC] ## 演示官方demo 作為一個新手,剛搭建好appium環境,讓我們先來演示一下官方demo,讓我們體驗一下運行一個appium自動化的過程吧。 ### step1:啟動安卓模擬器 本書使用“雷電模擬器”,啟動后如下: ![](https://box.kancloud.cn/f8ed974e76e81e45ef02e1c156f96db8_486x444.jpg) 啟動后,在命令行中檢查adb能否連接上該設備。 ### step2: 啟動Appium Desktop 啟動后,如下: ![](https://box.kancloud.cn/c1a510070b76e793271c0530e53dd077_923x181.jpg) ### step3:準備自動化腳本與待測APK test_android_contacts.py : ```python #!/usr/bin/env python # -*- coding: utf-8 -*- import os import pytest from appium import webdriver # Returns abs path relative to this file and not cwd PATH = lambda p: os.path.abspath( os.path.join(os.path.dirname(__file__), p) ) APPIUM_LOCAL_HOST_URL = 'http://localhost:4723/wd/hub' PLATFORM_VERSION = '5.1.1' class TestWebViewAndroid(): @pytest.fixture(scope="function") def driver(self, request): desired_caps = { 'appPackage': 'com.example.android.contactmanager', 'appActivity': '.ContactManager', 'platformName': 'Android', 'platformVersion': PLATFORM_VERSION, 'deviceName': 'Android Emulator', 'app': PATH('ContactManager.apk') } driver = webdriver.Remote(APPIUM_LOCAL_HOST_URL, desired_caps) def fin(): driver.quit() request.addfinalizer(fin) return driver # provide the fixture value def test_add_contacts(self, driver): el = driver.find_element_by_accessibility_id("Add Contact") el.click() textfields = driver.find_elements_by_class_name("android.widget.EditText") textfields[0].send_keys("Appium User") textfields[2].send_keys("someone@appium.io") assert 'Appium User' == textfields[0].text assert 'someone@appium.io' == textfields[2].text driver.find_element_by_accessibility_id("Save").click() # for some reason "save" breaks things #alert = driver.switch_to.alert # no way to handle alerts in Android driver.find_element_by_android_uiautomator('new UiSelector().clickable(true)').click() driver.press_keycode(3) if __name__ == '__main__': pytest.main() ``` 本實例,使用官方的代碼與apk,點擊下載:[ContactManager.apk](https://github.com/appium-boneyard/sample-code/blob/master/sample-code/apps/ContactManager/ContactManager.apk) 將apk放到與代碼相同的目錄下 ### step4:運行測試代碼 ![](https://box.kancloud.cn/7f36c794304980f48c23f6b76c569f4d_1193x971.gif) ## 分析Demo代碼 1. 連接Appium服務器 在本實例中,appium server 連接獲得WebDriver實例作為每個用例的初始化條件,放在pytest的fixture中。 代碼如下截圖 ![](https://box.kancloud.cn/48b7b235dbdb0bad7005bae5a1098bfe_676x338.jpg) 在fixture中,最關鍵的一句代碼是初始化,獲得WebDriver實例 `python driver = webdriver.Remote(APPIUM_LOCAL_HOST_URL, desired_caps)` 初始化時,需要指定**command_executor**,默認是“http://127.0.0.1:4444/wd/hub", 這里我們必須指定我們的4723端口,修改為“http://localhost:4723/wd/hub'” 同時,我們還需要通過**desired_capabilities**參數, 設置appium server啟動時的參數,啟動session的時候是必須提供的。它告訴appium server 本次測試是啟動瀏覽器還是啟動移動設備,是啟動andorid還是啟動ios,啟動android時,app的package是什么,app的activity是什么等。 >分析這里的fixture代碼之前,需要先掌握好pytest測試框架。這里 `request.addfinalizer(fin)` 表示用例teardown銷毀操作。`return dirver` 表示用例setup操作的返回值是一個WebDriver驅動實例。 2. 元素定位 **根據 text 定位** `el = driver.find_element_by_accessibility_id("Add Contact")` ![](https://box.kancloud.cn/f04d490fd7167bcc9624a55e06140396_1050x725.jpg) 3. 元素操作 **點擊元素** `el.click()` ## 分析Appium的加載流程 **通過分析Appium Server中的日志,分析Appium的加載流程** 1.創建會話Session,通過**desired_capabilities**設置appium server啟動時的參數。 ``` [MJSONWP] Calling AppiumDriver.createSession() with args: [{"appPackage":"com.example.android.contactmanager","appActivity":".ContactManager","platformName":"Android","platformVersion":"5.1.1","deviceName":"Android Emulator","app":"E:\\workspace\\python_learn\\ContactManager.apk"},null,{"firstMatch":[{}],"alwaysMatch":{"appium:appPackage":"com.example.android.contactmanager","appium:appActivity":".ContactManager","platformName":"Android","appium:platformVersion":"5.1.1","appium:deviceName":"Android Emulator","appium:app":"E:\\workspace\\python_learn\\ContactManager.apk"}}] [BaseDriver] Event 'newSessionRequested' logged at 1537521688377 (17:21:28 GMT+0800 (中國標準時間)) [Appium] Creating new AndroidDriver (v2.7.0) session [Appium] Capabilities: [Appium] platformName: Android [Appium] appPackage: com.example.android.contactmanager [Appium] appActivity: .ContactManager [Appium] platformVersion: 5.1.1 [Appium] deviceName: Android Emulator [Appium] app: E:\workspace\python_learn\ContactManager.apk [BaseDriver] W3C capabilities {"alwaysMatch":{"platformNa... and MJSONWP desired capabilities [object Object] were provided [BaseDriver] Creating session with W3C capabilities: {"alwaysMatch":{"platformNa... [BaseDriver] Session created with session id: 6ec4b5b7-b79c-426c-87ce-017472a07294 ``` 2. 檢查android adb環境,調用android adb 完成基本的系統操作 3. 向android上部署bootstrap.jar包并啟動 4. Forward android的端口到pc機器上 5. pc上監聽端口,接受請求,使用webdriver協議分析命令并通過forward的端口發送給bootstrap.jar 6. bootstrap.jar 接受命令并把命令發給uiautomator或者插樁體系。 **更多內容,請留意后面章節~**
                  <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>

                              哎呀哎呀视频在线观看