Esempio n. 1
0
 def test_create_php_file_and_replace(self):
     dest = self.test_dir + os.sep + 'dest_test'
     File.create_php_file_and_replace(TEST_FILE1_CONTENT,
                                      dest,
                                      'Test',
                                      'Replace')
     with open(dest, 'r') as content:
         self.assertIn('Replace\nSomething\nREPLACE\nSomewhere\nreplace',
                       content.read())
Esempio n. 2
0
 def test_sed_replace_without_match(self):
     sed_file_path = self.test_dir + os.sep + 'sed_test'
     with open(sed_file_path, 'w') as sed_file:
         sed_file.write('AABBBCCCC')
     File.sed_replace('ZZZ', 'DDDDD', sed_file_path)
     file_content = ''
     with open(sed_file_path, 'r') as sed_file:
         file_content = sed_file.read()
     self.assertIn('AABBBCCCC', file_content)
Esempio n. 3
0
def RunTestCase(starttime,devices):
    print("进入",devices,"的RunTestCase")
    # 获取路径
    configPath = "./config.ini"
    package = Config.getValue(configPath, "packName")[0]
    casepath = os.path.join(os.getcwd(), "TestCase")
    if not os.path.exists(casepath):
        print("测试用例需放到‘TestCase’文件目录下")
    reportpath = os.path.join(os.getcwd(), "Report")
    if not os.path.exists(reportpath):
        os.mkdir(reportpath)
        os.mkdir(reportpath+"/Screen")
    #读取ini文件,获得期望测试的用例列表
    TestList=Config.getValue(configPath, "testcase")
    # 通过GetPyList方法,取得目录里可测试的用例列表
    scriptList = File.GetPyList(casepath)
    suite = unittest.TestSuite()
    for i in range(len(TestList)):
        fileName = "TC_" + TestList[i]
        if fileName in scriptList:
            result = globals()[fileName].Main(devices)
            suite.addTests(result)
    unittestReport = BeautifulReport(suite)
    #处理模拟器端口用的冒号
    if ":" in devices:
        devices=devices.split(":")[1]
    print("devices=",devices)
    nowtime=time.strftime("%H%M%S")
    unittestReport.report(filename=devices+"_"+str(nowtime),description=package, report_dir=reportpath)
    stop_app(package)
Esempio n. 4
0
def RunTestCase(madb,start):
    devices=madb.get_mdevice()
    print("进入{}的RunTestCase".format(devices))
    # 获取路径
    package = madb.get_packagename()
    TestCasePath = madb.get_TestCasePath()
    print("TestCasePath=",TestCasePath)
    if not os.path.exists(TestCasePath):
        print("测试用例需放到‘TestCase’文件目录下")
    reportpath = os.path.join(os.getcwd(), "Report")
    #读取ini文件,获得期望测试的用例列表
    TestList=madb.get_testcaseforselfdevice()
    print("{}的待测用例为:{}".format(madb.get_mdevice(),TestList))
    # 通过GetPyList方法,取得目录里可测试的用例列表
    scriptList = File.GetPyList(TestCasePath)
    suite = unittest.TestSuite()
    for i in range(len(TestList)):
        fileName = "TC_" + TestList[i]
        print("fileName=",fileName)
        if fileName in scriptList:
            print("进入循环")
            #在整个命名空间里遍历所有名称为"TC_xx.py"形式的文件,默认这些文件都是unittest测试文件,然后调用其Main函数。
            result = globals()[fileName].Main(devices)
            suite.addTests(result)
    #聚合报告到BR
    unittestReport = BeautifulReport(suite)
    nowtime=time.strftime("%H%M%S",start)
    #unittestReport.report(filename=madb.get_nickdevice()+"_"+str(nowtime),description=package, report_dir=reportpath,rundevice=madb.get_mdevice())
    # unittestReport.report(filename=madb.get_nickname()+"_"+str(nowtime),description=package, report_dir=reportpath)
    unittestReport.report(filename=madb.get_nickname()+"_report",description=package, log_path=reportpath)
    stop_app(package)
