非pom模型
pom模型
1、在公共的模块中写入
caps:
platformName : Android
deviceName : 127.0.0.1:62001
appActivity : com.tencent.mobileqq.activity.LoginActivity
appPackage : com.tencent.mobileqq
2、编写读取yaml
import yaml,os
def yeml_method(path):
with open(path, "r", encoding="utf-8") as file:
data = yaml.load(stream=file, Loader=yaml.FullLoader)
return data
# print(os.path.dirname(__file__))
# print(os.path.dirname(os.path.dirname(__file__)))
# print(os.path.abspath(os.path.dirname(os.path.dirname(__file__))))
# print(os.path.join(os.path.abspath(os.path.dirname(os.path.dirname(__file__))),"testdata/yeml_read"))
print(yeml_method(os.path.join(os.path.abspath(os.path.dirname(os.path.dirname(__file__))),"basepage/casepage.yaml")))
3、导航界面
from appium.webdriver.common.mobileby import MobileBy
from basepage.basepage import BasePages
class DaHangpage(BasePages):
def __init__(self,driver):
BasePages.__init__(self,driver)
def click_login(self):
self.click(MobileBy.ID,"com.tencent.mobileqq:id/btn_login")
4、登录界面
from basepage.basepage import BasePages
from appium.webdriver.common.mobileby import MobileBy
class LoginPage(BasePages):
def send_zh(self,test):
self.input(test,MobileBy.ACCESSIBILITY_ID,"请输入QQ号码或手机或邮箱")
def send_mm(self,test):
self.input(test,MobileBy.ACCESSIBILITY_ID,"密码 安全")
def click_login_button(self):
self.click(MobileBy.ACCESSIBILITY_ID,"登 录")
5、公共方法
class BasePages:
def __init__(self,driver):
self.driver = driver
#元素定位
def locator(self, *loc):
return self.driver.find_element(*loc)
# 清空
def clear(self,*loc):
self.locator(*loc).clear()
# 输入
def input(self,test,*loc):
self.locator(*loc).send_keys(test)
# 点击
def click(self,*loc):
self.locator(*loc).click()
# 滑动(上下左右滑动)
def swipe(self,start_x,start_y,end_x,end_y,duration=0):
#获取屏幕的尺寸
window_size = self.driver.get_window_size()
x = window_size["width"]
y = window_size["height"]
self.driver.swipe(start_x=x*start_x,
start_y=y*start_y,
end_x= x*end_x,
end_y=y*end_y,
duration=duration)
6、编写测试用例
import unittest,os
from appium import webdriver
from baseobject.basedj import DaHangpage
from baseobject.basedl import LoginPage
from testdata.readyaml import yeml_method
import pytest
class TestClass(unittest.TestCase):
@classmethod
def setUpClass(cls) -> None:
data = yeml_method(os.path.join(os.path.abspath(os.path.dirname(os.path.dirname(__file__))),"basepage/casepage.yaml"))
# caps = {}
# caps["platformName"] = "Android"
# caps["deviceName"] = "127.0.0.1:62001"
# caps["appPackage"] = "com.tencent.mobileqq"
# caps["appActivity"] = "com.tencent.mobileqq.activity.LoginActivity"
# caps["platformVersion"] = "5.1.1"
cls.driver = webdriver.Remote("http://localhost:4723/wd/hub", data["caps"])
cls.driver.implicitly_wait(30)
def test_01(self):
dh = DaHangpage(self.driver)
dh.click_login()
@pytest.mark.parametrize("username,password",[("QQ号","QQ密码")])
def test_02(self,username,password):
lg = LoginPage(self.driver)
lg.send_zh("username")
lg.send_mm("password")
lg.click_login_button()
@classmethod
def tearDownClass(cls) -> None:
cls.driver.quit()
if __name__ == '__main__':
unittest.main()