Exemplo n.º 1
0
def main():
    #默认去config.ini里读取期望参与测试的设备,若为空,则选择当前连接的所有状态为“device”的设备
    devicesList = Madb().get_devicesList()
    if devicesList[0] == "":
        devicesList = Madb().getdevices()
    print("最终的devicesList=", devicesList)
    #读取是否需要同步性能测试的配置。
    need_performance = Madb().get_needperformance()
    reportpath = os.path.join(os.getcwd(), "Report")
    # 没有Report目录时自动创建
    if not os.path.exists(reportpath):
        os.mkdir(reportpath)
        os.mkdir(reportpath + "/Screen")
    print("测试开始")
    if devicesList:
        try:
            print("启动进程池")
            list = []
            # 根据设备列表去循环创建进程,对每个进程调用下面的enter_processing/enter_enter_performance方法。
            for i in range(len(devicesList)):
                #start会被传递到2个进程函数里,作为区分最终产物html和excel的标志
                start = time.localtime()
                madb = Madb(devicesList[i])
                if madb.get_androidversion() < 5:
                    print("设备{}的安卓版本低于5,不支持。".format(madb.get_mdevice()))
                    continue
                else:
                    #进程通信变量flag,默认为0,完成测试时修改为1。
                    flag = Value('i', 0)
                    if need_performance == "True":
                        p1 = Process(target=enter_performance,
                                     args=(
                                         madb,
                                         flag,
                                         start,
                                     ))
                        list.append(p1)
                p2 = Process(target=enter_processing,
                             args=(
                                 i,
                                 madb,
                                 flag,
                                 start,
                             ))
                list.append(p2)
            for p in list:
                p.start()
            for p in list:
                p.join()
            print("进程回收完毕")
            print("测试结束")
        except AirtestError as ae:
            print("Airtest发生错误" + traceback.format_exc())
        except PocoException as pe:
            print("Poco发生错误" + traceback.format_exc())
        except Exception as e:
            print("发生未知错误" + traceback.format_exc())
    else:
        print("未找到设备,测试结束")
Exemplo n.º 2
0
def run_case(devices, poco):
    logger.info("{}进入unittest".format(devices))
    package = Madb(devices).get_packagename()

    class TC102(unittest.TestCase):
        u'''添加好友'''
        @classmethod
        def setUpClass(cls):
            """ 这里放需要在所有用例执行前执行的部分"""
            wake()

        def setUp(self):
            """这里放需要在每条用例前执行的部分"""
            start_app(package)
            sleep(2)

        def test_demo2(self):
            """此处添加用例描述"""
            poco(text='手机号登录').click()

        def tearDown(self):
            """这里放需要在每条用例后执行的部分"""
            sleep(5)
            stop_app(package)

        # @classmethod
        # def tearDownClass(cls):
        #     u"""这里放需要在所有用例后执行的部分"""
        #     stop_app("com.qywlandroid")
        #     sleep(1)

    srcSuite = unittest.TestLoader().loadTestsFromTestCase(TC102)
    # srcSuite = TC101("test_demo2")
    return srcSuite
Exemplo n.º 3
0
def main():
    # 默认去config.ini里读取期望参与测试的设备,若为空,则选择当前连接的所有状态为“device”的设备
    devices_List = Madb().get_devicesList()
    if devices_List[0] == "":
        devices_List = Madb().getdevices()
    print("最终的devicesList=", devices_List)
    # 读取是否需要同步性能测试的配置。
    # need_performance = Madb().get_needperformance()
    print("测试开始")
    print("启动appium")

    time.sleep(5)
    if devices_List:
        try:
            print("启动进程池")
            devices_List = devices_List.split(",")
            list1 = []
            # 根据设备列表去循环创建进程,对每个进程调用下面的enter_processing/enter_enter_performance方法。
            for i in range(len(devices_List)):
                # start会被传递到2个进程函数里,作为区分最终产物html和excel的标志

                start = time.localtime()
                madb = Madb(devices_List[i])
                # 进程通信变量flag,默认为0,完成测试时修改为1。
                flag = Value('i', 0)
                p2 = Process(target=enter_processing, args=(i, madb, flag, start))
                list1.append(p2)
            for p in list1:
                p.start()
            for p in list1:
                p.join()
            print("进程回收完毕")

            print("测试结束")
        except Exception as e:
            print("发生未知错误" + traceback.format_exc())
    else:
        print("未找到设备,测试结束")