Esempio n. 5
0
def RunTestCase(madb, start):
    # 获取设备列表
    devices = madb.get_mdevice()
    logger.info("进入{}的RunTestCase".format(devices))

    # 获取是否跳过生成测试报告
    skip_report = madb.get_skip_report()
    report_flag = True if skip_report == "1" else False

    # 获取jenkins部署信息
    jenkins_branch, timestamp = jenkins_lastBuild_info()
    logger.info('jenkins分支:{}'.format(jenkins_branch))
    timeArray = time.localtime(timestamp / 1000)
    jenkins_time = time.strftime("%Y--%m--%d %H:%M:%S", timeArray)
    logger.info('部署时间:{}'.format(jenkins_time))

    # 获取手机型号
    command = adb + " -s {} shell getprop ro.product.model".format(devices)
    brand = os.popen(command).read()
    # 获取手机版本
    command1 = adb + " -s {} shell getprop ro.build.version.release".format(
        devices)
    version = os.popen(command1).read()
    # 获取路径
    package = madb.get_packagename()
    TestCasePath = madb.get_TestCasePath()
    if not os.path.exists(TestCasePath):
        logger.error("测试用例需放到‘TestCase’文件目录下")
    reportpath = os.path.join(os.getcwd(), "Report")
    # 读取ini文件,获得期望测试的用例列表
    TestList = madb.get_testcaseforselfdevice()
    logger.info("{}的待测用例为:{}".format(madb.get_mdevice(), TestList))
    # 通过GetPyList方法,取得目录里可测试的用例列表
    scriptList = File.GetPyList(TestCasePath)
    # 初始化测试套件
    suite = unittest.TestSuite()
    # 初始化poco
    poco = AndroidUiautomationPoco()
    for i in range(len(TestList)):
        fileName = "TC_" + TestList[i]
        logger.debug("fileName={}".format(fileName))
        if fileName in scriptList:
            # 在整个命名空间里遍历所有名称为"TC_xx.py"形式的文件,默认这些文件都是unittest测试文件,然后调用其run_case函数。
            result = globals()[fileName].run_case(devices, poco)
            # 根据result类型判断调试单个方法or全部方法
            if isinstance(result, unittest.suite.TestSuite):
                suite.addTests(result)
            else:
                suite.addTest(result)
    # 聚合报告到BR
    unittestReport = BeautifulReport(suite)
    nowtime = time.strftime("%Y%m%d%H%M%S", start)
    unittestReport.report(filename=madb.get_nickname() + "_" + str(nowtime),
                          description=package,
                          report_dir=reportpath,
                          brand=brand,
                          version=version,
                          jenkins_branch=jenkins_branch,
                          jenkins_time=jenkins_time,
                          report_flag=report_flag)
Esempio n. 6
0
 def test_write_json_file(self):
     data = {
         '\\/coucou\\/': 'Plouf',
         'bla': 'è&ça °'
     }
     to_compare = '{\n    "\\/coucou\\/": "Plouf",\n    "bla": "è&ça °"\n}\n'
     test_file_path = self.test_dir + os.sep + 'json_test'
     result = File.write_json_file(test_file_path, data)
     self.assertTrue(result)
     content = ''
     with open(test_file_path, 'r') as test_file:
         content = test_file.read()
     self.assertEqual(content, to_compare)
Esempio n. 7
0
 def test_replace_in_file_newname(self):
     File.replace_in_file(self.test_file1, 'Test', 'newname')
     content = ''
     with open(self.test_file1, 'r') as file_content:
         content = file_content.read()
     self.assertIn('newname\nSomething\nNEWNAME\nSomewhere\nnewname',
                   content)
     File.replace_in_file(self.test_file2, 'Test', 'newname')
     with open(self.test_file2, 'r') as file_content:
         content = file_content.read()
     self.assertIn(TEST_FILE2_CONTENT,
                   content)
     File.replace_in_file(self.test_file3, 'Test', 'newname')
     with open(self.test_file3, 'r') as file_content:
         content = file_content.read()
     self.assertIn('i newname a file',
                   content)
Esempio n. 8
0
# -*- coding: utf-8 -*-
__author__ = "无声"
import os

#自动引入当前文件夹下所有py文件
from tools import File
print(os.getcwd())
pyList = File.GetPyList("./TestCase")

__all__ = pyList
Esempio n. 9
0
# -*- coding: utf-8 -*-
__author__ = "无声"

import os, inspect

#自动引入当前文件夹下所有py文件
from tools import File

Path = os.path.abspath(
    os.path.dirname(inspect.getfile(inspect.currentframe())) + os.path.sep +
    ".")
