Page Object
Page Object是Selenium自动化测试项目开发实践的最佳设计模式之一,通过对界面元素的封装减少冗余代码,同时在后期维护中,若元素定位发生变化,只需要调整页面元素封装的代码,提高测试用例的可维护性。
一、测试环境
Win 10
java version "1.8.0_181"
Appium v1.14.1(不能低于1.6.3)
selenium:3.141.0
测试设备:Android 5.1.1
Python:3.6
测试App:考研帮Android app V3.1.0
二、测试场景
1 封装登录类
三、参考代码
import logging
from appium_advance.page_object.common_fun import Common
from appium_advance.page_object.desired_caps import appium_desired
from selenium.webdriver.common.by import By
class LoggingView(Common):
username_type = (By.ID,'com.tal.kaoyan:id/login_email_edittext')
password_type = (By.ID,'com.tal.kaoyan:id/login_password_edittext')
LoggingBtn = (By.ID,'com.tal.kaoyan:id/login_login_btn')
def login_action(self,username,password):
self.check_cancelBtoon()
self.check_skipBtn()
logging.info('======开始登录=========')
logging.info('username is:%s' %username)
self.driver.find_element(*self.username_type).send_keys(username)
logging.info('password is:%s' %password)
self.driver.find_element(*self.password_type).send_keys(password)
logging.info('click logingBtn')
self.driver.find_element(*self.LoggingBtn).click()
logging.info('login finished登录完成')
if __name__ == '__main__':
driver = appium_desired()
l1 = LoggingView(driver)
l1.login_action('自己的用户名','自己的密码')