Example #1
0
 def __init__(self,dname):
     
     self.device = device.Device(dname)
     self.dname = dname
     self.pname = device_config.getValue(dname, 'product_type')
     self.pkg = device_config.getValue(dname, 'slave_service')
     self.func_dict = {'network': self.network_change,
                       'clear_app': self.clear_app,
                       'access_other_app': self.access_other_app,
                       'click_screen': self.click_screen,
                       'close_app': self.close_app,
                       'close_backend_tasks': self.close_backend_tasks,
                       'connect_network_trigger': self.connect_network_trigger,
                       'install_app': self.install_app,
                       'module_effective': self.module_effective,
                       'reboot': self.reboot_device,
                       'screen_on': self.screen_on,
                       'start_app': self.start_app,
                       'task_init_source': self.task_init_resource,
                       'unlock_screen': self.unlock_screen,
                       'update_para': self.update_para,
                       'update_date': self.update_time,
                       'sdcard_action': self.sdcard_action,
                       'third_app_operation': self.install_third_app,
                       'kill_process': self.kill_process,
                       'SrvConfig_Switch': self.set_srvcon_switch,
                       'SrvConfig_Push_Interval': self.set_srvcon_Interval,
                       'oper_startup_main': self.oper_startup_main,
                       'oper_module_config': self.oper_module_config}
Example #2
0
def set_security_magazine_switch(dname, action):
    """
    set magazine lockscreen in setting page
    :param dname: device name
    :param action: on/off
    :return: NONE
    """

    # open set security UI
    DEVICE = device.Device(dname)
    value = magazine_config.getValue(dname, 'security_setting')
    DEVICE.app_operation('LAUNCH', pkg=value)
    sleep(5)

    # click setting button
    setting_path = magazine_config.getValue(
        dname, 'security_magazine_switch').split('::')
    location = setting_path[0]
    index = int(setting_path[1])

    # check current state
    state = myuiautomator.get_element_attribute(dname, location, index,
                                                'checked')

    if action.upper() == 'ON' and state != 'true':
        myuiautomator.click_element_by_id(dname, location, index)

    if action.upper() == 'OFF' and state == 'true':
        myuiautomator.click_element_by_id(dname, location, index)

    #return back to HOME
    DEVICE.send_keyevent(3)
Example #3
0
def init_app(uid):

    myDevice = device.Device(uid)
    myDevice.uninstall_app()
    # get path of app
    local_path = os.path.abspath(
        os.path.join('apps/', myDevice.CONFIG.getValue(uid, 'app')))
    mobile_path = myDevice.CONFIG.getValue(uid, 'mobile_app_path')
    myDevice.device_file_operation('PUSH', local_path, mobile_path)
    app_path = os.path.join(mobile_path, myDevice.CONFIG.getValue(uid, 'app'))

    try:
        threads = []
        install = threading.Thread(target=install_app,
                                   args=(myDevice, app_path))
        proc_process = threading.Thread(target=do_popup_windows, args=(6, uid))
        threads.append(install)
        threads.append(proc_process)
        for t in threads:
            t.setDaemon(True)
            t.start()
            sleep(5)
        t.join()
    except Exception, ex:
        print ex
Example #4
0
def do_popup_windows(nub, uid):

    find_text = [u"安装", u"允许", u"跳过", u"继续", u"开启", u"欢迎"]

    for i in range(nub):
        uiautomator.click_popup_window(uid, find_text)
        myDevice = device.Device(uid)
        myDevice.emulate_swipe_action()
