美文网首页
Appium自动化测试框架——POM模式

Appium自动化测试框架——POM模式

作者: 远航天下 | 来源:发表于2018-07-13 11:08 被阅读0次

来看几个脚本分离具体实施

先看截图

POM模式说明.png
PO文件夹就是POM核心实施方法,也就是对每个页面元素进行元素及方法拆分整合;
TestCase文件夹对页面进行测试,当然你也也可以在这里面写上自己的case用例
我们看几个元素分离的例子:
base_page.py
author = 'damao'

from appium import webdriver

class Base(object):

    def __init__(self):
        pass

    """控制启动APP"""
    def remote_app(self):
        self.devices_env = {
            "platformName": "Android",
            "deviceName": "RKKDU17C12006192",
            "platformVersion": "8.0",
            "appPackage": "com.szyh.ui",  # apk包名
            "appActivity": "com.szyh.ui.login.WelcomeActivity",  # app的launchable-activity
            "unicodeKeyboard": True,
            "resetKeyboard": True
        }
        self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", self.devices_env)
login_page.py
author = 'damao'

from Appium_JDPE_Test.PO import base_page


class LoginPage(base_page.Base):
    """登陆页面元素维护"""
    user_name = "com.szyh.ui:id/userid" # 登陆页面用户名输入框
    pass_word =  "com.szyh.ui:id/pwd" # 登陆页面密码输入框
    login_btn = "com.szyh.ui:id/login" # 登陆页面”登陆“按钮
    full_screen =  "com.szyh.ui:id/cpi_welcome" # 启动页面”全屏显示“按钮
    enter_app =  "com.szyh.ui:id/btn_welcome_last" # 启动页面
    
    def set_username(self, username):
        name = self.driver.find_element_by_id(self.user_name)
        name.send_keys(username)  # 输入用户名

    def set_password(self, password):
        pwd = self.driver.find_element_by_id(self.pass_word)
        pwd.send_keys(password)  # 输入密码

    def click_login(self):
        loginbtn = self.driver.find_element_by_id(self.login_btn)
        loginbtn.click()  # 单击登录

    def set_fullscreen(self):
        fullscreen = self.driver.find_element_by_id(self.full_screen)
        fullscreen.click()  #  点击”全屏显示按钮“

    def to_enter_app(self):
        enterapp = self.driver.find_element_by_id(self.enter_app)
        enterapp.click() # 点击进入按钮进入APP
regist_user_page.py
author = 'damao'

from Appium_JDPE_Test.PO import base_page
import subprocess

"""点击首页用户注册按钮,进入用户注册页面"""

class RegistPage(base_page.Base):
    """注册页面元素维护"""
    regist_btu = "com.szyh.ui:id/textView2"  # 首页“没有账号?注册”按钮
    nickname = "com.szyh.ui:id/nicheng" # 昵称
    phone = "com.szyh.ui:id/phoneNo" # 手机号
    login_password = "com.szyh.ui:id/pwd"  # 登录密码
    confirm_password = "com.szyh.ui:id/repwd" # 确认密码
    check_out_btu = "com.szyh.ui:id/ck_agreen" # 勾选注册协议
    regist = "com.szyh.ui:id/registry_btn" # 注册按钮
    massage_box = "com.szyh.ui:id/check_code" # 短信验证码输入框
    massage_sub_btu = "com.szyh.ui:id/submit_btn" # 提交按钮

    def click_regist_btu(self):    # 点击首页“没有账号?注册”按钮
        self.driver.find_element_by_id(self.regist_btu).click()

    def set_nickname(self,nickname):  # 输入昵称
        self.driver.find_element_by_id(self.nickname).send_keys(nickname)
        # x = subprocess.check_output('adb devices', shell=True).split()[1][:-7]
        # self.driver.find_element_by_id(self.nickname).click()
        # subprocess.Popen('adb -s %s shell input text %s' % (x, nickname), shell=True)

    def set_phone(self,phone_nub): # 输入电话号码
        self.driver.find_element_by_id(self.phone).send_keys(phone_nub)

    def set_login_password(self,login_passwd):  # 输入登录密码
        self.driver.find_element_by_id(self.login_password).send_keys(login_passwd)

    def set_confirm_password(self,confirm_passwd):  # 确认输入登录密码
        self.driver.find_element_by_id(self.confirm_password).send_keys(confirm_passwd)

    def click_check_btu(self): # 勾选注册用户协议
        self.driver.find_element_by_id(self.check_out_btu).click()

    def click_regist(self): # 点击“注册”按钮
        self.driver.find_element_by_id(self.regist).click()

    def set_massage(self,msg): # 输入验证码
        self.driver.find_element_by_id(self.massage_box).send_keys(msg)

    def click_submsg_btu(self): # 点击验证码提交按钮
        self.driver.find_element_by_id(self.massage_sub_btu).click()
在命令这个py文件的时候,最好使用当前页面的名字来命名,这样一样就能看出来,
这些技巧和方法还是需要结合实际测试例子来熟悉和领悟

相关文章

网友评论

      本文标题:Appium自动化测试框架——POM模式

      本文链接:https://www.haomeiwen.com/subject/grcjpftx.html