Ejemplo n.º 1
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)
Ejemplo n.º 2
0
def main():
    configPath = "./config.ini"
    devicesList = Config.getValue(
        configPath,
        "deviceslist",
    )
    #devicesList = getdevices()
    print("测试开始")
    try:
        pool = multiprocessing.Pool(processes=len(devicesList))
        print("启动进程池")
        results = []
        for i in range(len(devicesList)):
            pool.apply_async(Main, (
                i,
                devicesList[i],
            ))  #根据设备列表去循环创建进程,对每个进程调用下面的Main方法。
        pool.close()
        pool.join()
        print("进程回收完毕")
        print("测试结束")
    except AirtestError as ae:
        print("Airtest发生错误" + ae)
    except PocoException as pe:
        print("Poco发生错误" + pe)
    except Exception as e:
        print("发生未知错误" + e)
Ejemplo n.º 3
0
def PushApk2Devices(devicesname):
    configPath = "./config.ini"
    packagename = Config.getValue(configPath, "packName")[0]
    apkpath = Config.getValue(configPath, "apkpath")[0]
    try:
        installThread = threading.Thread(target=AppInstall,
                                         args=(
                                             devicesname,
                                             apkpath,
                                             packagename,
                                         ))
        inputThread = threading.Thread(target=InputEvent, args=(devicesname, ))
        installThread.start()
        inputThread.start()
        installThread.join()
        inputThread.join()
        return "Success"
    except Exception as e:
        return e
    pass
Ejemplo n.º 4
0
def StartApp(devices):
    configPath = "../config.ini"
    packagename = Config.getValue(configPath, "packName")[0]
    start_app(packagename)

    # 获取andorid的poco代理对象,准备进行开启应用权限(例如申请文件存储、定位等权限)点击操作
    pocoAndroid = AndroidUiautomationPoco(use_airtest_input=True,
                                          screenshot_each_action=False)
    if devices == "127.0.0.1:62001":
        #这里是针对不同机型进行不同控件的选取,需要用户根据自己的实际机型实际控件进行修改
        count = 0
        while not pocoAndroid("android.view.View").exists():
            print(devices, "开启应用的权限点击,循环第", count, "次")
            if count >= 3:
                break
            if pocoAndroid(
                    "com.android.packageinstaller:id/permission_allow_button"
            ).exists():
                pocoAndroid(
                    "com.android.packageinstaller:id/permission_allow_button"
                ).click()
            else:
                time.sleep(3)
                count += 1
    elif devices == "127.0.0.1:62025":
        count = 0
        while not pocoAndroid("android.view.View").exists():
            print(devices, "开启应用的权限点击,循环第", count, "次")
            if count >= 3:
                break
            if pocoAndroid("android:id/button1").exists():
                pocoAndroid("android:id/button1").click()
            else:
                time.sleep(3)
                count += 1

    return None
Ejemplo n.º 5
0
 def __init__(self, mdevice=""):
     #获取当前文件的上层路径
     self._parentPath = os.path.abspath(
         os.path.dirname(inspect.getfile(inspect.currentframe())) +
         os.path.sep + ".")
     #获取当前项目的根路径
     self._rootPath = os.path.abspath(
         os.path.dirname(self._parentPath) + os.path.sep + ".")
     self._configPath = self._rootPath + "\config.ini"
     self._devicesList = Config.getValue(
         self._configPath,
         "deviceslist",
     )
     self._packagePath = Config.getValue(self._configPath, "apkpath")[0]
     self._packageName = Config.getValue(self._configPath, "packname")[0]
     self._activityName = Config.getValue(self._configPath,
                                          "activityname")[0]
     self._needClickInstall = Config.getValue(self._configPath,
                                              "needclickinstall")[0]
     self._needClickStartApp = Config.getValue(self._configPath,
                                               "needclickstartapp")[0]
     self._startTime = time.time()
     self._timeoutAction = int(
         Config.getValue(self._configPath, "timeoutperaction")[0])
     self._timeoutStartApp = int(
         Config.getValue(self._configPath, "timeoutofstartapp")[0])
     self._mdevice = mdevice
     # 处理模拟器端口用的冒号
     if ":" in self._mdevice:
         self._nickName = self._mdevice.split(":")[1]
     else:
         self._nickName = self._mdevice
     self._iteration = int(
         Config.getValue(self._configPath, "iteration")[0])
     self._allTestcase = Config.getValue(self._configPath, "testcase")
     try:
         self._testcaseForSelfDevice = Config.getTestCase(
             self._configPath, self._nickName)
         if self._testcaseForSelfDevice[0] == "":
             self._testcaseForSelfDevice = self._allTestcase
     except Exception:
         self._testcaseForSelfDevice = self._allTestcase
     self._testCasePath = Config.getValue(self._configPath, "testcasepath")
     if self._testCasePath[0] == "":
         self._testCasePath = os.path.join(self._rootPath, "TestCase")
     self._needPerformance = Config.getValue(self._configPath,
                                             "needPerformance")[0]
     if self._activityName == "":
         self._activityName = APK(self.get_apkpath()).activities[0]
