def test_num_threads(self): element = CommonThreadGroup(num_threads=50) rendered_doc = element.to_xml() parsed_doc = xmltodict.parse(tag_wrapper(rendered_doc, 'test_results')) for tag in parsed_doc['test_results']['ThreadGroup']['stringProp']: if tag['@name'] == 'ThreadGroup.num_threads': assert tag['#text'] == '50'
def test_on_sample_error(self): element = CommonThreadGroup( on_sample_error=ThreadGroupAction.START_NEXT_LOOP) rendered_doc = element.to_xml() parsed_doc = xmltodict.parse(tag_wrapper(rendered_doc, 'test_results')) for tag in parsed_doc['test_results']['ThreadGroup']['stringProp']: if tag['@name'] == 'ThreadGroup.on_sample_error': assert tag['#text'] == 'startnextloop'
def test_sheduler_duration(self): element = CommonThreadGroup(continue_forever=True, loops=55, sheduler_duration=1000, sheduler_delay=2000) rendered_doc = element.to_xml() parsed_doc = xmltodict.parse(tag_wrapper(rendered_doc, 'test_results')) assert parsed_doc['test_results']['ThreadGroup']['stringProp'][4][ '#text'] == '1000'
def test_sheduler_delay(self): element = CommonThreadGroup(is_sheduler_enable=True, sheduler_duration=1000, sheduler_delay=2000) rendered_doc = element.to_xml() parsed_doc = xmltodict.parse(tag_wrapper(rendered_doc, 'test_results')) for tag in parsed_doc['test_results']['ThreadGroup']['stringProp']: if tag['@name'] == 'ThreadGroup.delay': assert tag['#text'] == '2000'
def test_includes_elements_get_size(self): thread_group = CommonThreadGroup(continue_forever=True) elements_list = [ HTTPCacheManager(), HTTPCacheManager(), HTTPCacheManager() ] for element in elements_list: thread_group.append(element) assert len(thread_group) == 3
def test_includes_elements_test_render(self): thread_group = CommonThreadGroup(continue_forever=True) elements_list = [ HTTPCacheManager(), HTTPCacheManager(), HTTPCacheManager() ] for element in elements_list: thread_group.append(element) xml_data = thread_group._render_inner_elements() assert len(re.findall('element_type', xml_data)) == 3
def test_check_forbidden_symbols(self): thread_group = CommonThreadGroup(continue_forever=True) elements_list = [ HTTPCacheManager(), HTTPCacheManager(), HTTPCacheManager() ] for element in elements_list: thread_group.append(element) xml_data = thread_group._render_inner_elements() assert "<" not in xml_data assert ">" not in xml_data
def test_is_sheduler_enable(self): element = CommonThreadGroup(is_sheduler_enable=True) rendered_doc = element.to_xml() parsed_doc = xmltodict.parse(tag_wrapper(rendered_doc, 'test_results')) assert parsed_doc['test_results']['ThreadGroup']['boolProp'][ '#text'] == 'true'
def test_loops(self): element = CommonThreadGroup(loops=55) rendered_doc = element.to_xml() parsed_doc = xmltodict.parse(tag_wrapper(rendered_doc, 'test_results')) assert parsed_doc['test_results']['ThreadGroup']['elementProp'][ 'stringProp']['#text'] == '55'
def test_positive(self): CommonThreadGroup(delayed_start=True)
def test_check2(self): with pytest.raises(TypeError): CommonThreadGroup(continue_forever=True, is_sheduler_enable="123")
def test_check(self): with pytest.raises(TypeError): CommonThreadGroup(continue_forever="True")
def test_positive(self): CommonThreadGroup(continue_forever=True, is_sheduler_enable=True)
def test_positive(self): CommonThreadGroup(continue_forever=True, sheduler_delay=23)
def test_check2(self): with pytest.raises(TypeError): CommonThreadGroup(continue_forever=True, sheduler_delay="a")
def test_check(self): with pytest.raises(TypeError): CommonThreadGroup(continue_forever=True, sheduler_duration="1")
def test_positive(self): CommonThreadGroup(continue_forever=True, loops=23)
def test_check2(self): with pytest.raises(TypeError): CommonThreadGroup(continue_forever=True, loops="a")
def test_check(self): with pytest.raises(TypeError): CommonThreadGroup(delayed_start="True")
from jmeter_api.configs.http_cache_manager.elements import HTTPCacheManager from jmeter_api.timers.constant_throughput_timer.elements import ConstantThroughputTimer from jmeter_api.timers.constant_timer.elements import ConstantTimer from jmeter_api.non_test_elements.test_plan.elements import TestPlan from jmeter_api.controllers.loop_controller.elements import LoopController from jmeter_api.test_fragment.elements import TestFragment from jmeter_api.controllers.module_controller.elements import ModuleController from jmeter_api.samplers.http_request.elements import HttpRequest from jmeter_api.samplers.jsr223.elements import JSR223 from jmeter_api.thread_groups.common_thread_group.elements import CommonThreadGroup if __name__ == "__main__": test_plan = TestPlan(name='NewTestPlan') test_plan.append(HTTPCacheManager(clear_each_iteration=True)) test_plan.append(CommonThreadGroup(continue_forever=True, name='FirstThreadGroup') .append(HttpRequest(host='www.google.com')) .append(HttpRequest(host='www.google.com')) .append(ConstantTimer(delay=1000)) ) second_thread_group = CommonThreadGroup( continue_forever=True, name='SecondThreadGroup') for x in range(20): second_thread_group.append(HttpRequest( host='www.google.com', path=f'/new-{x}', name=f'NewSampler{x}')) second_thread_group.append(ConstantThroughputTimer(targ_throughput=10)) test_plan.append(second_thread_group) test_fragment = TestFragment() lc = LoopController(loops=3, name='loop3') lc2 = LoopController(continue_forever=True) lc2.append(HttpRequest(host='www.google.com')) lc.append(HttpRequest(host='www.google.com'))