Exemple #1
0
    def __init_webtest_opt(self, params):
        """init the test runtime, mainly process the star up of test stub"""
        if params is None:
            return None

        session_id = str(uuid.uuid1())
        stub_app = params.get('stub-name', 'testkit-stub')
        stub_port = params.get('stub-port', '8000')
        testsuite_name = params.get('testsuite-name', '')
        testset_name = params.get('testset-name', '')
        capability_opt = params.get("capability", None)
        test_launcher = params.get('test-launcher', '')
        test_extension = params.get('test-extension', None)
        test_widget = params.get('test-widget', None)

        test_opt = self.conn.get_launcher_opt(
            test_launcher, test_extension, test_widget, testsuite_name, testset_name)
        if test_opt is None:
            LOGGER.info("[ init the test launcher, get failed ]")
            return None
        LOGGER.info("[ web test launcher: %s ]" % test_opt["launcher"])
        LOGGER.info("[ web test app: %s ]" % test_opt["test_app_id"])
        self.opts.update(test_opt)
        self.opts['debug_mode'] = params.get("debug", False)

        # uifw, this suite don't need stub
        if self.opts['self_exec'] or self.opts['self_repeat']:
            self.opts['test_type'] = "jqunit"
            return session_id

        # enable debug information
        stub_debug_opt = "--debug" if self.opts['debug_mode'] else ""

        # suite_id to be removed in later version
        test_opt["suite_id"] = test_opt["test_app_id"]
        if self.__init_test_stub(stub_app, stub_port, stub_debug_opt):
            ret = http_request(get_url(
                self.server_url, "/init_test"), "POST", test_opt)
            if ret is None:
                LOGGER.info("[ init test suite failed! ]")
                return None
            elif "error_code" in ret:
                LOGGER.info("[ init test suite, "
                            "get error code %d ! ]" % ret["error_code"])
                return None

            if capability_opt is not None:
                ret = http_request(get_url(self.server_url,
                                           "/set_capability"),
                                   "POST", capability_opt)
            return session_id
        else:
            LOGGER.info("[ Init test failed ! ]")
            return None
Exemple #2
0
    def __init_webtest_opt(self, params):
        """init the test runtime, mainly process the star up of test stub"""
        if params is None:
            return None

        session_id = str(uuid.uuid1())
        stub_app = params.get('stub-name', 'testkit-stub')
        stub_port = params.get('stub-port', '8000')
        testsuite_name = params.get('testsuite-name', '')
        testset_name = params.get('testset-name', '')
        capability_opt = params.get("capability", None)
        test_launcher = params.get('test-launcher', '')
        test_extension = params.get('test-extension', None)
        test_widget = params.get('test-widget', None)

        test_opt = self.conn.get_launcher_opt(test_launcher, test_extension,
                                              test_widget, testsuite_name,
                                              testset_name)
        if test_opt is None:
            LOGGER.info("[ init the test launcher, get failed ]")
            return None
        LOGGER.info("[ web test launcher: %s ]" % test_opt["launcher"])
        LOGGER.info("[ web test app: %s ]" % test_opt["test_app_id"])
        self.opts.update(test_opt)
        self.opts['debug_mode'] = params.get("debug", False)

        # uifw, this suite don't need stub
        if self.opts['self_exec'] or self.opts['self_repeat']:
            self.opts['test_type'] = "jqunit"
            return session_id

        # enable debug information
        stub_debug_opt = "--debug" if self.opts['debug_mode'] else ""

        # suite_id to be removed in later version
        test_opt["suite_id"] = test_opt["test_app_id"]
        if self.__init_test_stub(stub_app, stub_port, stub_debug_opt):
            ret = http_request(get_url(self.server_url, "/init_test"), "POST",
                               test_opt)
            if ret is None:
                LOGGER.info("[ init test suite failed! ]")
                return None
            elif "error_code" in ret:
                LOGGER.info("[ init test suite, "
                            "get error code %d ! ]" % ret["error_code"])
                return None

            if capability_opt is not None:
                ret = http_request(get_url(self.server_url, "/set_capability"),
                                   "POST", capability_opt)
            return session_id
        else:
            LOGGER.info("[ Init test failed ! ]")
            return None