Exemplo n.º 4
0
def run_case(devices, poco):
    logger.debug("{}进入unittest".format(devices))
    package = Madb(devices).get_packagename()

    class TC101(unittest.TestCase):
        """用例描述"""
        @classmethod
        def setUpClass(cls):
            """ 这里放需要在所有用例执行前执行的部分"""
            wake()

        def setUp(self):
            """这里放需要在每条用例前执行的部分"""
            start_app(package)
            sleep(2)

        def test_login(self):
            """点击微信登录"""
            pass
            # logger.info('执行1')
            # poco(text='微信登录').click()

        def test_demo2(self):
            """点击手机号登录"""
            pass
            # logger.info('执行2')
            # poco(text='手机号登录').click()
            # pass

        def test_demo3(self):
            """touch使用"""
            pass
            # logger.info('执行test_demo3')
            # touch(Template('{}/login_on.png'.format(case_img)))

        def tearDown(self):
            """这里放需要在每条用例后执行的部分"""
            sleep(5)
            stop_app(package)

        @classmethod
        def tearDownClass(cls):
            u"""这里放需要在所有用例后执行的部分"""
            pass

    # 调试测试类下所有方法
    # srcSuite = unittest.TestLoader().loadTestsFromTestCase(TC101)
    # 调试测试类下某个方法
    srcSuite = TC101("test_login")
    return srcSuite
Exemplo n.º 5
0
def auto_search(i, flag=True):
    tasks = get_hotsoon_task()
    if tasks:
        json_result = json.loads(tasks[i].json)
        data = {"status": '1'}
        ShortVideoState.edit_status(tasks[i].id, data)
        dictParameters = json_result["dictParameters"]
        searchWords = dictParameters["searchWord"]
        searchWord_list = searchWords.split(",")
        poco = Madb().get_poco()
        if len(searchWord_list) > 0:
            keyword = searchWord_list[0]
            for searchWord in searchWord_list:
                index = searchWord_list.index(searchWord)
                aut_search_recur(keyword, searchWord, index, poco, flag)
        auto_search(i, False)
Exemplo n.º 6
0
def douyin_enter_processing(i):
    if len(devicesList):
        madb = Madb(devicesList[i])
    else:
        return
    devices = madb.get_mdevice()
    print("进入进程,devicename={}".format(devices))
    isconnect = ""
    try:
        #调用airtest的各个方法连接设备
        if ("127.0.0.1" in devices or '-' in devices):
            connect_device('android:///' + devices +
                           '?cap_method=javacap&touch_method=adb')
        else:
            connect_device("Android:///" + devices)

        time.sleep(madb.get_timeout_of_per_action())
        auto_setup(__file__)
        isconnect = "Pass"
        print("设备{}连接成功".format(devices))
        installflag = ""
        startflag = ""
        if isconnect == "Pass":
            try:
                #尝试启动应用
                madb.StartApp()
                douyin_auto_search(i)
                # 查询搜索任务
                startflag = "Success"
            except Exception as e:
                print("运行失败" + traceback.format_exc())
            time.sleep(madb.get_timeout_of_per_action())
            #应用启动成功则开始运行用例
            if (startflag == "Success"):
                print("{}完成测试".format(devices))
            else:
                print("{}未运行测试。".format(devices))
        else:
            print("设备{}连接失败".format(devices))
    except Exception as e:
        print("连接设备{}失败".format(devices) + traceback.format_exc())
