<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>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                ## 自動化混合應用 Appium 的核心理念之一是,你不應該為了測試而改變被測的應用程序。在這種理念中,可以使用像 Selenium 測試 Web 應用的方式去測試混合應用。Appium 需要知道你是想自動化應用的原生部分還是 Web 視圖,這在技術上有一點復雜。但值得慶幸的是,我們可以繼續使用 Selenium WebDriver 做所有的事。 一旦測試處于 Web 視圖上下文之中,所有 [Selenium](http://www.seleniumhq.org/) [WebDriver API](http://www.seleniumhq.org/docs/03_webdriver.jsp) 指令集都是可用的。 ### 進入 Web 視圖上下文(context) 在你的 Appium 測試中,以下是與 Web 視圖通信所必須的幾個步驟: 1. 導航到你的應用程序中的 Web 視圖的部分 1. [取得當前可用的上下文](../commands/context/get-contexts.md) * 這將返回一個包含我們可以訪問的上下文的列表,例如 `'NATIVE_APP'` 或 `'WEBVIEW_1'` 1. 使用想要訪問的上下文的 id [設置上下文](../commands/context/set-context.md) * 這會使你的 Appium 會話進入一個模式, 處于該模式時所有命令被解釋為用來自動化 Web 視圖,而不是應用程序的原生部分。 例如,如果你運行 `getElementByTagName`,它將操作 Web 視圖中的 DOM,而不是返回原生元素。 當然,某些 WebDriver 方法只在一個或另一個上下文中有效,所以在錯誤的上下文中執行時你會收到一個報錯信息。 1. 想要停止對 Web 視圖的上下文中自動化,并返回到應用程序的原生部分,簡單的 [設置上下文](../commands/context/set-context.md) 即可。將上下文賦值為原生上下文的 id(通常是 `'NATIVE_APP'`)便可離開 Web 上下文,重新使用原生指令。 ### 在會話(session)開啟時自動進入 Web 視圖上下文(context) 如果你的應用程序在 web 視圖中開始,并且你不想在自動化應用程序的原生部分后,再進入 Web 視圖,你可以通過設置「[desired capability](../writing-running-appium/caps.md)」 中的 `autoWebview` 為 `true` 使得 Appium 在會話初始化時自動進入 Web 視圖上下文。 ### 示例 ```javascript // javascript // 假定我們已經為這個應用程序初始化了 `driver` 對象 driver .contexts().then(function (contexts) { // get list of available views. Returns array: ["NATIVE_APP","WEBVIEW_1"] return driver.context(contexts[1]); // choose the webview context }) // 執行一些 web 測試 .elementsByCss('.green_button').click() .context('NATIVE_APP') // leave webview context // 如果你想,可以在這做一些原生操作 .quit() // stop webdrivage ``` ```java // java // 假定我們設置了 capabilities driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); Set<String> contextNames = driver.getContextHandles(); for (String contextName : contextNames) { System.out.println(contextName); //prints out something like NATIVE_APP \n WEBVIEW_1 } driver.context(contextNames.toArray()[1]); // set context to WEBVIEW_1 // 執行一些 web 測試 String myText = driver.findElement(By.cssSelector(".green_button")).click(); driver.context("NATIVE_APP"); // 如果你想,可以在這做一些原生操作 driver.quit(); ``` ```ruby # ruby_lib_core # 假定我們設置了 capabilities @driver = Appium::Core.for(url: SERVER_URL, desired_capabilities: capabilities).start_driver # ruby_lib # opts = { caps: capabilities, appium_lib: { custom_url: SERVER_URL }} # @driver = Appium::Driver.new(opts, true).start_driver # 我切換到了最后一個上下文,因為在我們的示例中它總是 webview,在其他情況下,您可能需要明確指定一個上下文 # 在運行 @driver.contexts 期間,查看 appium 日志確定想要的上下文,并找到關聯的 ID # 使用 @driver.switch_to.context("WEBVIEW_6") 切換到想要的上下文 Given(/^I switch to webview$/) do webview = @driver.available_contexts.last @driver.switch_to.context(webview) end Given(/^I switch out of webview$/) do @driver.switch_to.context(@driver.contexts.first) end # 現在使用 CSS 選擇器在你的 webview 中選擇一個元素 And(/^I click a webview button $/) do @driver.find_element(:css, ".green_button").click end ``` ```python # python # 假定我們已經為這個應用程序初始化了 `driver` 對象 # 切換到 webview webview = driver.contexts.last driver.switch_to.context(webview) # 執行一些 web 測試 driver.find_element(:css, ".green_button").click # 切換回原生視圖 driver.switch_to.context(driver.contexts.first) # 如果你想,可以在這做一些原生操作 driver.quit() ``` ```php // php // 假定我們已經在這個AppiumTestCase中初始化了 `driver` 對象 public function testThings() { $expected_contexts = array( 0 => 'NATIVE_APP', 1 => 'WEBVIEW_1' ); $contexts = $this->contexts(); $this->assertEquals($expected_contexts, $contexts); $this->context($contexts[1]); $context = $this->context(); $this->assertEquals('WEBVIEW_1', $context); // 做一些關于 web 的事 $this->context('NATIVE_APP'); // 做一些關于原生的事 } ``` ### 自動化 Android 的混合應用 Appium [通過 Chromedriver 內建的混合應用支持](../writing-running-appium/web/chromedriver.md) ,使得任何 Chrome 支持的 Android Web 視圖都可以自動化。 不幸的是,你必須在構建應用程序時做額外的一步。正如 Android [遠程調試文檔](https://developers.google.com/web/tools/chrome-devtools/remote-debugging/webviews) 中所述,必須設置 [android.webkit.WebView](http://developer.android.com/reference/android/webkit/WebView.html) 元素的 [setWebContentsDebuggingEnabled](http://developer.android.com/reference/android/webkit/WebView.html#setWebContentsDebuggingEnabled(boolean)) 屬性設置為 `true`。 一旦你設置了 [desired capabilities](../writing-running-appium/caps.md) 并開啟了 Appium 會話,請遵循上面的通用說明。 ### 自動化 iOS 的混合應用 Appium 使用自定義的遠程調試器建立連接去與 web 視圖交互。當 Appium 和模擬器和在同一臺機器且對模擬器執行時,此鏈接直接建立到模擬器。Appium 可以自動化 [WkWebView](https://developer.apple.com/documentation/webkit/wkwebview) 和 [UIWebView](https://developer.apple.com/documentation/uikit/uiwebview) 元素。不幸的是,目前還不能處理 [SafariViewController](https://developer.apple.com/documentation/safariservices/sfsafariviewcontroller) 元素。 一旦你設置了 [desired capabilities](../writing-running-appium/caps.md) 并開啟了 Appium 會話,請遵循上面的通用說明。 #### 對真實的 iOS 設備執行 當對真實的 iOS 設備執行時,Appium 不能直接訪問 web 試圖。所以必須通過 USB 線纜連接設備。從版本 1.15 開始,Appium 可以通過 [appium-ios-device](https://github.com/appium/appium-ios-device) 通過本機建立連接。 只有版本低于 1.15 的Appium才需要使用 [ios-webkit-debugger-proxy](https://github.com/google/ios-webkit-debug-proxy) 建立連接。 關于如何安裝并運行 `ios-webkit-debugger-proxy` 的教學,請查看 [iOS webkit 調試代理](../writing-running-appium/web/ios-webkit-debug-proxy.md) 文檔 現在你可以開啟 Appium 測試會話,并遵循上面的通用說明。 本文由 [CrazyForPoor](https://github.com/CrazyForPoor) 翻譯。
                  <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>

                              哎呀哎呀视频在线观看