Android Native和Hybrid两种架构采用Appium进行UI自动化
一、Native和Hybrid两种架构,整理一张图

二、native与web view上下文切换简单代码示例
import pytest,time
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 TestDemo():
def setup(self):
caps = {}
caps["platformName"] = "Android"
caps["deviceName"] = "Android Emulator"
caps["appPackage"] = "com.xxxxx.android"
caps["appActivity"] = ".view.WelcomeActivityAlias"
caps["autoGrantPermissions"] = "true"
#Chromedriver可通过Chrome浏览器的inspect看到app自带的web view版本号,再去下载相应的driver
# caps["chromedriverExecutable"] = "Chromedriver的路径"
self.driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
self.driver.implicitly_wait(20)
self.driver.find_element_by_id("com.xueqiu.android:id/tv_agree").click()
def test_webview(self):
self.driver.find_element_by_xpath("//*[@text=‘男女‘]").click()
#打印出上下文信息
for i in range(3):
time.sleep(5)
print(self.driver.contexts)
self.driver.find_element_by_accessibility_id("开户").click()
#切换到web view中
self.driver.switch_to.context(self.driver.contexts[1])
#等待元素展示完全再进行点击和输入内容
WebDriverWait(self.driver,15).until(expected_conditions.visibility_of_element_located((By.ID,"phone-number")))
self.driver.find_element_by_id("phone-number").send_keys("13577778881")
def teardown(self):
time.sleep(10)
self.driver.quit() 相关推荐
dangai00 2020-06-06
xjp 2020-05-26
freerocker 2020-05-26
LazySleep 2020-04-19
歆萌 2020-08-03
xjp 2020-08-03
lucialee 2020-07-18
歆萌 2020-07-05
maowenbei 2020-07-04
QCkiss 2020-06-21
无缘公子 2020-06-18
xhpscdx 2020-06-16
freerocker 2020-06-16
ZoctopusD 2020-06-14
lucialee 2020-06-13
freerocker 2020-06-12
xhpscdx 2020-06-12
RocketJ 2020-06-11
chichichi0 2020-06-10