目录
前言:
本文为在霍格沃兹测试开发学社中学习到的一些技术写出来分享给大家,希望有志同道合的小伙伴可以一起交流技术,一起进步~ 😘
1. 产品分析
-
被测应用:雪球 App
-
雪球 App 介绍
- 雪球 app 是一款免费版,非常实用的股票平台,提供热点资讯内容和实时行情,提供了证券交流交易,公募、理财服务
- 雪球 app 功能包括搜索股票,查看行情,交易,浏览热门文章,发帖,登录,注册,等功能
2. 实战练习思路
3. 用例设计
搜索场景:
- 打开【雪球】应用首页
- 点击搜索框,进入搜索页面
- 向搜索输入框中输入【alibaba】
- 点击搜索结果中的【阿里巴巴】
- 切换到 tab 的【股票】
- 找到 股票【阿里巴巴】的股票价格 price
- 判断 price 在 110 上下 10%浮动
4.构造PO模型,编写测试用例
4.1 模型框架
PO模型分为三层:
- 具体业务层
- 公共业务层
- 和业务无关的公共方法层
4.2 目录结构
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
4.3 搭建框架
先把框架搭好,写好测试用例,填充业务逻辑,保证用例可以正常跑通。
- base
-
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)
- page
- main_page.py
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)
- search_page.py
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)
- search_result_page.py
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)
- cases
- test_xueqiu.py
#使用harmcrest 要导入全部内容,要不然有一些函数会报错
from hamcrest import *
from appiumpo.base.xueqiu_app import XueQiuApp
class TestXueQiu:
def setup(self):
"""启动雪球App"""
self.xueqiu=XueQiuApp()
self.main=self.xueqiu.start().goto_main()
def teardown(self):
"""关闭雪球App"""
pass
def test_search(self):
search_key