Exemplo n.º 7
0
def app_start(device):
    desired_caps = {}
    desired_caps['platformName'] = data['platformName']
    desired_caps['platformVersion'] = data['platformVersion']
    desired_caps['deviceName'] = data['deviceName']
    desired_caps['udid'] = device

    desired_caps['appPackage'] = data['packname']
    desired_caps['appActivity'] = data['activity']
    desired_caps['noReset'] = data['noReset']
    madb = Madb(device)
    print(int(madb.get_nickname()))
    i = 0
    if int(madb.get_nickname()) == 62001:
        i = 0
    elif int(madb.get_nickname()) == 62025:
        i = 1
    elif int(madb.get_nickname()) > 62025:
        i = 2 + (int(madb.get_nickname()) - 62025)
    port = 4723 + 2 * i
    print('appium port:%s start run %s at %s' % (port, device, time.ctime()))
    driver_address = 'http://' + str(data['ip']) + ':' + str(port) + '/wd/hub'
    driver = webdriver.Remote(driver_address, desired_caps)
    driver.implicitly_wait(5)
Exemplo n.º 8
0
        AndroidVersion = os.popen(adb + " -s {} shell getprop ro.build.version.sdk".format(devices)).read().strip()
        airtest_minicap_path=os.path.abspath(os.path.dirname(root_path) + os.path.sep + ".")+"\\airtest\\core\\android\\static\\stf_libs"
        airtest_minicapso_path= os.path.abspath(os.path.dirname(root_path) + os.path.sep + ".")+"\\airtest\\core\\android\\static\\stf_libs\\minicap-shared\\aosp\\libs\\"+"android-{}\\{}\\minicap.so".format(AndroidVersion,ABI)
        push_minicap=adb + " -s {} push {}/{}/minicap".format(devices,airtest_minicap_path,ABI) +" /data/local/tmp/"
        push_minicapso = adb + " -s {} push {}".format(devices, airtest_minicapso_path) + " /data/local/tmp/"
        print("推送minicap和minicap.so")
        os.popen(push_minicap)
        os.popen(push_minicapso)
        chmod=adb+ " -s {} shell chmod 777 /data/local/tmp/*".format(devices)
        print("赋予权限成功")
        os.popen(chmod)
        wm_size_command=adb+" -s {} shell wm size".format(devices)
        vm_size=os.popen(wm_size_command).read()
        vm_size=vm_size.split(":")[1].strip()
        print("屏幕分辨率为{}".format(vm_size))
        start_minicap=adb + " -s {} shell LD_LIBRARY_PATH=/data/local/tmp /data/local/tmp/minicap -P {}@{}/0 -t".format(devices,vm_size,vm_size)
        result=os.popen(start_minicap).read()
        print(result)
        print("设备{}上已经成功安装并开启了MiniCap。".format(devices))
    except Exception as e:
        print( e,traceback.format_exc())

if __name__=="__main__":
    devicesList = Madb().get_devicesList()
    if devicesList[0] == "":
        devicesList = Madb().getdevices()
    print("最终的devicesList=", devicesList)
    for device in devicesList:
        ini_MiniCap(device)
        #GetScreenbyMiniCap(time.time(),device,"测试")
Exemplo n.º 9
0
        fr_r_index = content.rfind(tag)
    else:
        fr_r_index = content.find(tag)
    for i in range(1, round_num):
        if reverse:
            fr_r_index = content.rfind(tag, 0, fr_r_index)
        else:
            fr_r_index = content.find(tag, fr_r_index + 1)
    fr_prev = content[0:fr_r_index]
    fr_next = content[fr_r_index:len(content)]
    return fr_prev, fr_next


#调试代码,单独执行的话,flag默认为1。
if __name__ == "__main__":
    devicesList = Madb().getdevices()
    print("最终的devicesList=", devicesList)

    start = time.localtime()
    '''
    madb = Madb(devicesList[0])
    flag = Value('i', 0)
    enter_performance (madb, flag, start,)
    '''
    print("启动进程池")
    flag = Value('i', 0)
    Processlist = []
    for i in range(len(devicesList)):
        madb = Madb(devicesList[i])
        if madb.get_androidversion() < 5:
            print("设备{}的安卓版本低于5,不支持。".format(madb.get_mdevice()))