Example #5
0
def run(dname, loop, rtype):

    global DEVICENAME, DEVICE, LogPath
    global LOOP_NUM, RESULT_DICT, FAIL_CASE, RUN_ID

    DEVICENAME = dname
    DEVICE = device.Device(DEVICENAME)

    # run test case
    logname = desktop.get_log_name(dname, 'TestMemory')
    LogPath = os.path.dirname(os.path.abspath(logname))
    utest_log = os.path.join(LogPath, 'unittest.html')

    # ##RESULT_DICT format {casename:{Result:['PASS','PASS'],Log:['','']}}#####
    RESULT_DICT = {}
    FAIL_CASE = []

    # insert run info to database
    dname = sys.argv[1]
    slist = sys.argv[2]
    vname = device_config.getValue(dname, 'version')
    RUN_ID = tc.insert_runinfo(slist, dname, vname, loop, rtype)

    try:
        for LOOP_NUM in range(loop):
            fileobj = file(utest_log, 'a+')
            if LOOP_NUM == 0 or rtype.upper() == 'ALL':
                suite = unittest.TestLoader().loadTestsFromTestCase(
                    TestMemoryCPU)
            else:
                suite = unittest.TestSuite()
                for name in FAIL_CASE:
                    suite.addTest(TestMemoryCPU(name))
                FAIL_CASE = []

            if suite.countTestCases() > 0:

                runner = HTMLTestRunner.HTMLTestRunner(
                    stream=fileobj,
                    verbosity=2,
                    loop=LOOP_NUM,
                    title='Test Memory&CPU Report',
                    description='Test Result',
                )
                runner.run(suite)
                fileobj.close()
                sleep(5)

            # write log to summary report
            if LOOP_NUM == loop - 1:
                desktop.summary_result(utest_log, True, RESULT_DICT)
                TestLinkObj.write_result_to_testlink(DEVICENAME, RESULT_DICT)
            else:
                desktop.summary_result(utest_log, False, RESULT_DICT)

    except Exception, ex:
        print ex
Example #6
0
def run(dname, loop, rtype):

    global DEVICENAME, CONFIG, DEVICE, LogPath
    global LOOP_NUM, RESULT_DICT, FAIL_CASE

    CONFIG = configuration.configuration()
    fname = PATH('../config/' + 'configuration.ini')
    CONFIG.fileConfig(fname)

    DEVICENAME = dname
    DEVICE = device.Device(DEVICENAME)

    # initial test environment
    init_env()

    # run test case
    logname = desktop.get_log_name(dname, 'TestTasks')
    LogPath = os.path.dirname(os.path.abspath(logname))
    utest_log = os.path.join(LogPath, 'unittest.html')

    # ##RESULT_DICT format {casename:{Result:['PASS','PASS'],Log:['','']}}#####
    RESULT_DICT = {}
    FAIL_CASE = []

    try:
        for LOOP_NUM in range(loop):

            fileobj = file(utest_log, 'a+')
            if LOOP_NUM == 0 or rtype.upper() == 'ALL':
                suite = unittest.TestLoader().loadTestsFromTestCase(TestTask)
            else:
                suite = unittest.TestSuite()
                for name in FAIL_CASE:
                    suite.addTest(TestTask(name))
                FAIL_CASE = []

            if suite.countTestCases() > 0:
                runner = HTMLTestRunner.HTMLTestRunner(
                    stream=fileobj,
                    verbosity=2,
                    title='Task Testing Report',
                    description='Test Result',
                )
                runner.run(suite)
            fileobj.close()
            sleep(5)
            # write log to summary report
            if LOOP_NUM == loop - 1:
                desktop.summary_result(utest_log, True, RESULT_DICT)
            else:
                desktop.summary_result(utest_log, False, RESULT_DICT)

    except Exception, ex:
        print ex
Example #7
0
def set_magazine_app_switch(dname, action):
    """
    set magazine wifi switch in app
    :param dname:  device name
    :param action:  on/off
    :return: None
    """
    DEVICE = device.Device(dname)
    activity_name = magazine_config.getValue(dname, 'magazine_pkg')
    DEVICE.app_operation('START', pkg=activity_name)
    sleep(5)
    # there are some popup windows when start-up app
    findstr = [u'开启', u'安装', u'允许', u'确定', u'同意']
    myuiautomator.do_popup_windows(3, findstr, dname)
    sleep(2)

    # access to setting screen of the third party of app
    setting_page = magazine_config.getValue(dname, 'activity_setting_page')
    if setting_page.upper() != 'NONE':
        DEVICE.app_operation('LAUNCH', setting_page)

    setting_path = magazine_config.getValue(dname,
                                            'magazine_wifi_switch').split('|')
    action_flag = False
    for ind, value in enumerate(setting_path):
        ltype, location, index = value.split('::')
        # check if this is the last option of setting path
        if ind == len(setting_path) - 1:
            state = myuiautomator.get_element_attribute(
                dname, value, int(index), 'checked')
            if (action.upper() == 'ON'
                    and state != 'true') or (action.upper() == 'OFF'
                                             and state == 'true'):
                action_flag = True
        if ind < len(setting_path) - 1 or action_flag:
            if ltype.upper() == 'CLASS':
                myuiautomator.click_element_by_class(dname, location,
                                                     int(index))
            if ltype.upper() == 'ID':
                myuiautomator.click_element_by_id(dname, location, int(index))
            if ltype.upper() == 'NAME':
                myuiautomator.click_element_by_name(dname, location,
                                                    int(index))

    myuiautomator.do_popup_windows(2, [u'关闭', u'打开'], dname)
    sleep(1)
    #return back to HOME
    DEVICE.send_keyevent(4)
    sleep(3)
    DEVICE.send_keyevent(3)
    sleep(3)
