前言:
本文为在霍格沃兹测试开发学社中学习到的一些技术写出来分享给大家,希望有志同道合的小伙伴可以一起交流技术,一起进步~ 😘
被测应用:雪球 App
雪球 App 介绍

搜索场景:
PO模型分为三层:

base/
base_page.py #基类
xueqiu_app.py # app启动相关
page/
main_page.py #PO-主页
search_page.py #PO-搜索页
search_result_page.py #PO-搜索结果也
cases/
test_xueqiu.py
先把框架搭好,写好测试用例,填充业务逻辑,保证用例可以正常跑通。
base_page.py(实现暂时为空)
xueqiu_app.py
from appium import webdriver
from appiumpo.page.main_page import MainPage
class XueQiuApp:
""" 放置雪球APP相关的操作:start 启动;restart 重启;stop 停止"""
def start(self):
desired_caps = {
}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '6.0'
desired_caps['deviceName'] = '127.0.0.1:7555'
desired_caps['appPackage'] = 'com.xueqiu.android'
desired_caps['appActivity'] = '.view.WelcomeActivityAlias'
desired_caps['noReset'] = 'true'
self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
self.driver.implicitly_wait(10)
return self
def restart(self):
pass
def stop(self):
pass
def goto_main(self):
#完成切换到到PO的功能
return MainPage(self.driver)
from appium.webdriver.common.appiumby import AppiumBy
from appium.webdriver.webdriver import WebDriver
from appiumpo.page.search_page import SearchPage
class MainPage:
def __init__(self,driver:WebDriver):
self.driver=driver
def click_search(self):
#点击搜索框
self.driver.find_element(AppiumBy.ID,"com.xueqiu.android:id/tv_search").click()
return SearchPage(self.driver)
from appium.webdriver.common.appiumby import AppiumBy
from appium.webdriver.webdriver import WebDriver
from appiumpo.page.search_result_page import SearchResultPage
class SearchPage:
def __init__(self, driver:WebDriver):
self.driver = driver
def input_searchcontent(self,searchkeys):
# 输入搜索内容
self.driver.find_element(AppiumBy.ID,"com.xueqiu.android:id/search_input_text").send_keys(searchkeys)
return self
def click_searchresult(self,text):
self.driver.find_element(AppiumBy.XPATH, f"//*[@text='{
text}']").click()
return SearchResultPage(self.driver)
from appium.webdriver.common.appiumby import AppiumBy
from appium.webdriver.webdriver import WebDriver
class SearchResultPage:
def __init__(self, driver: WebDriver):
self.driver = driver
def goto_stock_tab(self):
#点击股票
self.driver.find_element(AppiumBy.XPATH,"//*[@text='股票']").click()
return self
def get_price(self):
#找到对应股票的价格,返回股票价格
current_price=self.driver.find_element(AppiumBy.XPATH,"//*[@text='BABA']/../../..//*[@resource-id='com.xueqiu.android:id/current_price']").text
return float(current_price)
#使用harmcrest 要导入全部内容,要不然有一些函数会报错
from hamcrest import *
from appiumpo.base.xueqiu_app import XueQiuApp
class TestXueQiu:
def setup(self):