Android webview (纯web页面)自动化测试Demo

个人总结:

  • desire_capabilitiy中不再需要配置“appPackage”、“appActivity”参数项,增加"browserName": "Browser"。如果chromedriver没有放到appium的路径下,则还需要配置"chromedriverExecutable"参数项,如下:
    "chromedriverExecutable": "D:/BrowserDriver/chromedriver_win32_2.39/chromedriver.exe"
  • 其他的元素定位跟PC端的web元素一样。
  • webdriver.find_element使用的时appium库的。

 

Demo:

  • #!/usr/bin/python3.8.9
    # -*- coding: utf-8 -*-
    
    # @Author  : Tina Yu
    # @Time    : 2021-12-12 17:16
    
    from time import sleep
    
    from appium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions
    from selenium.webdriver.support.wait import WebDriverWait
    
    
    class TestAppWeb:
        def setup(self):
            desire_cap = {
                "platformName": "android",
                "platformVersion": "6.0",
                "deviceName": "127.0.0.1:7555",
                "browserName": "Browser",
                # "noReset": True,
                # 如果将chromedriver放到了appium的chromedriver路径下,则不需要再指定
                "chromedriverExecutable": "D:/BrowserDriver/chromedriver_win32_2.39/chromedriver.exe",
            }
            self.driver = webdriver.Remote("http://localhost:4723/wd/hub", desire_cap)
            self.driver.implicitly_wait(10)
    
        def teardown(self):
            self.driver.quit()
    
        def test_app_web(self):
            """
            1、打开百度页面
            2、点击搜索框
            3、输入appium关键字
            4、进行搜索
            :return:
            """
            self.driver.get("http://m.baidu.com")
            self.driver.find_element(By.XPATH, "//*[@for='index-kw']").click()
            self.driver.find_element(By.ID, "index-kw").send_keys("appium")
            search_button_locator = (By.ID, "index-bn")
            WebDriverWait(self.driver, 10, 1).until(expected_conditions.element_to_be_clickable(search_button_locator))
            self.driver.find_element(*search_button_locator).click()
            sleep(3)
    
posted @ 2021-12-14 13:47  于慧妃  阅读(320)  评论(0编辑  收藏  举报