zoukankan      html  css  js  c++  java
  • Appium+unittest+PageObject实例

    实例中设计到的文件如下红色标出

    [loggers]
    keys=root,infoLogger
    
    [logger_root]
    level=DEBUG
    handlers=consoleHandler,fileHandler
    
    [logger_infoLogger]
    handlers=consoleHandler,fileHandler
    qualname=infoLogger
    propagate=0
    
    [handlers]
    keys=consoleHandler,fileHandler
    
    [handler_consoleHandler]
    class=StreamHandler
    level=INFO
    formatter=form02
    args=(sys.stdout,)
    
    [handler_fileHandler]
    class=FileHandler
    level=INFO
    formatter=form01
    args=('runlog_conf.log', 'a')
    
    [formatters]
    keys=form01,form02
    
    [formatter_form01]
    format=%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s
    
    [formatter_form02]
    format=%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s
    View Code
    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    # @Time : 2019-07-04 17:17
    # @File : baseView.py
    
    
    class BaseView(object):
        def __init__(self,driver):
            self.driver=driver
        def find_element(self,*loc):
            return self.driver.find_element(*loc)
    View Code
    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    # @Time : 2019-07-04 17:22
    # @Author : zhouyang
    # @File : commom_fun.py
    
    from appium_advance.page_object.desired_caps import appium_desired
    from appium_advance.page_object.baseView import BaseView
    from selenium.common.exceptions import NoSuchElementException
    import logging
    from selenium.webdriver.common.by import By
    
    class Commom(BaseView):
        cancelBtn=(By.ID,'android:id/button2')
        skipBtn=(By.ID,'com.tal.kaoyan:id/tv_skip')
    
        def check_cancleBtn(self):
            logging.info('===========check cancleBtn==========')
            try:
                cancelBtn = self.driver.find_element(*self.cancelBtn)
            except NoSuchElementException:
                logging.info('no cancelBtn')
            else:
                cancelBtn.click()
    
        def check_skipBtn(self):
            logging.info('===========check cancelBtn===========')
            try:
                skipBtn = self.driver.find_element(*self.skipBtn)
            except NoSuchElementException:
                logging.info('no cancelBtn')
            else:
                skipBtn.click()
    
    if __name__ == '__main__':
        driver=appium_desired()
        com=Commom(driver)
        com.check_cancleBtn()
        com.check_skipBtn()
    View Code
    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    # @Time : 2019-07-03 11:05
    # @Author : zhouyang
    # @File : capability_yaml.py
    '''
    从desired_caps.yaml文件中获取capability数据,登录考研帮app,把日志保存在文件中
    '''
    from selenium import webdriver
    import yaml
    import logging
    import logging.config
    
    
    file=open('../yaml/desired_caps.yaml','r')
    data=yaml.load(file)
    
    CON_LOG='../log/log.conf'
    logging.config.fileConfig(CON_LOG)
    logging=logging.getLogger()
    
    def appium_desired():
        desired_caps = {}
        desired_caps['platformName'] = data['platformName']
        desired_caps['platformVerion'] = data['platformVersion']
        desired_caps['deviceName'] = data['deviceName']
        desired_caps['app'] = data['app']
        desired_caps['noReset'] = data['noReset']
        desired_caps['appPackage'] = data['appPackage']
        desired_caps['appActivity'] = data['appActivity']
        desired_caps['unicodeKeyboard'] = data['unicodeKeyboard']
        desired_caps['resetKeyboard'] = data['resetKeyboard']
    
        logging.info('start info...')
    
        driver = webdriver.Remote('http://' + str(data['ip']) + ':' + str(data['port']) + '/wd/hub', desired_caps)
        driver.implicitly_wait(8)
        return driver
    
    if __name__ == '__main__':
        appium_desired()
    View Code
    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    # @Time : 2019-07-05 11:42
    # @Author : zhouyang
    # @File : loginView.py
    
    from appium_advance.page_object.desired_caps import appium_desired
    from appium_advance.page_object.commom_fun import Commom
    import logging
    from selenium.webdriver.common.by import By
    
    class LoginView(Commom):
        username_type=(By.ID,'com.tal.kaoyan:id/login_email_edittext')
        password_type=(By.ID,'com.tal.kaoyan:id/login_password_edittext')
        submit_type=(By.ID,'com.tal.kaoyan:id/login_login_btn')
    
        def login_action(self,username,password):
            self.check_cancleBtn()
            self.check_skipBtn()
            logging.info('=================login===================')
            logging.info('input username:%s'%username)
            self.driver.find_element(*self.username_type).send_keys(username)
    
            logging.info('input password:%s' %password)
            self.driver.find_element(*self.password_type).send_keys(password)
    
            logging.info('click loginBtn')
            self.driver.find_element(*self.submit_type).click()
            logging.info('===============login finish==============')
    
    if __name__ == '__main__':
        driver=appium_desired()
        l=LoginView(driver)
        l.login_action('自学网2018','zxw2018')
    
            
    View Code
    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    # @Time : 2019-07-05 11:42
    # @Author : zhouyang
    # @File : loginView.py
    
    from appium_advance.page_object.desired_caps import appium_desired
    from appium_advance.page_object.commom_fun import Commom
    import logging
    from selenium.webdriver.common.by import By
    
    class LoginView(Commom):
        username_type=(By.ID,'com.tal.kaoyan:id/login_email_edittext')
        password_type=(By.ID,'com.tal.kaoyan:id/login_password_edittext')
        submit_type=(By.ID,'com.tal.kaoyan:id/login_login_btn')
    
        def login_action(self,username,password):
            self.check_cancleBtn()
            self.check_skipBtn()
            logging.info('=================login===================')
            logging.info('input username:%s'%username)
            self.driver.find_element(*self.username_type).send_keys(username)
    
            logging.info('input password:%s' %password)
            self.driver.find_element(*self.password_type).send_keys(password)
    
            logging.info('click loginBtn')
            self.driver.find_element(*self.submit_type).click()
            logging.info('===============login finish==============')
    
    if __name__ == '__main__':
        driver=appium_desired()
        l=LoginView(driver)
        l.login_action('自学网2018','zxw2018')
    
            
    View Code
    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    # @Time : 2019-07-05 16:18
    # @Author : zhouyang
    # @File : myunit.py
    
    from appium_advance.page_object.desired_caps import appium_desired
    import logging
    import unittest
    from time import sleep
    
    class StartEnd(unittest.TestCase):
        def setUp(self):
            logging.info('===============setup==============')
            self.driver=appium_desired()
    
        def tearDown(self):
            logging.info('=============teardown============')
            sleep(5)
            self.driver.close_app()
    View Code
    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    # @Time : 2019-07-05 16:24
    # @Author : zhouyang
    # @File : test_login.py
    '''
    unittest写的测试用例
    '''
    import unittest
    from appium_advance.unittest.myunit import StartEnd
    from appium_advance.page_object.loginView import LoginView
    import logging
    
    class Test_Login(StartEnd):
        def test_login_zxw2018(self):
            logging.info('=========test_login_zxw2018=========')
            l=LoginView(self.driver)
            l.login_action('自学网2018','zxw2018')
    
        def test_login_zxw2017(self):
            logging.info('=========test_login_zxw2017=========')
            l=LoginView(self.driver)
            l.login_action('自学网2017','zxw2017')
    
        def test_login_error(self):
            logging.info('=========test_login_error=========')
            l=LoginView(self.driver)
            l.login_action('123','456')
    
    if __name__ == '__main__':
        unittest.main()
    platformName: Android
    platformVersion: 4.4.2
    deviceName: 127.0.0.1:62001
    app: C:UsersAdministratorDesktopkaoyan3.1.0.apk
    appPackage: com.tal.kaoyan
    appActivity: com.tal.kaoyan.ui.activity.SplashActivity
    noReset: False
    unicodeKeyboard: True
    resetKeyboard: True
    ip: 127.0.0.1
    port: 4723
    View Code
  • 相关阅读:
    JS函数
    JS数据类型
    JavaScript HTML DOM
    JavaScript-HTML
    HTML基础知识
    数据库--事务:级联删除(学生教师信息表)为例
    javascript window.open
    设置DIV半透明CSS代码:
    css实现你的网页图片半透明效果
    html中,如何打开index.html后可以自动打开另一个页面?
  • 原文地址:https://www.cnblogs.com/xiuxiu123456/p/11150359.html
Copyright © 2011-2022 走看看