Android Native和Hybrid两种架构采用Appium进行UI自动化

缥帙各舒散,前后互相逾。这篇文章主要讲述Android Native和Hybrid两种架构采用Appium进行UI自动化相关的知识,希望能为你提供帮助。
【Android Native和Hybrid两种架构采用Appium进行UI自动化】一、Native和Hybrid两种架构,整理一张图

Android Native和Hybrid两种架构采用Appium进行UI自动化

文章图片

二、native与web view上下文切换简单代码示例
1 import pytest,time 2 from appium import webdriver 3 from selenium.webdriver.common.by import By 4 from selenium.webdriver.support import expected_conditions 5 from selenium.webdriver.support.wait import WebDriverWait 6 7 class TestDemo(): 8def setup(self): 9caps = {} 10caps["platformName"] = "android" 11caps["deviceName"] = "Android Emulator" 12caps["appPackage"] = "com.xxxxx.android" 13caps["appActivity"] = ".view.WelcomeActivityAlias" 14caps["autoGrantPermissions"] = "true" 15#Chromedriver可通过Chrome浏览器的inspect看到app自带的web view版本号,再去下载相应的driver 16# caps["chromedriverExecutable"] = "Chromedriver的路径" 17 18self.driver = webdriver.Remote("http://localhost:4723/wd/hub", caps) 19self.driver.implicitly_wait(20) 20self.driver.find_element_by_id("com.xueqiu.android:id/tv_agree").click() 21 22def test_webview(self): 23self.driver.find_element_by_xpath("//*[@text=\'男女\']").click() 24#打印出上下文信息 25for i in range(3): 26time.sleep(5) 27print(self.driver.contexts) 28 29self.driver.find_element_by_accessibility_id("开户").click() 30#切换到web view中 31self.driver.switch_to.context(self.driver.contexts[1]) 32#等待元素展示完全再进行点击和输入内容 33WebDriverWait(self.driver,15).until(expected_conditions.visibility_of_element_located((By.ID,"phone-number"))) 34self.driver.find_element_by_id("phone-number").send_keys("13577778881") 35 36 37def teardown(self): 38time.sleep(10) 39self.driver.quit()

 

    推荐阅读