混合应用中包含 Web 视图的应用,在 Appium 介绍及环境安装 中介绍了appium支持WebView测试,本文将分享Android 混合页面的测试方法。
被测浏览器:
iOS:Safari
Android:Chrome,Chromium,Browser (自带浏览器)
adb shell pm list package | grep webview
adb shell pm dump com.android.browser | grep version
adb shell pm dump com.android.chrome | grep version
adb shell pm dump com.android.webview | grep version
查看手机browser和chrome版本
C:\Users\10287>adb shell pm list packages|findstr browser
package:com.android.browser
C:\Users\10287>adb shell pm dump com.android.browser | findstr version
versionCode=22 targetSdk=22
versionName=5.1.1-500200323
C:\Users\10287>adb shell pm dump com.android.chrome | findstr version
versionCode=398713200 targetSdk=29
versionName=80.0.3987.132
enabled=true targetSdkVersion=29 versionCode=398713200
在手机上设置中查看 Android System WebView应用版本
desirecapability
1、连接手机/模拟器
手机打开google浏览器,并进入百度网页:https://m.baidu.com
2、Chrome浏览器输入地址: chrome://inspect
可以看到电脑连接的设备名以及打开的手机浏览器
点击inspect
这样就可以定位到浏览器元素。
文档:https://developers.google.com/web/tools/chrome-devtools/remote-debugging/webviews?hl=zh-cn
测试步骤:
下载ApiDemos-debug.apk
from appium import webdriver
from appium.webdriver.common.mobileby import MobileBy
class TestBrowser():
def setup(self):
desired_caps = {
‘platformName‘: ‘android‘,
‘platformVersion‘: ‘10‘,
‘appPackage‘: ‘io.appium.android.apis‘,
‘appActivity‘: ‘io.appium.android.apis.ApiDemos‘,
‘deviceName‘: ‘CUYDU19626004019‘,
‘noReset‘: ‘true‘,
‘chromedriverExecutable‘: ‘D:/testing_tools/chromedriver85/chromedriver.exe‘
}
self.driver = webdriver.Remote(‘http://127.0.0.1:4723/wd/hub‘, desired_caps)
self.driver.implicitly_wait(5)
def teardown(self):
self.driver.quit()
def test_webview(self):
self.driver.find_element_by_accessibility_id("Views").click()
webview ="WebView"
print(self.driver.contexts)
self.driver.find_element_by_android_uiautomator(‘new UiScrollable(new UiSelector().‘
‘scrollable(true).instance(0)).‘
f‘scrollIntoView(new UiSelector().text("{webview}")‘
‘.instance(0));‘).click()
print(self.driver.contexts)
self.driver.switch_to.context(self.driver.contexts[1])
print(self.driver.current_context)
self.driver.find_element(MobileBy.ID, ‘i am a link‘).click()
文章标题:Android WebView测试
本文作者:hiyo
本文链接:https://www.cnblogs.com/hiyong/p/14163722.html
欢迎关注公众号:「测试开发小记」及时接收最新技术文章!
原文:https://www.cnblogs.com/hiyong/p/14163722.html