appium+python自动化测试模板

import unittest                                   #Python单元测试框架
import os
import sys
import time
import re
from configparser import ConfigParser             #读取配置库
from selenium import webdriver                    #导入selenium库
from appium import webdriver                      #导入appium库


class ProductInformation(unittest.TestCase):
    """
    TestCase: xxxxx
    Description: xxxxx
    """
    
    #@classmethod,在此类中只进行一次初始化和清理工作 
    @classmethod
    def setUp(self):
        #self.driver = appium_config.appium_start()
        desired_caps = {}
        desired_caps['platformName'] = 'Android'
        desired_caps['platformVersion'] = '6.0'
        desired_caps['deviceName'] = 'Nexus 6 API 23'
        desired_caps['appPackage'] = 'com.lanxum.diagnosis.student.hg'
        #desired_caps['appActivity'] = 'com.lanxum.diagnosis.student.model.nav.SplashActivity'
        desired_caps['app'] = 'E://AndroidStudioProjects/a0801.apk'#E:\AndroidStudioProjects\0801.apk
        self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)

    def test_initial(self):
        time.sleep(3)
        nav_btn = self.driver.find_element_by_name('跳过')
        #nav_btn = self.driver.find_element_by_id('com.lanxum.diagnosis.student.hg:id/nav_first_ignore')
        nav_btn.click()
        time.sleep(1)
        self.driver.find_element_by_name('请输入登录账号').send_keys('xiaoming')
        #self.driver.find_element_by_id('com.lanxum.diagnosis.student.hg:id/et_login_id').send_keys('xiaoming')
        self.driver.hide_keyboard()
        time.sleep(1)
        #self.driver.find_element_by_xpath("//android.widget.EditText[@content-desc='请输入登录密码']").send_keys('111111')
        password = self.driver.find_elements_by_class_name('android.widget.EditText')
        password[1].send_keys('111111')
        #self.driver.find_element_by_id('com.lanxum.diagnosis.student.hg:id/et_login_password').send_keys('111111')
        self.driver.hide_keyboard()
        time.sleep(1)
        self.driver.find_element_by_name('登录').click()
        #self.driver.find_element_by_id('com.lanxum.diagnosis.student.hg:id/btn_login').click()
    @classmethod
    def tearDown(self):
        self.driver.quit()
    # texture Testcase
def suite():
    tests = [
        "test_initial",        
    ]
    return unittest.TestSuite(map(ProductInformation,tests))
if __name__ == "__main__":
    unittest.TextTestRunner(verbosity=2).run(suite())

你可能感兴趣的:(软件测试)