Forum Discussion

Bob's avatar
Bob
Contributor
16 years ago

teardown script to reset request

Hi,

I have a request which I am changing using some groovy and property transfers.  However after the test case has finished I would like to reset that request to its original code.  I am guessing I do this using groovy but am not sure how.

The setup is as follows:

TestSuite1 has a property which is the request.
TestCase1 has a number of test Steps the first of which is a property transfer step which sets the request to be the one in the suite property.
Test Case 1 then does some other stuff which changes the values in that request.

Once its done I need to reset the request in test case 1 to the original value so that when the test is run again the initial property transfer is successful.

Any ideas?

3 Replies

  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    Doesn't the Property Transfer reset the request value every time the test case is rerun? Am I missing something?

    Ohhh - maybe you mean you are doing a transfer that changes part of the initial request? Then why not have a TestCase property that contains the entire initial request and do a property transfer before all the others which sets the request to that initial value.
  • Bob's avatar
    Bob
    Contributor
    Ok I'll try explaining a bit more.

    I have a large number of test cases.  The request being sent for all these test cases is the same except for 1 or two values.  However the request itself may change.  So in order to prevent having to edit a large number of requests in all the test cases I have one request set up as a property of the test suite.

    In each test cases I have a request which has a single property and nothing else.  This property is the request set up in in the propertys.  The following test steps in the test case add in values to the request as needed.

    However as the property in the request has changed and the original property is no longer there I dont know how to change it back!This means if I change the request in the suite property and run the tests again they dont get populated with the new request.

    My questions are therefore:
    1.  Is it possible to use groovy or some other method to "reset" a reguest in a test case or set it back to the original request (which was just a simple property placeholder)
    2.  Or is there another way to use a single request in multiple test cases in such a way that when I change the request it changes in all test cases also?

    Thanks
  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    testCase.getTestStepByName("REST Test Request").testRequest.setRequestContent(context.expand('${#TestSuite#defaultRequest}'))


    This puts the value of the test suite property into the request content.

    I would put it in the setup script; that way even if the test case fails it would still get run every time.