Put Up (put-up)
Put-up tag is used to execute any object in BEFORE phase. This means that it will be executed before SUITE, if the put-up is added to the suite. The properties defined in put-up will be available for all the test scenarios within test suite. Cast put-up tag will be equivalent to TestNG @BeforeSuite Annotation in general automation terms. The Ideal case of using Put up is for creating an http web server which is used by all subsequent api call tests.
it is always good to add a unique id to your files, even if we don't use it anywhere
Usage:
<put-up id=""! >
...any test scenario/step or any object.
</put-up>
! - mandatory
put-up and lifecycle-hook method "before" are almost similar in action. However, the benefit of put-up is that it will populate all it's variables (property name and values) which will be available globally within a SUITE. For lifecycle-hook, we need to populate variable manually to access them globally.
Examples
Example | Behaviour |
---|---|
<put-up id="testProxy">
<property name="proxyPort" value="${proxyPort!'8177'}"/>
<property name="proxyUrl" value="localhost" />
<http:proxy-server name="proxyServer" context="proxyCtx" port="${proxyPort}" remoteUrl="${@rt('url')}" remotePort="${@rt('port')}">
<condition value="${(proxyCtx.getRequestHeader('nullBody')??)?c}">
<script>
${proxyServer.setNullResponseBody()}
</script>
</condition>
</http:proxy-server>
</put-up> | Creates a proxy server object in put-up. The property proxyUrl will be available for all scenarios under Suite. |
<put-up id="generateAuthToken">
<sui:scenario device="${@chrome()}">
<test-step>
.. all the test steps to generate new token after successful login
//using freemarker slicing to get the token from url
<property name="authToken" value="${currentUrl[49..120]}"/>
</test-step>
</sui:scenario>
</put-up>
Token generated in put-up will be used in scenario <http:call method="get" url="${url}">
<http:request-header headerName="Authorization" value="Bearer ${authToken}"/>
<response-get name="apiResponse"/>
</http:call> | Creates a SUI:Scenario object in Put-up for creating authentication using web login. The Auth token is calculated from Url after login and will be used in making http calls in test scenarios. |
Good Practices
Every put-up should be created under "objects" folder.