Exemplo n.º 10
0
def main():
    # 默认去config.ini里读取期望参与测试的设备,若为空,则选择当前连接的所有状态为“device”的设备
    devicesList = Madb().get_devicesList()
    if devicesList[0] == "":
        devicesList = Madb().getdevices()
    print("最终的devicesList=", devicesList)
    if Madb().get_apkpath() == "" or Madb().get_packagename() == "":
        print("配置文件填写不全,packagename和apkpath是必填项")
        devicesList = None
    # 读取是否需要同步性能测试的配置。
    skip_performance = Madb().get_skip_performance()
    skip_performance = True if skip_performance == "1" else False
    is_storaged_by_excel = Madb().get_storage_by_excel()
    is_storaged_by_excel = True if is_storaged_by_excel == "1" else False
    reportpath = os.path.join(os.getcwd(), "Report")
    # 没有Report目录时自动创建
    if not os.path.exists(reportpath):
        os.mkdir(reportpath)
        os.mkdir(reportpath + "/Screen")
        os.mkdir(reportpath + "/Data")
        print(reportpath)
    print("测试开始")
    if devicesList:
        try:
            print("启动进程池")
            list = []
            # 根据设备列表去循环创建进程,对每个进程调用下面的enter_processing/enter_enter_performance方法。
            for i in range(len(devicesList)):
                # start会被传递到2个进程函数里,作为区分最终产物html和excel的标志
                start = time.localtime()
                madb = Madb(devicesList[i])
                if madb.get_androidversion() < 5:
                    print("设备{}的安卓版本低于5,不支持。".format(madb.get_mdevice()))
                    continue
                else:
                    # 进程通信变量flag,默认为0,完成测试时修改为1。
                    flag = Value('i', 0)
                    fpsflag = Value('i', 0)
                    if not skip_performance:
                        p1 = Process(target=enter_performance,
                                     args=(madb, flag, start,
                                           is_storaged_by_excel))
                        list.append(p1)
                p2 = Process(target=enter_processing,
                             args=(
                                 i,
                                 madb,
                                 flag,
                                 start,
                             ))
                list.append(p2)
            for p in list:
                p.start()
            for p in list:
                p.join()
            print("进程回收完毕")
            print("测试结束")
            screenoff = Madb().get_screenoff()
            screenoff = True if screenoff == "1" else False
            if screenoff:
                for i in devicesList:
                    setScreenOFF(i)
                    print("设备{}已灭屏".format(i))
        except AirtestError as ae:
            print("Airtest发生错误" + traceback.format_exc())
        except PocoException as pe:
            print("Poco发生错误" + traceback.format_exc())
        except Exception as e:
            print("发生未知错误" + traceback.format_exc())
    else:
        print("未找到设备,测试结束")
    mailtext = "自动化测试完毕"
    '''
Exemplo n.º 11
0
            if installflag == "Success":
                try:
                    # 尝试启动应用
                    madb.StartApp()
                    startflag = "Success"
                except Exception as e:
                    print("运行失败" + traceback.format_exc())
            time.sleep(madb.get_timeout_of_per_action())
            # 应用启动成功则开始运行用例
            if (startflag == "Success"):
                RunTestCase.RunTestCase(madb, start)
                print("{}完成测试".format(devices))
            else:
                print("{}未运行测试。".format(devices))
        else:
            print("设备{}连接失败".format(devices))
    except Exception as e:
        print("连接设备{}失败".format(devices) + traceback.format_exc())
    # 无论结果如何,将flag置为1,通知Performance停止记录。
    flag.value = 1


if __name__ == "__main__":
    screenoff = Madb().get_screenoff()
    screenoff = True if screenoff == "1" else False
    devicesList = Madb().getdevices()
    if screenoff:
        for i in devicesList:
            setScreenOFF(i)
            print("设备{}已灭屏".format(i))
Exemplo n.º 12
0
from tools.db import State, ShortVideoState

import traceback

index_print = print


def print(*args, **kwargs):
    index_print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), *args,
                **kwargs)


'''
整个框架的主程序,根据配置表读取设备,并逐一为其分配搜索进程。
'''
devicesList = Madb().getdevices()


def main():
    #默认去config.ini里读取期望参与测试的设备,若为空,则选择当前连接的所有状态为“device”的设备
    task_search()
    #douyin_task_search()


def douyin_task_search():
    if devicesList:
        try:
            print("启动进程池")
            list = []
            # 根据设备列表去循环创建进程,对每个进程调用下面的enter_processing方法。
            for i in range(len(devicesList)):