def test_hashtree_contain(self):
     element = ConstantThroughputTimer(name='My tp timer',
                                       targ_throughput=2,
                                       based_on=BasedOn.THIS_THREAD_ONLY,
                                       comments='My comments',
                                       is_enabled=False)
     rendered_doc = element.to_xml()
     assert '<hashTree />' in rendered_doc
 def test_value_stringProp(self):
     element = ConstantThroughputTimer(name='My tp timer',
                                       targ_throughput=2,
                                       based_on=BasedOn.THIS_THREAD_ONLY,
                                       comments='My comments',
                                       is_enabled=False)
     rendered_doc = element.to_xml()
     parsed_doc = xmltodict.parse(tag_wrapper(rendered_doc, 'test_results'))
     assert parsed_doc['test_results']['ConstantThroughputTimer']['stringProp']['#text'] == 'My comments'
    def test_args_type_check(self):
        # name type check
        with pytest.raises(TypeError):
            ConstantThroughputTimer(name=123)

        # comments type check
        with pytest.raises(TypeError):
            ConstantThroughputTimer(comments=123)

        # is_enabled type check
        with pytest.raises(TypeError):
            ConstantThroughputTimer(is_enabled="True")

        # targ_throughput type check (negative number input)
        with pytest.raises(TypeError, match=r".*arg: targ_throughput should be positive int or float.*"):
            ConstantThroughputTimer(targ_throughput=-1)

        # arg: targ_throughput should be positive int or float. (wrong data type input)
        with pytest.raises(TypeError, match=r".*arg: targ_throughput should be positive int or float.*"):
            ConstantThroughputTimer(targ_throughput='123')

        # based_on type check (wrong data type input)
        with pytest.raises(TypeError, match=r".*arg: based_on should be BasedOn.*"):
            ConstantThroughputTimer(based_on=123)
Пример #4
0
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'))
    lc.append(lc2)
    mc = ModuleController(node_path="NewTestPlan/Test Fragment/loop3")
    test_fragment.append(lc)
    test_fragment.append(mc)
    test_plan.append(test_fragment)

    open('example_testplan_01.jmx', 'w').write(test_plan.to_xml())