def add_web_add_header(self, value_web_add_header, headtagname, level, headenHash, tailenHash, transaction_start_count, doc):
        try:
            t = xmlgen.extract_latesttag(headtagname, int(level))
            if int(headenHash) == 1:
                t = xmlgen.addStringprop_noparam(t, 'hashTree')
            Hr_m = xmlgen.addelement_withparam(t, "HeaderManager", "HeaderPanel", "HeaderManager", "HTTP Header Manager",
                                               "true")
            Hr_c = xmlgen.addStringprop_noparam(Hr_m, "collectionProp", "HeaderManager.headers")

            for i in range(0, len(value_web_add_header)):
                Hr_c1 = xmlgen.addelement_withparam(Hr_c, "elementProp", "", "Header")
                xmlgen.addprop_withparam(Hr_c1, "stringProp", "Header.name",
                                             str(value_web_add_header[i][0].replace("\"", "")).strip())
                xmlgen.addprop_withparam(Hr_c1, "stringProp", "Header.value",
                                             str(value_web_add_header[i][1].replace("\"", "")).strip())

            self.value_web_add_header[:] = []

            if int(tailenHash) == 1:
                xmlgen.addStringprop_noparam(t, 'hashTree')

            return headtagname, level - 1 , headenHash, tailenHash, transaction_start_count, doc
        except Exception as e:
            print "error in add_web_add_header : " + str(e)
    def web_custom_request(self, variable, headtagname, level, headenHash, tailenHash, transaction_start_count, doc):
        headenHash = 0
        tailenHash = 1

        (xml_objects, headtagname, level, headenHash, tailenHash, transaction_start_count,
         doc) = self.common_web_url_submit_link(variable, headtagname, level, headenHash, tailenHash,
                                                transaction_start_count, doc)

        try:
            if len(str(variable[1]['Body'])) > 0:
                xmlgen.addprop_withparam(xml_objects[1], "boolProp", "HTTPSampler.postBodyRaw", "true")
                Hr_m1 = xmlgen.addelement_withparam(xml_objects[1], "elementProp", "HTTPsampler.Arguments", "Arguments")
                Hr_c = xmlgen.addStringprop_noparam(Hr_m1, "collectionProp", "Arguments.arguments")
                Hr_c1 = xmlgen.addelement_withparam(Hr_c, "elementProp", "", "HTTPArgument")
                xmlgen.addprop_withparam(Hr_c1, "boolProp", "HTTPArgument.always_encode", "false")
                xmlgen.addprop_withparam(Hr_c1, "stringProp", "Argument.value", escape(str(variable[1]['Body']).replace("\\\"", "\"")))
                xmlgen.addprop_withparam(Hr_c1, "stringProp", "Argument.metadata", "=")
        except Exception as e:
            xmlgen.addprop_withparam(xml_objects[1], "boolProp", "HTTPSampler.postBodyRaw", "true")
            Hr_m1 = xmlgen.addelement_withparam(xml_objects[1], "elementProp", "HTTPsampler.Arguments", "Arguments")
            Hr_c = xmlgen.addStringprop_noparam(xml_objects[1], "collectionProp", "Arguments.arguments")
            Hr_c1 = xmlgen.addelement_withparam(Hr_c, "elementProp", "", "HTTPArgument")
            xmlgen.addprop_withparam(Hr_c1, "boolProp", "HTTPArgument.always_encode", "false")
            xmlgen.addprop_withparam(Hr_c1, "stringProp", "Argument.value", "")
            xmlgen.addprop_withparam(Hr_c1, "stringProp", "Argument.metadata", "=")

        (xml_objects, headtagname, level, headenHash, tailenHash, transaction_start_count,
         doc) = self.common_web_url_submit_link_closing(xml_objects, variable, headtagname, level, headenHash,
                                                        tailenHash, transaction_start_count, doc)
        return headtagname, level, headenHash, tailenHash, transaction_start_count, doc
    def web_submit_data_adding_variables(self, xml_objects, variable, pos_string, doc):
        Hr_c1 = xmlgen.addStringprop_noparam(xml_objects[2], "elementProp",
                                             escape(variable[1]["Value" + str(pos_string)]),
                                             "HTTPArgument")
        xmlgen.addprop_withparam(Hr_c1, "boolProp", "HTTPArgument.always_encode", "false")
        xmlgen.addprop_withparam(Hr_c1, "boolProp", "HTTPArgument.use_equals", "true")
        xmlgen.addprop_withparam(Hr_c1, "stringProp", "Argument.value",
                                 escape(variable[1]["Value" + str(pos_string)]))
        xmlgen.addprop_withparam(Hr_c1, "stringProp", "Argument.metadata", "=")
        xmlgen.addprop_withparam(Hr_c1, "stringProp", "Argument.name",
                                 escape(variable[1]["Name" + str(pos_string)]))
        xmlgen.addprop_withparam(xml_objects[1], "boolProp", "HTTPSampler.monitor", "false")

        return xml_objects, variable, pos_string, doc
    def add_web_reg_save_param(self, value_web_reg_save_param, headtagname, level, headenHash, tailenHash, transaction_start_count, doc):
        name = ""
        expression_capture_value = ""

        t = xmlgen.extract_latesttag(headtagname, level)

        for items in range(0, len(value_web_reg_save_param)):
            if int(items) == "0":
                h1 = xmlgen.addStringprop_noparam(t, 'hashTree')
            else:
                h1 = t

            try:
                name = str(value_web_reg_save_param[items]['ParamName'])
            except Exception as e:
                name = str(value_web_reg_save_param[items]['web_reg_save_param'])
            if len(name) < 1:
                print "Something went wrong in capturing name for web_reg_save_param !!! name cannot be empty : " + str(value_web_reg_save_param)

            try:
                captured_ordinal = value_web_reg_save_param[items]['Ordinal'].strip()
            except Exception as e:
                try:
                    captured_ordinal = value_web_reg_save_param[items]['Ord'].strip()
                except Exception as e:
                    print "Error while calculating Ordinal : " + str(e)
                    captured_ordinal = "1"

            if "ALL" in captured_ordinal.upper():
                ordinal = "-1"
            elif captured_ordinal.isdigit():
                ordinal = captured_ordinal
            else:
                ordinal = "1"

            try:
                if len(value_web_reg_save_param[items]['LB/IC']) > 1 or len(value_web_reg_save_param[items]['RB/IC']) > 1:
                    expression_capture_value = str(value_web_reg_save_param[items]['LB/IC']) + "(.*?)" + str(value_web_reg_save_param[items]['RB/IC'])
                else:
                    print "either of LB/IC or RB/IC is empty"
                    expression_capture_value = ""
            except Exception:
                try:
                    if len(value_web_reg_save_param[items]['LB']) > 1 or len(value_web_reg_save_param[items]['RB']) > 1:
                        expression_capture_value = str(value_web_reg_save_param[items]['LB']) + "(.*?)" + str(value_web_reg_save_param[items]['RB'])
                    else:
                        print "either of LB/IC or RB/IC is empty"
                        expression_capture_value = ""
                except Exception as e:
                    try:
                        if len(value_web_reg_save_param[items]['RegExp']) > 1:
                            expression_capture_value = str(value_web_reg_save_param[items]['RegExp'])
                        else:
                            print "Seems RegExp is empty"
                            expression_capture_value = ""
                    except Exception as e:
                        print e
                        print "Cannot create regular expression for : " + str(value_web_reg_save_param[items])

            self.parameters_list.append(name)

            rex_m = xmlgen.addelement_withparam(h1, "RegexExtractor", "RegexExtractorGui", "RegexExtractor", name,
                                                "true")
            xmlgen.addprop_withparam(rex_m, "stringProp", "RegexExtractor.useHeaders", "false")
            xmlgen.addprop_withparam(rex_m, "stringProp", "RegexExtractor.refname", str(name))
            xmlgen.addprop_withparam(rex_m, "stringProp", "RegexExtractor.regex", escape(expression_capture_value).replace("\\",""))
            xmlgen.addprop_withparam(rex_m, "stringProp", "RegexExtractor.template", "$1$")
            xmlgen.addprop_withparam(rex_m, "stringProp", "RegexExtractor.default", "NOT_FOUND")
            xmlgen.addprop_withparam(rex_m, "stringProp", "RegexExtractor.match_number", str(ordinal))
            xmlgen.addStringprop_noparam(h1, 'hashTree')
        self.value_web_reg_save_param[:] = []
        return headtagname, level - 1, headenHash, tailenHash, transaction_start_count, doc
    def common_web_url_submit_link_closing(self, xml_objects, variable, headtagname, level, headenHash, tailenHash,
                                       transaction_start_count, doc):
        try:
            method_type = variable[1]['Method']
        except Exception as e:
            method_type = "GET"

        try:
            if 'Action' in variable[1].keys():
                path = variable[1]['Action']
            elif 'URL' in variable[1].keys():
                path = variable[1]['URL']
            else:
                path = "NOT_FOUND"
                print "Please verify - cannot find path in " + str(variable)
        except Exception as e:
            path = "NOT_FOUND"
            print "Please verify - cannot find path in " + str(variable)


        t = xml_objects[0]
        Hr_m = xml_objects[1]
        xmlgen.addprop_withparam(Hr_m, "stringProp", "HTTPSampler.domain", "")
        xmlgen.addprop_withparam(Hr_m, "stringProp", "HTTPSampler.port", "")
        xmlgen.addprop_withparam(Hr_m, "stringProp", "HTTPSampler.connect_timeout", "")
        xmlgen.addprop_withparam(Hr_m, "stringProp", "HTTPSampler.response_timeout", "")
        xmlgen.addprop_withparam(Hr_m, "stringProp", "HTTPSampler.protocol", "")
        xmlgen.addprop_withparam(Hr_m, "stringProp", "HTTPSampler.contentEncoding", "")
        xmlgen.addprop_withparam(Hr_m, "stringProp", "HTTPSampler.method", method_type)
        xmlgen.addprop_withparam(Hr_m, "stringProp", "HTTPSampler.path", escape(path))
        xmlgen.addprop_withparam(Hr_m, "stringProp", "HTTPSampler.embedded_url_re", "")
        xmlgen.addprop_withparam(Hr_m, "boolProp", "HTTPSampler.follow_redirects", "true")
        xmlgen.addprop_withparam(Hr_m, "boolProp", "HTTPSampler.auto_redirects", "false")
        xmlgen.addprop_withparam(Hr_m, "boolProp", "HTTPSampler.use_keepalive", "true")
        xmlgen.addprop_withparam(Hr_m, "boolProp", "HTTPSampler.DO_MULTIPART_POST", "false")

        if int(tailenHash) == 1:
            xmlgen.addStringprop_noparam(t, 'hashTree')

        return [Hr_m], headtagname, level, headenHash, tailenHash, transaction_start_count, doc