Exemple #3
0
    def __init_test_stub(self, stub_app, stub_port, debug_opt):
        # init testkit-stub deamon process
        timecnt = 0
        blaunched = False
        while timecnt < CNT_RETRY:
            #print 'stub_app' ,stub_app
            if not self.conn.check_process(stub_app):
                LOGGER.info("[ no stub process activated, now try to launch %s ]" % stub_app)
                self.conn.launch_stub(stub_app, stub_port, debug_opt)
                timecnt += 1
            else:
                blaunched = True
                break

        if not blaunched:
            LOGGER.info("[ launch stub process failed! ]")
            return False

        if self.server_url is None:
            self.server_url = self.conn.get_server_url(stub_port)

        timecnt = 0
        blaunched = False
        while timecnt < CNT_RETRY:
            ret = http_request(get_url(
                self.server_url, "/check_server_status"), "GET", {})
            if ret is None:
                LOGGER.info("[ check server status, not ready yet! ]")
                timecnt += 1
                time.sleep(1)
            else:
                blaunched = True
                break
        return blaunched
Exemple #4
0
    def __init_test_stub(self, stub_app, stub_port, debug_opt):
        # init testkit-stub deamon process
        timecnt = 0
        blaunched = False
        while timecnt < CNT_RETRY:
            if not self.conn.check_process(stub_app):
                LOGGER.info(
                    "[ no stub process activated, now try to launch %s ]" %
                    stub_app)
                self.conn.launch_stub(stub_app, stub_port, debug_opt)
                timecnt += 1
            else:
                blaunched = True
                break

        if not blaunched:
            LOGGER.info("[ launch stub process failed! ]")
            return False

        if self.server_url is None:
            self.server_url = self.conn.get_server_url(stub_port)

        timecnt = 0
        blaunched = False
        while timecnt < CNT_RETRY:
            ret = http_request(
                get_url(self.server_url, "/check_server_status"), "GET", {})
            if ret is None:
                LOGGER.info("[ check server status, not ready yet! ]")
                timecnt += 1
                time.sleep(1)
            else:
                blaunched = True
                break
        return blaunched
Exemple #5
0
 def kill_app(self, wgt_name):
     cmd_json = {}
     cmd_json['cmd'] = KILL_XWALK
     server_url = "http://%s:8000" % self.deviceip
     ret = http_request(get_url(server_url, "/execute_async_cmd"), "POST",
                        cmd_json, 30)
     time.sleep(3)
     return True
 def kill_app(self, wgt_name):
     cmd_json = {}
     cmd_json['cmd'] = KILL_XWALK
     server_url = "http://%s:8000" % self.deviceip
     ret = http_request(
         get_url(server_url, "/execute_async_cmd"), "POST", cmd_json, 30)
     time.sleep(3)
     return True
Exemple #7
0
 def launch_stub(self, stub_app, stub_port="8000", debug_opt=""):
     stub_status = False
     server_url = "http://%s:9000" % self.deviceip
     ret = http_request(get_url(server_url, "/launch_stub"), "GET", {})
     if ret is None:
         LOGGER.error(
             "[ ERROR: get server status timeout, please check deivce! ]")
     else:
         if ret.get("OK") is not None:
             stub_status = True
     return stub_status
 def kill_stub(self):
     stub_status = False
     server_url = "http://%s:9000" % self.deviceip
     ret = http_request(
         get_url(server_url, "/kill_stub"), "GET", {})
     if ret is None:
         LOGGER.error("[ ERROR: get server status timeout, please check deivce! ]")
     else: 
         if ret.get("OK") is not None:
             stub_status = True
     return stub_status
 def launch_stub(self, stub_app, stub_port="8000", debug_opt=""):
     stub_status = False
     server_url = "http://%s:9000" % self.deviceip
     ret = http_request(
         get_url(server_url, "/launch_stub"), "GET", {})
     if ret is None:
         LOGGER.error("[ ERROR: get server status timeout, please check deivce! ]")
     else: 
         if ret.get("OK") is not None:
             stub_status = True
     return stub_status
Exemple #10
0
 def kill_stub(self):
     stub_status = False
     server_url = "http://%s:9000" % self.deviceip
     ret = http_request(get_url(server_url, "/kill_stub"), "GET", {})
     if ret is None:
         LOGGER.error(
             "[ ERROR: get server status timeout, please check deivce! ]")
     else:
         if ret.get("OK") is not None:
             stub_status = True
     return stub_status
