新手学appium-有关单独运行一个个的模块

  在运行app的过程,如果我想一个个模块单独的运行并产生测试报告。那么该怎么做呢?

  我可以把公共的部分,如登录功能放在setup()里面,那么每次运行你定义的一个个函数,都会调用这个setup()中的数据。

  还是贴一下代码的思路

  

#coding=utf-8

import os
import unittest,sys,time,re,datetime,HTMLTestRunner
from appium import webdriver
from time import sleep
import sys

#reload(sys)
#sys.setdefaultencoding("utf-8") 

# Returns abs path relative to this file and not cwd
PATH = lambda p: os.path.abspath(
    os.path.join(os.path.dirname(__file__), p)
)

class ContactsAndroidTests(unittest.TestCase):
    def setUp(self):
        desired_caps = {}
        desired_caps['platformName'] = 'Android'
        desired_caps['platformVersion'] = '4.3'
        desired_caps['deviceName'] = '192.168.56.101:5555'
        '''desired_caps['app'] = PATH(
            '../../../sample-code/apps/ContactManager/ContactManager.apk'
        )'''
        desired_caps['appPackage'] = 'com.jiudao.ccare'
        desired_caps['appActivity'] = '.StartActivity'

        self.driver = webdriver.Remote('http://192.168.10.165:4723/wd/hub', desired_caps)

        #登录操作
        time.sleep(3)
        username=self.driver.find_element_by_id("com.jiudao.ccare:id/user_name")
        username.clear()
        username.send_keys("suser@umser")
        password=self.driver.find_element_by_id("com.jiudao.ccare:id/user_password")
        password.clear()
        password.send_keys("1")
        self.driver.find_element_by_id("com.jiudao.ccare:id/keep_password").click()
        self.driver.find_element_by_id("com.jiudao.ccare:id/login").click()
        time.sleep(4)

    def tearDown(self):
        self.driver.close_app()
        self.driver.quit()

    #第一个模块
    def homePage(self):
        pass

    #第二个模块
    def wait(self):
        pass

    #第三个模块
    def process(self):
        pass

    #第四个模块
    def completed(self):
        pass

    #退出操作
    def exitAccount(self):
        """退出操作"""
        pass


if __name__ == '__main__':
    suite = unittest.TestSuite()
    suite.addTest(ContactsAndroidTests("homePage"))
    suite.addTest(ContactsAndroidTests("wait"))
    suite.addTest(ContactsAndroidTests("process"))
    suite.addTest(ContactsAndroidTests("completed"))
    suite.addTest(ContactsAndroidTests("exitAccount"))
    timestr = time.strftime('%Y%m%d%H%M%S',time.localtime(time.time()))
    filename = "D:\\appium\\appiumresult\\result_" + timestr + ".html"
    print (filename)
    fp = open(filename, 'wb')
    runner = HTMLTestRunner.HTMLTestRunner(
                stream=fp,
                title='测试结果',
                description='测试报告'
                )
    runner.run(suite)
    fp.close() #测试报告关闭
    

 

posted @ 2015-05-08 14:11  Mr.Dantes  阅读(757)  评论(0编辑  收藏  举报