def get_sampler_pair(self, request): action = etree.Element( "com.blazemeter.jmeter.rte.sampler.RTESampler", guiclass="com.blazemeter.jmeter.rte.sampler.gui.RTESamplerGui", testclass="com.blazemeter.jmeter.rte.sampler.", testname=request.label) action.append( JMX._string_prop("RTESampler.action", request.config.get('rte-action'))) if "wait-for" in request.config: self._gen_wait(action, request.config.get("wait-for")) if 'fields' in request.config: inputs = JMX._collection_prop("Inputs.inputs") for _input in request.config["fields"]: inputs.append(self._gen_input_prop(_input)) elem_props = JMX._element_prop( "Inputs.inputs", "com.blazemeter.jmeter.rte.sampler.Inputs") elem_props.append(inputs) action.append(elem_props) if 'attention-key' in request.config: action.append( JMX._string_prop("RTESampler.attentionKey", request.config.get('attention-key'))) children = etree.Element("hashTree") if 'extract-cursor-position' in request.config and request.config.get( 'extract-cursor-position'): element = request.config.get('extract-cursor-position') extractor = self._gen_rte_extractor(element['varname'], "CURSOR_POSITION") children.append(extractor) children.append( etree.Element("hashTree") ) # Is this an RTE extension bug? doesn't seem necesary, # but won't work without it. if 'extract-field-position' in request.config and request.config.get( 'extract-field-position'): element = request.config.get('extract-field-position') position = element['base-position'].strip("()") row, column = position.split(",") offset = element['field-offset'] extractor = self._gen_rte_extractor(element['varname'], "NEXT_FIELD_POSITION", row, column, offset) children.append(extractor) children.append(etree.Element("hashTree")) return action, children
def _gen_rte_extractor(varname, type, row="", column="", offset=""): extractor = etree.Element( "com.blazemeter.jmeter.rte.extractor.RTEExtractor", guiclass="com.blazemeter.jmeter.rte.extractor.RTEExtractorGui", testclass="com.blazemeter.jmeter.rte.extractor.RTEExtractor", testname="Cursor extractor") extractor.append( JMX._string_prop("RTEExtractor.variablePrefix", varname)) extractor.append(JMX._string_prop("RTEExtractor.positionType", type)) extractor.append(JMX._string_prop("RTEExtractor.row", row)) extractor.append(JMX._string_prop("RTEExtractor.offset", offset)) extractor.append(JMX._string_prop("RTEExtractor.column", column)) return extractor
def _gen_input_prop(_input): row, col, label, text = RTEProtocolHandler._handle_input_notaiton( _input) if row and col: prop = JMX._element_prop( "elementProp", "com.blazemeter.jmeter.rte.sampler.CoordInputRowGUI") prop.append(JMX._string_prop("CoordInputRowGUI.row", row)) prop.append(JMX._string_prop("CoordInputRowGUI.column", col)) elif label: prop = JMX._element_prop( "elementProp", "com.blazemeter.jmeter.rte.sampler.LabelInputRowGUI") prop.append(JMX._string_prop("LabelInputRowGUI.label", label)) prop.append(JMX._string_prop("Input.input", text)) return prop
def _get_publish_sampler(request): mqtt = etree.Element("net.xmeter.samplers.PubSampler", guiclass="net.xmeter.gui.PubSamplerUI", testclass="net.xmeter.samplers.PubSampler", testname=request.label) topic_missed = TaurusConfigError( f'Topic is required for request "{request.config}"') mqtt.append( JMX._string_prop("mqtt.topic_name", request.config.get("topic", topic_missed))) mqtt.append(JMX._string_prop("mqtt.qos_level", "0")) mqtt.append(JMX._bool_prop("mqtt.add_timestamp", True)) mqtt.append(JMX._string_prop("mqtt.message_type", "String")) mqtt.append(JMX._string_prop("mqtt.message_type_fixed_length", "1024")) mqtt.append( JMX._string_prop("mqtt.message_to_sent", request.config.get("message", ""))) mqtt.append(JMX._bool_prop("mqtt.retained_message", False)) return mqtt
def _gen_server_config(self, scenario): cfg = etree.Element( "ConfigTestElement", guiclass="com.blazemeter.jmeter.rte.sampler.gui.RTEConfigGui", testclass="ConfigTestElement", testname="Server Config") data = scenario.data server = data.get("rte-server").split(":") if server: cfg.append( JMX._string_prop("%sserver" % RTE_CONNECTION_CONFIG_, server[0])) cfg.append( JMX._string_prop("%sport" % RTE_CONNECTION_CONFIG_, server[1])) if len(server) > 1 else None cfg.append(JMX._string_prop("%sprotocol" % RTE_CONNECTION_CONFIG_, data['rte-protocol'])) if 'rte-protocol' in data \ else None if 'rte-config' in data: config = data.get('rte-config') cfg.append( JMX._string_prop("%ssslType" % RTE_CONNECTION_CONFIG_, config['ssl'])) if 'ssl' in config else None cfg.append(JMX._string_prop("%sterminalType" % RTE_CONNECTION_CONFIG_, config['terminal-type'])) if \ 'terminal-type' in config else None connection_timeout = self.safe_time(config['connection-timeout']) cfg.append(JMX._string_prop("%sconnectTimeout" % RTE_CONNECTION_CONFIG_, connection_timeout)) if \ 'connection-timeout' in config else None return [cfg, etree.Element("hashTree")]
def _gen_input_prop(_input): row, col, label, text, tabs = RTEProtocolHandler._handle_input_notation( _input) if row and col: prop = JMX._element_prop( "elementProp", "com.blazemeter.jmeter.rte.sampler.CoordInputRowGUI") prop.append(JMX._string_prop("CoordInputRowGUI.row", row)) prop.append(JMX._string_prop("CoordInputRowGUI.column", col)) elif label: prop = JMX._element_prop( "elementProp", "com.blazemeter.jmeter.rte.sampler.LabelInputRowGUI") prop.append(JMX._string_prop("LabelInputRowGUI.label", label)) elif tabs is not None: prop = JMX._element_prop( "elementProp", "com.blazemeter.jmeter.rte.sampler.TabulatorInputRowGui") prop.append( JMX._string_prop("TabulatorInputOffsetGUI.column", tabs)) prop.append(JMX._string_prop("Input.input", text)) return prop
def _get_subscribe_sampler(request): mqtt = etree.Element("net.xmeter.samplers.SubSampler", guiclass="net.xmeter.gui.SubSamplerUI", testclass="net.xmeter.samplers.SubSampler", testname=request.label) topic_missed = TaurusConfigError( f'Topic is required for request "{request.config}"') time_interval = int(dehumanize_time(request.config.get("time", 1))) mqtt.append( JMX._string_prop("mqtt.topic_name", request.config.get("topic", topic_missed))) mqtt.append(JMX._string_prop("mqtt.qos_level", "0")) mqtt.append(JMX._bool_prop("mqtt.add_timestamp", False)) mqtt.append(JMX._bool_prop("mqtt.debug_response", False)) mqtt.append( JMX._string_prop("mqtt.sample_condition", "specified elapsed time (ms)")) mqtt.append( JMX._string_prop("mqtt.sample_condition_value", str(time_interval * 1000))) return mqtt
def _gen_server_config(self, config_data): config = etree.Element( "ConfigTestElement", guiclass="com.blazemeter.jmeter.rte.sampler.gui.RTEConfigGui", testclass="ConfigTestElement", testname="Server Config") if "rte-server" in config_data: server = config_data.get("rte-server").split(":") config.append( JMX._string_prop("RTEConnectionConfig.server", server[0])) if len(server) > 1: config.append( JMX._string_prop("RTEConnectionConfig.port", server[1])) if 'rte-protocol' in config_data: config.append( JMX._string_prop("RTEConnectionConfig.protocol", config_data['rte-protocol'])) if 'rte-config' in config_data: rte_config = config_data.get('rte-config') if 'ssl' in rte_config: config.append( JMX._string_prop("RTEConnectionConfig.sslType", rte_config['ssl'])) if 'terminal-type' in rte_config: config.append( JMX._string_prop("RTEConnectionConfig.terminalType", rte_config['terminal-type'])) if 'connection-timeout' in rte_config: connection_timeout = self.safe_time( rte_config['connection-timeout']) config.append( JMX._string_prop("RTEConnectionConfig.connectTimeout", connection_timeout)) return [config, etree.Element("hashTree")]
def _get_connect_sampler(request): mqtt = etree.Element("net.xmeter.samplers.ConnectSampler", guiclass="net.xmeter.gui.ConnectSamplerUI", testclass="net.xmeter.samplers.ConnectSampler", testname=request.label) mqtt.append( JMX._string_prop("mqtt.server", request.config.get("addr", "127.0.0.1"))) mqtt.append(JMX._string_prop("mqtt.port", "1883")) mqtt.append(JMX._string_prop("mqtt.version", "3.1")) mqtt.append(JMX._string_prop("mqtt.conn_timeout", "10")) mqtt.append(JMX._string_prop("mqtt.protocol", "TCP")) mqtt.append(JMX._string_prop("mqtt.ws_path", "")) mqtt.append(JMX._bool_prop("mqtt.dual_ssl_authentication", False)) mqtt.append(JMX._string_prop("mqtt.clientcert_file_path", "")) mqtt.append(JMX._string_prop("mqtt.clientcert_password", "")) mqtt.append(JMX._string_prop("mqtt.client_id_prefix", "conn_")) mqtt.append(JMX._bool_prop("mqtt.client_id_suffix", True)) mqtt.append(JMX._string_prop("mqtt.conn_keep_alive", "300")) mqtt.append(JMX._string_prop("mqtt.conn_attampt_max", "0")) mqtt.append(JMX._string_prop("mqtt.reconn_attampt_max", "0")) mqtt.append(JMX._string_prop("mqtt.conn_clean_session", "true")) return mqtt
def _gen_wait(self, action, wait_for): action.append( JMX._bool_prop("%swaitSync" % RTE_SAMPLER_, 'sync' in wait_for)) if 'sync' in wait_for: sync_timeout = self.safe_time(wait_for['sync']) action.append( JMX._string_prop("%swaitSyncTimeout" % RTE_SAMPLER_, sync_timeout)) action.append( JMX._bool_prop("%swaitCursor" % RTE_SAMPLER_, 'cursor' in wait_for)) if 'cursor' in wait_for: cursor = wait_for['cursor'] if type(cursor) is unicode: row, column = cursor.split(',') else: row, column = cursor['position'].split(',') action.append( JMX._string_prop("%swaitCursorRow" % RTE_SAMPLER_, row)) action.append( JMX._string_prop("%swaitCursorColumn" % RTE_SAMPLER_, column)) if 'timeout' in cursor: cursor_timeout = self.safe_time(cursor['timeout']) action.append( JMX._string_prop("%swaitCursorTimeout" % RTE_SAMPLER_, cursor_timeout)) action.append( JMX._bool_prop("%swaitSilent" % RTE_SAMPLER_, 'silent' in wait_for)) if 'silent' in wait_for: silent = wait_for['silent'] if type(silent) is unicode: stable_time = self.safe_time(silent) else: stable_time = self.safe_time(silent['stable-time']) action.append( JMX._string_prop("%swaitSilentTime" % RTE_SAMPLER_, stable_time)) if 'timeout' in silent: silent_timeout = self.safe_time(silent['timeout']) action.append( JMX._string_prop("%swaitSilentTimeout" % RTE_SAMPLER_, silent_timeout)) action.append( JMX._bool_prop("%swaitText" % RTE_SAMPLER_, 'text' in wait_for)) if 'text' in wait_for: text = wait_for['text'] if type(text) is unicode: regex = text else: regex = text['regex'] action.append( JMX._string_prop("%swaitTextRegex" % RTE_SAMPLER_, regex)) timeout = self.safe_time(text['timeout']) action.append(JMX._string_prop("%swaitTextTimeout" % RTE_SAMPLER_, timeout)) if \ 'timeout' in text else None if 'search-area' in text: top, left, bot, right = re.findall(r'\d+', text['search-area']) action.append( JMX._string_prop("%swaitTextAreaTop" % RTE_SAMPLER_, top)) action.append( JMX._string_prop("%swaitTextAreaLeft" % RTE_SAMPLER_, left)) action.append( JMX._string_prop("%swaitTextAreaBottom" % RTE_SAMPLER_, bot)) action.append( JMX._string_prop("%swaitTextAreaRight" % RTE_SAMPLER_, right))