Ejemplo n.º 6
0
    def __init__(self, mdevice=""):
        # 获取当前文件的上层路径
        self._parentPath = os.path.abspath(
            os.path.dirname(inspect.getfile(inspect.currentframe())) +
            os.path.sep + ".")
        # 获取当前项目的根路径
        self._rootPath = os.path.abspath(
            os.path.dirname(self._parentPath) + os.path.sep + ".")
        self._configPath = self._rootPath + "\config.ini"
        self._devicesList = Config.getValue(
            self._configPath,
            "deviceslist",
        )
        self._packagePath = Config.getValue(self._configPath, "apkpath")[0]
        self._packageName = Config.getValue(self._configPath, "packname")[0]
        self._activityName = Config.getValue(self._configPath,
                                             "activityname")[0]
        self._skip_pushapk2devices = Config.getValue(self._configPath,
                                                     "skip_pushapk2devices")[0]
        self._auto_delete_package = Config.getValue(self._configPath,
                                                    "auto_delete_package")[0]
        self._auto_install_package = Config.getValue(self._configPath,
                                                     "auto_install_package")[0]
        self._skip_check_of_install = Config.getValue(
            self._configPath, "skip_check_of_install")[0]
        self._skip_check_of_startapp = Config.getValue(
            self._configPath, "skip_check_of_startapp")[0]
        self._skip_performance = Config.getValue(self._configPath,
                                                 "skip_performance")[0]
        self._storage_by_excel = Config.getValue(self._configPath,
                                                 "storage_by_excel")[0]
        self._screenoff = Config.getValue(self._configPath, "screenoff")[0]
        self._startTime = time.time()
        self._timeout_of_per_action = int(
            Config.getValue(self._configPath, "timeout_of_per_action")[0])
        self._timeout_of_startapp = int(
            Config.getValue(self._configPath, "timeout_of_startapp")[0])
        self._mdevice = mdevice
        # 处理模拟器端口用的冒号
        if ":" in self._mdevice:
            self._nickName = self._mdevice.split(":")[1]
        else:
            self._nickName = self._mdevice
        self._iteration = int(
            Config.getValue(self._configPath, "iteration")[0])
        self._allTestcase = Config.getValue(self._configPath, "testcase")
        try:
            self._testcaseForSelfDevice = Config.getTestCase(
                self._configPath, self._nickName)
            if self._testcaseForSelfDevice[0] == "":
                self._testcaseForSelfDevice = self._allTestcase
        except Exception:
            self._testcaseForSelfDevice = self._allTestcase
        self._testCasePath = Config.getValue(self._configPath, "testcasepath")
        if self._testCasePath[0] == "":
            self._testCasePath = os.path.join(self._rootPath, "TestCase")

        if self._activityName == "":
            self._activityName = APK(self.get_apkpath()).activities[0]
        self._isSurfaceView = Config.getValue(self._configPath,
                                              "isSurfaceView")[0]