Exemple #11
0
    def launch_app(self, wgt_name, extension=None):
        blauched = False
        cmdline = LAUNCH_XWALK % (wgt_name, wgt_name, wgt_name)
        if extension is not None:
            cmdline = LAUNCH_XWALK_EXTENSIONS % (wgt_name, wgt_name, wgt_name, wgt_name, extension)
        cmd_json = {}
        cmd_json['cmd'] = cmdline
        server_url = "http://%s:8000" % self.deviceip
        ret = http_request(
            get_url(server_url, "/execute_async_cmd"), "POST", cmd_json, 30)
        time.sleep(3)

        cmdline = QUERY_XWALK
        cmd_json['cmd'] = cmdline
        ret = http_request(
            get_url(server_url, "/execute_cmd"), "POST", cmd_json, 30)
        if ret and len(ret):
            blauched = True
        LOGGER.info("[ Launch test cases launcher: %s" % blauched);
        return blauched
Exemple #12
0
    def launch_app(self, wgt_name, extension=None):
        blauched = False
        cmdline = LAUNCH_XWALK % (wgt_name, wgt_name, wgt_name)
        if extension is not None:
            cmdline = LAUNCH_XWALK_EXTENSIONS % (wgt_name, wgt_name, wgt_name,
                                                 wgt_name, extension)
        cmd_json = {}
        cmd_json['cmd'] = cmdline
        server_url = "http://%s:8000" % self.deviceip
        ret = http_request(get_url(server_url, "/execute_async_cmd"), "POST",
                           cmd_json, 30)
        time.sleep(3)

        cmdline = QUERY_XWALK
        cmd_json['cmd'] = cmdline
        ret = http_request(get_url(server_url, "/execute_cmd"), "POST",
                           cmd_json, 30)
        if ret and len(ret):
            blauched = True
        LOGGER.info("[ Launch test cases launcher: %s" % blauched)
        return blauched
Exemple #13
0
 def check_process(self, process_name):
     stub_status = 0
     server_url = "http://%s:9000" % self.deviceip
     LOGGER.error("[ Server URL: %s]" % server_url)
     ret = http_request(get_url(server_url, "/check_stub"), "GET", {})
     if ret is None:
         LOGGER.error(
             "[ ERROR: get server status timeout, please check deivce! ]")
     else:
         if ret.get("OK") is not None:
             stub_status = 1
     return stub_status
Exemple #14
0
 def check_process(self, process_name):
     stub_status = 0       
     server_url = "http://%s:9000" % self.deviceip
     LOGGER.error("[ Server URL: %s]" % server_url)
     ret = http_request(
         get_url(server_url, "/check_stub"), "GET", {})
     if ret is None:
         LOGGER.error("[ ERROR: get server status timeout, please check deivce! ]")
     else: 
         if ret.get("OK") is not None:
             stub_status = 1
     return stub_status
Exemple #15
0
 def shell_cmd_ext(self,
                   cmd="",
                   timeout=None,
                   boutput=False,
                   stdout_file=None,
                   stderr_file=None):
     check_stub_num = 0
     while (not self.check_process("")) and check_stub_num < 3:
         self.launch_stub("")
         check_stub_num += 1
         time.sleep(3)
     cmd_json = {}
     cmd_json['cmd'] = cmd
     server_url = "http://%s:8000" % self.deviceip
     result = http_request(get_url(server_url, "/general_cmd_response"),
                           "POST", cmd_json, 30)
     if result is not None:
         LOGGER.info("Response exit_code: %s" % result["exit_code"])
         LOGGER.info("Response output: %s" % result["output"])
         time.sleep(1)
         return [int(result["exit_code"]), result["output"], []]
     else:
         LOGGER.info("Fail to connect stub!")
         return [-1, ["Fail to connect stub"], []]
Exemple #16
0
 def shell_cmd_ext(self,
                   cmd="",
                   timeout=None,
                   boutput=False,
                   stdout_file=None,
                   stderr_file=None):
     check_stub_num = 0
     while (not self.check_process("")) and check_stub_num < 3:
         self.launch_stub("")
         check_stub_num += 1
         time.sleep(3)
     cmd_json = {}
     cmd_json['cmd'] = cmd
     server_url = "http://%s:8000" % self.deviceip
     result = http_request(
         get_url(server_url, "/general_cmd_response"), "POST", cmd_json, 30)
     if result is not None:
         LOGGER.info("Response exit_code: %s" % result["exit_code"])
         LOGGER.info("Response output: %s" % result["output"])
         time.sleep(1)
         return [int(result["exit_code"]), result["output"], []]
     else:
         LOGGER.info("Fail to connect stub!")
         return [-1, ["Fail to connect stub"], []]