pyList = File.GetPyList(Path)

__all__ = pyList
Esempio n. 10
0
 def test_is_content_in_file_without_content(self):
     file_to_test = self.test_dir + os.sep + 'WithContent'
     with open(file_to_test, 'w') as dest:
         dest.write('Small content in a file')
     result = File.is_content_in_file(file_to_test, 'content')
     self.assertTrue(result)
Esempio n. 11
0
 def test_is_content_in_file_without_the_content(self):
     file_to_test = self.test_dir + os.sep + 'WithoutTheContent'
     with open(file_to_test, 'w') as dest:
         dest.write('Nothing in this file')
     result = File.is_content_in_file(file_to_test, 'content')
     self.assertFalse(result)
Esempio n. 12
0
 def test_is_content_in_file_without_file(self):
     file_to_test = self.test_dir + os.sep + 'FileNotFound'
     result = File.is_content_in_file(file_to_test, 'test string')
     self.assertFalse(result)
Esempio n. 13
0
 def test_add_line_under_without_line(self):
     File.add_line_under(self.test_file2, 'Useful', 'Added')
     with open(self.test_file2, 'r') as content:
         self.assertIn('A\nUseless\nFile', content.read())
Esempio n. 14
0
def RunTestCase(driver: AutoWeb, start):
    logger.info("进入RunTestCase")
    # 读取ini配置文件
    # 获取测试网页的url
    url = driver.get_url()
    logger.info('测试的网页:{}'.format(url))
    # 获取测试网页的描述
    desc = driver.get_pro_desc()
    # 获取是否跳过生成测试报告
    skip_report = driver.get_skip_report()
    report_flag = True if skip_report == "1" else False

    # 获取jenkins部署信息
    jenkins_branch, timestamp = jenkins_lastBuild_info()
    logger.info('jenkins分支:{}'.format(jenkins_branch))
    timeArray = time.localtime(timestamp / 1000)
    jenkins_time = time.strftime("%Y-%m-%d %H:%M:%S", timeArray)
    logger.info('部署时间:{}'.format(jenkins_time))

    # 获取测试用例路径
    TestCasePath = AutoWeb.get_testcase_path()
    if not os.path.exists(TestCasePath):
        logger.error("测试用例需放到‘TestCase’文件目录下")

    # 获得期望测试的用例列表
    TestList = AutoWeb.get_testcase()
    logger.info("待测用例为:{}".format(TestList))

    # 通过GetPyList方法,取得目录里可测试的用例列表
    scriptList = File.GetPyList(TestCasePath)
    # 初始化测试套件
    suite = unittest.TestSuite()
    for i in range(len(TestList)):
        fileName = "TC_" + TestList[i]
        logger.debug("fileName={}".format(fileName))
        if fileName in scriptList:
            # 在整个命名空间里遍历所有名称为"TC_xx.py"形式的文件,默认这些文件都是unittest测试文件,然后调用其run_case函数。
            result = globals()[fileName].run_case(driver, url)
            # 根据result类型判断调试单个方法or全部方法
            if isinstance(result, unittest.suite.TestSuite):
                suite.addTests(result)
            else:
                suite.addTest(result)
    # 聚合报告到BR
    unittestReport = BeautifulReport(suite)
    nowtime = time.strftime("%Y%m%d%H%M%S", start)
    reportpath = os.path.join(os.getcwd(), "Report")
    unittestReport.report(filename=str(nowtime),
                          description=desc,
                          url=url[8:],
                          report_dir=reportpath,
                          jenkins_branch=jenkins_branch,
                          jenkins_time=jenkins_time,
                          report_flag=report_flag)
    # 测试case中如果使用airtest_touch方法进行定位元素,会产生一个temp.jpg的截图文件,测试完成后删除
    temp_img_path = os.path.join(root_path, 'temp.jpg')
    if os.path.exists(temp_img_path):
        os.remove(temp_img_path)
        logger.info('完成删除临时截图文件')
    else:
        logger.info('不存在临时截图文件:{}'.format(temp_img_path))
Esempio n. 15
0
 def get_file_with_name(self, fname):
     with tools.cd(self.path):
         if os.path.exists(fname):
             return File(fname, read=True)
     raise IOError('File not found', fname, 'in', self.path)