appiumwebview测试

Posted IT界的测试混子

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了appiumwebview测试相关的知识,希望对你有一定的参考价值。

环境准备

手机端浏览器

ios:Safari
安卓:Chrome, Chromium, Browser(安卓自带浏览器)

Pc端

Chrome浏览器

查看手机浏览器版本

查看安卓浏览器包名
adb shell pm list package | findstr browser

C:\\Users\\Administrator>adb shell pm list package | findstr browser
package:com.android.browser

查看浏览器版本
adb shell pm dump 包名 | findstr version

C:\\Users\\Administrator>adb shell pm dump com.android.browser | findstr version

      versionCode=25 minSdk=0 targetSdk=25
      versionName=7.1.2

chromedriver

文档

https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/web/chromedriver.md

https://appium.io/docs/en/writing-running-appium/web/chromedriver/

下载

https://sites.google.com/a/chromium.org/chromedriver/downloads
淘宝镜像
http://npm.taobao.org/mirrors/chromedriver

Chromedriver 版本对应

https://raw.githubusercontent.com/appium/appium-chromedriver/master/config/mapping.json

{
90.0.4430.24: "90.0.4430.24",
89.0.4389.23: "89.0.4389.23",
88.0.4324.96: "88.0.4324.96",
87.0.4280.88: "87.0.4280.88",
87.0.4280.20: "87.0.4280.20",
86.0.4240.22: "86.0.4240.22",
85.0.4183.87: "85.0.4183.87",
85.0.4183.83: "85.0.4183.83",
84.0.4147.30: "84.0.4147.30",
83.0.4103.39: "83.0.4103.39",
81.0.4044.138: "81.0.4044.138",
81.0.4044.69: "81.0.4044.69",
81.0.4044.20: "81.0.4044.20",
80.0.3987.106: "80.0.3987.106",
80.0.3987.16: "80.0.3987.16",
79.0.3945.36: "79.0.3945.36",
79.0.3945.16: "79.0.3945.16",
78.0.3904.105: "78.0.3904.105",
78.0.3904.70: "78.0.3904.70",
78.0.3904.11: "78.0.3904.11",
77.0.3865.40: "77.0.3865.40",
77.0.3865.10: "77.0.3865.10",
76.0.3809.126: "76.0.3809.126",
76.0.3809.68: "76.0.3809.68",
76.0.3809.25: "76.0.3809.25",
76.0.3809.12: "76.0.3809.12",
75.0.3770.140: "75.0.3770.140",
75.0.3770.90: "75.0.3770.90",
75.0.3770.8: "75.0.3770.8",
74.0.3729.6: "74.0.3729",
73.0.3683.68: "70.0.3538",
2.46: "71.0.3578",
2.45: "70.0.0",
2.44: "69.0.3497",
2.43: "69.0.3497",
2.42: "68.0.3440",
2.41: "67.0.3396",
2.40: "66.0.3359",
2.39: "66.0.3359",
2.38: "65.0.3325",
2.37: "64.0.3282",
2.36: "63.0.3239",
2.35: "62.0.3202",
2.34: "61.0.3163",
2.33: "60.0.3112",
2.32: "59.0.3071",
2.31: "58.0.3029",
2.30: "58.0.3029",
2.29: "57.0.2987",
2.28: "55.0.2883",
2.27: "54.0.2840",
2.26: "53.0.2785",
2.25: "53.0.2785",
2.24: "52.0.2743",
2.23: "51.0.2704",
2.22: "49.0.2623",
2.21: "46.0.2490",
2.20: "43.0.2357",
2.19: "43.0.2357",
2.18: "43.0.2357",
2.17: "42.0.2311",
2.16: "42.0.2311",
2.15: "40.0.2214",
2.14: "39.0.2171",
2.13: "38.0.2125",
2.12: "36.0.1985",
2.11: "36.0.1985",
2.10: "33.0.1751",
2.9: "31.0.1650",
2.8: "30.0.1573",
2.7: "30.0.1573",
2.6: "29.0.1545",
2.5: "29.0.1545",
2.4: "29.0.1545",
2.3: "28.0.1500",
2.2: "27.0.1453",
2.1: "27.0.1453",
2.0: "27.0.1453"
}

chrome://inspect/#devices

在这里插入图片描述

测试demo

https://github.com/appium/appium/raw/master/sample-code/apps/ApiDemos-debug.apk