Exemple #17
0
def _web_test_exec(conn, server_url, test_web_app, exetype, cases_queue,
                   result_obj):
    """function for running web tests"""
    exetype = exetype.lower()
    test_set_finished = False
    err_cnt = 0
    for test_group in cases_queue:
        if test_set_finished:
            break

        ret = http_request(get_url(server_url, "/set_testcase"), "POST",
                           test_group, 30)
        if ret is None:
            LOGGER.error("[ set testcases timeout, please check device! ]")
            result_obj.set_status(1)
            break

        if not conn.launch_app(test_web_app):
            LOGGER.error("[ ERROR: launch test app %s failed! ]" %
                         test_web_app)
            result_obj.set_status(1)
            break

        while True:
            if result_obj.get_status() == 1:
                test_set_finished = True
                break
            ret = http_request(get_url(server_url, "/check_server_status"),
                               "GET", {})
            if ret is None:
                LOGGER.error(
                    "[ ERROR: get server status timeout, please check deivce! ]"
                )
                err_cnt += 1
            else:
                result_cases = ret.get("cases")
                error_code = ret.get("error_code")
                if error_code is not None:
                    if not conn.launch_app(test_web_app):
                        test_set_finished = True
                        result_obj.set_status(1)
                        break
                    if error_code == LAUNCH_ERROR:
                        LOGGER.error(
                            "[ ERROR: test app no response, hang or not launched! ]"
                        )
                        test_set_finished = True
                        result_obj.set_status(1)
                        break
                    elif error_code == BLOCK_ERROR:
                        LOGGER.error("[ ERROR: test case block issue! ]")
                        err_cnt += 1
                else:
                    err_cnt = 0

                if result_cases is not None and len(result_cases):
                    result_obj.extend_result(result_cases)
                elif exetype == 'manual':
                    LOGGER.info("[ please execute manual cases ]\r\n")

                if ret["finished"] == 1:
                    test_set_finished = True
                    result_obj.set_status(1)
                    break
                elif ret["block_finished"] == 1:
                    break

            if err_cnt >= CNT_RETRY:
                LOGGER.error(
                    "[ ERROR: get too many errors, stop current set! ]")
                test_set_finished = True
                result_obj.set_status(1)
                break
            time.sleep(2)
Exemple #18
0
def _web_test_exec(conn, server_url, test_web_app, exetype, cases_queue, result_obj):
    """function for running web tests"""
    print 'test_web_app', test_web_app
    exetype = exetype.lower()
    test_set_finished = False
    err_cnt = 0
    for test_group in cases_queue:
        if test_set_finished:
            break

        ret = http_request(
            get_url(server_url, "/set_testcase"), "POST", test_group, 30)
        if ret is None:
            LOGGER.error(
                "[ set testcases timeout, please check device! ]")
            result_obj.set_status(1)
            break

        if not conn.launch_app(test_web_app):
            LOGGER.error("[ ERROR: launch test app %s failed! ]" % test_web_app)
            result_obj.set_status(1)
            break

        while True:
            if result_obj.get_status() == 1:
                test_set_finished = True
                break
            ret = http_request(
                get_url(server_url, "/check_server_status"), "GET", {})
            if ret is None:
                LOGGER.error(
                    "[ ERROR: get server status timeout, please check deivce! ]")
                err_cnt += 1
            else:
                result_cases = ret.get("cases")
                error_code = ret.get("error_code")
                if error_code is not None:
                    if not conn.launch_app(test_web_app):
                        test_set_finished = True
                        result_obj.set_status(1)
                        break
                    if error_code == LAUNCH_ERROR:
                        LOGGER.error("[ ERROR: test app no response, hang or not launched! ]")
                        test_set_finished = True
                        result_obj.set_status(1)
                        break
                    elif error_code == BLOCK_ERROR:
                        LOGGER.error("[ ERROR: test case block issue! ]")
                        err_cnt += 1
                else:
                    err_cnt = 0

                if result_cases is not None and len(result_cases):
                    result_obj.extend_result(result_cases)
                elif exetype == 'manual':
                    LOGGER.info(
                        "[ please execute manual cases ]\r\n")

                if ret["finished"] == 1:
                    test_set_finished = True
                    result_obj.set_status(1)
                    break
                elif ret["block_finished"] == 1:
                    break

            if err_cnt >= CNT_RETRY:
                LOGGER.error(
                    "[ ERROR: get too many errors, stop current set! ]")
                test_set_finished = True
                result_obj.set_status(1)
                break
            time.sleep(2)