模块五 App控件交互
】
import pytest from appium import webdriver from time import sleep class TestDw(): def setup(self): desire_cap = {} desire_cap['platformName'] = 'android' desire_cap['devicesName'] = '127.0.0.1:7555' desire_cap['appPackage'] = 'com.xueqiu.android' desire_cap['appActivity'] = 'view.WelcomeActivityAlias' desire_cap['dontStopAppOnReset'] = 'true' desire_cap['unicodeKeyBoard'] = 'true' desire_cap['resetKeyBoard'] = 'true' self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub",desire_cap) self.driver.implicitly_wait(10) def teardown(self): self.driver.quit() def test_search(self): print("搜索用例") """ 1.打开雪球app 2.点击搜索输入框 3.想搜索输入框里面输入“阿里巴巴” 4.在搜索输入框里面选择“阿里巴巴”,然后进行点击 5.获取这只相关阿里巴巴的股价,并判断这只股价的价格>200元 """ self.driver.find_element_by_id("com.xueqiu.android:id/tv_search").click() e16 = self.driver.find_element_by_id("com.xueqiu.android:id/search_input_text").send_keys("阿里巴巴") self.driver.find_element_by_xpath("//*[@resource-id='com.xueqiu.android:id/name' and @text='阿里巴巴']").click() cureent_price = float(self.driver.find_element_by_id("com.xueqiu.android:id/current_price").text) assert cureent_price > 200 sleep(3) self.driver.back() def test_attr(self): """ 1.打开雪球应用首页 2.定位首页搜索框 3.判断搜索框是否可用,变查看搜索框name属性值 4.打印搜索框这个元素的左上角坐标和它的宽高 5.向搜索框输入alibaba 6.判断阿里巴巴是否可见 7.如果可见,打印搜索成功点击,如果不可见,打印搜索失败 """ ele = self.driver.find_element_by_id("com.xueqiu.android:id/tv_search") #判断是否可用 search_enabled = ele.is_enabled() #查看name属性值 print(ele.text) #查看左上角坐标值 print(ele.location) #查看宽高 print(ele.size) if search_enabled == True: ele.click() self.driver.find_element_by_id("com.xueqiu.android:id/search_input_text").send_keys("alibaba") ele_alibaba = self.driver.find_element_by_xpath("//*[@resource-id='com.xueqiu.android:id/name' and @text='阿里巴巴']") # ele_alibaba.is_displayed() #get_attribute可以获得元素的几乎所有属性 ele_displayed = ele_alibaba.get_attribute("displayed") if ele_displayed == 'true': print("搜索成功") else: print("搜索失败") if __name__ == '__main__': pytest.main()