webview介绍

  • Android系统提供能显示网页的系统控件(特殊的view)
  • <Android4.4 WebView底层是WebKit内核
  • >=Android4.4 Google采用chromium作为系统WebView底层支持,API没变,支持html5,Css3,javascript

Capabilities

http://appium.io/docs/en/writing-running-appium/caps/

CapabilityDescriptionValues
automationName自动化引擎Appium (default), or UiAutomator2, Espresso, or UiAutomator1 for Android, or XCUITest or Instruments for iOS, or YouiEngine for application built with You.i Engine
platformName手机系统iOS, Android, or FirefoxOS
platformVersion操作系统版本e.g., 7.1, 4.4
appapp绝对路径/abs/path/to/my.apk or http://myapp.com/app.ipa
browserName手机web浏览器名称。‘Safari’ for iOS and ‘Chrome’, ‘Chromium’, or ‘Browser’ for Android
chromedriverExecutablewebdriver本地绝对路径/abs/path/to/webdriver

案例代码

demo1 webview直接打开浏览器

# pip install appium-python-client
from appium import webdriver
import time
from appium.webdriver.common.mobileby import MobileBy

class TestWebView:
    def setup(self):
        desired_caps = {
            "platformName": "android",
            "platformVersion": "7.1.2",
            "deviceName":"127.0.0.1:62001",
            "browserName":"Browser",
            "chromedriverExecutable":"F:\\\\chromedriver_win32\\\\chromedriver_win32\\\\chromedriver.exe",
            "chromeOptions": {"w3c": False},
        }

        self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps)
        self.driver.implicitly_wait(10)

    def teardown(self):
        time.sleep(3)
        self.driver.quit()


    def test_browser(self):
        self.driver.get("https://www.baidu.com/")
        print(self.driver.contexts) #['NATIVE_APP', 'CHROMIUM']
        self.driver.switch_to.context(self.driver.contexts[-1])
        self.driver.find_element(MobileBy.ID,"index-kw").send_keys("appium webview测试")
        self.driver.find_element(MobileBy.ID,"index-bn").click()

在这里插入图片描述

demo2 ApiDemos-debug.apk 内嵌webview

# pip install appium-python-client
from appium import webdriver
import time
from appium.webdriver.common.mobileby import MobileBy

class TestWebView:
    def setup(self):
        des_caps = {
            "platformName": "android",
            "platformVersion": "7.1.2",
            "appPackage": "io.appium.android.apis",
            "appActivity": "io.appium.android.apis.ApiDemos",
            "noReset": "true",
            "deviceName":"127.0.0.1:62001",
            "chromedriverExecutable":"F:\\\\chromedriver_win32\\\\chromedriver_win32\\\\chromedriver.exe",
            "chromeOptions":{'w3c':False},
        }

        self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", des_caps)
        self.driver.implicitly_wait(10)

    def teardown(self):
        time.sleep(3)
        self.driver.quit()

    def test_browser(self):
        self.driver.find_element_by_accessibility_id("Views").click()
        self.driver.find_element_by_android_uiautomator(
            'new UiScrollable(new UiSelector().scrollable(true).'
            'instance(0)).scrollIntoView(new UiSelector().text("WebView").'
            'instance(0))').click()
        self.driver.switch_to.context(self.driver.contexts[-1])
        self.driver.find_element(MobileBy.ID,"i_am_a_textbox").clear()
        self.driver.find_element(MobileBy.ID,"i_am_a_textbox").send_keys("test 123")
        self.driver.find_element(MobileBy.ID,"i am a link").click()

在这里插入图片描述

踩坑

(1)Matched W3C error code 'invalid argument' to InvalidArgumentError

在这里插入图片描述
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: invalid locator
在这里插入图片描述### 解决方法:
https://github.com/appium/appium/issues/13306
desired_caps['chromeOptions'] = {'w3c': False}

以上是关于appiumwebview测试的主要内容,如果未能解决你的问题,请参考以下文章

;~ 小部分AutoHotkey源代码片段测试模板2019年10月9日.ahk

typescript Angular 2测试片段。代码库https://developers.livechatinc.com/blog/category/programming/angular-2/

如何在片段着色器中进行自定义模板测试

typescript Angular最终版本的Angular 2测试片段。代码库https://developers.livechatinc.com/blog/category/programming

typescript Angular最终版本的Angular 2测试片段。代码库https://developers.livechatinc.com/blog/category/programming

typescript Angular最终版本的Angular 2测试片段。代码库https://developers.livechatinc.com/blog/category/programming