How to remove custom header with predefined value from request object for negative cases?

A few years ago there was a topic, but I can’t find a good idea how to correctly write test cases.
Problematics:
I setup GET request object, show in UI variables section headers:
header1 value by default “”
header2 value by default “”
I can go next way:
requestCreateAccount = findTestObject(‘Way toTest Object’, [(‘header1’) : header1])
responseCreateAccount = WS.sendRequestAndVerify(requestCreateAccount)
but in this case I’ll receive default value for header2.
Of cause I can use next lines to make it manually:

RequestObject requestObject = new RequestObject(‘objectId’)

requestObject.setRestUrl(‘http://lalala.com’)
TestObjectProperty header1 = new TestObjectProperty(‘header1’, ConditionType.EQUALS, ‘blabla’)
ArrayList defaultHeaders = Arrays.asList(header1)
requestObject.setHttpHeaderProperties(defaultHeaders)
requestObject.setRestRequestMethod(‘GET’)
and only then make
ResponseObject responseObject = WS.sendRequest(requestObject)

But for some scenarios I need to send request without header2 to check response(optional)/

Can you show the best practices to do it?

Hi,

You already found the best solution, build your TestObject by code.
Using pre-defined headers binded to variables won’t work properly for your use case, unless when you don’t need the second header, you remove it … by code also.
Which is … meh, better just add what is needed per/case.

I reckon you can combine as following:

requestCreateAccount = findTestObject(‘Way toTest Object’)
headers = [new TestObjectProperty(‘header1’, ConditionType.EQUALS, ‘blabla’)]
requestCreateAccount.setHttpHeaderProperties(headers)
responseCreateAccount = WS.sendRequestAndVerify(requestCreateAccount)

but if I already have header with default variable in the object’s “variables” tab, then it will be passed in request with this default values. there is no way to remove for particular cases this header. So, the only solution - is to create similar object without suche header in variables tab, or create request manually as above.