Example #8
0
def common_init_env(dname):

    DEVICE = device.Device(dname)
    file_list = device_config.getValue(dname,'pushfile').split(';')
    try:
        for fname in file_list:
            orgi,dest = fname.split(':')
            orgi = PATH('../external/' + dname + '/' + orgi)
            if os.path.isfile(orgi):
                DEVICE.device_file_operation('push',orgi,dest)
    except Exception, ex:
        print ex
        print "initial environment is failed"
        sys.exit(0)
Example #9
0
def set_device_wallpaper(dname, theme_type):
    """
    SET wallpaper accroding to configration theme path in advance
    :param dname: device uid
    :param wallpaper_type:  VLIFE OR SYSTEM
    :return: NONE
    """

    # log in theme app like i theme
    DEVICE = device.Device(dname)
    if theme_type.upper() == 'VLIFE':
        activity_name = wallpaper_config.getValue(dname,
                                                  'set_vlife_wallpaper_pkg')
        DEVICE.app_operation(action='LAUNCH', pkg=activity_name)
        sleep(2)
        vlife_path = wallpaper_config.getValue(
            dname, 'vlife_wallpaper_path').split('|')
    else:
        activity_name = wallpaper_config.getValue(dname,
                                                  'set_system_wallpaper_pkg')
        DEVICE.app_operation(action='LAUNCH', pkg=activity_name)
        sleep(2)
        vlife_path = wallpaper_config.getValue(
            dname, 'system_wallpaper_path').split('|')
    element = myuiautomator.Element(dname)
    event = myuiautomator.Event(dname)

    for text in vlife_path:
        x = 0
        y = 0
        if text.find(':') == -1:
            value = unicode(text)
        # because there is not 'click' action on text, so have to click next to element
        else:
            value = unicode(text.split(':')[0])
            x = text.split(':')[1]
            y = text.split(':')[2]
        # There is no name for some component
        if value == u'坐标':
            event.touch(int(x), int(y))
        else:
            ele = element.findElementByName(value)
            if ele is not None:
                event.touch(abs(ele[0] - int(x)), abs(ele[1] - int(y)))
                sleep(2)
    # return to HOME
    DEVICE.send_keyevent(3)
Example #10
0
def verify_login_pkg_content(dname, contents):

    DEVICE = device.Device(dname)
    verify_node = [
        'uid', 'lockscreen_id', 'wallpaper_id', 'mac', 'platform', 'product',
        'product_soft', 'promotion'
    ]
    #verify_node = ['uid','lockscreen_id','wallpaper_id','imei','mac','platform','product','promotion']
    find_node = []
    filter_result = {}

    data = pXml.parseXml(contents)
    for name in verify_node:
        try:
            if name == 'platform':
                value = data.get_elements_attribute_value(name, 'version')[0]
            elif name == 'product_soft':
                value = data.get_elements_attribute_value(name, 'soft')[0]
            else:
                value = data.get_elements_text(name)[0]
            filter_result[name] = value
            find_node.append(name)
        except Exception, ex:
            continue
Example #11
0
    newParser = argparse.ArgumentParser()
    newParser.add_argument("-u", "--uid", dest="uid", help="Your device uid")

    args = newParser.parse_args()
    uid = args.uid

    if uid is None:
        sys.exit(0)

    # verify if device is connected
    devices = device.Device.get_connected_devices()
    if uid not in devices:
        print "Device is not connected, please check"
        sys.exit(0)

    my_device = device.Device(uid)
    logname = desktop.get_log_name(uid, 'verify.html')

    # create test log
    if not os.path.exists(logname):
        write_html_header(logname, 'Verify Advertisement')
    my_logger = log.Log(logname)

    #start_service()

    loop_number = 0
    TestFlag = True
    dtime = CONFIG.getValue('Common', 'duration')
    dtime = 300

    # start-up service and monitor logcat