visit
Hello there! We're coming out of the shadows and continuing the series of articles about our product. We've got so many feedbacks (mainly positive), suggestions, and bug reports after publishing our last overview article. Today you'll see in action and try out some features of our application.
For more information be sure to look over its documentation - . Let's go!Let's start with creating a new (File->New project). If TestMace is launched the first time, it'll be done automatically. Let's issue a request for creating a new post (in case if it is possible without authorization). In the Project node context menu select Add node -> .
Name it create-post. You'll see a new node in the project tree and it's tab will be shown.
Set the following request parameters:{"title": "New testmace quick start post"}
value.As mentioned before, we've got a POST endpoint /login, that takes the following json as the request body:
{"username": "<username>", "password": "<password>"}
, where username and password have the admin and password values respectively. This endpoint returns the following json as a response: {"token": "<token>"}
. Let's use it for authorization. Create a RequestStep node named login with the Project node being its parent. Drag and drop this node above the create-post node in the tree.
Set the following parameters for the newly added node:{"username": "admin", "password": "password"}
value.Define the
domain
variable with the value //testmace-quick-start.herokuapp.com
at the Project node level. To do that, you need to:OK. Now we can inherit this variable in children of any nesting level and in the login and create-post nodes in particular. To use the variable in the text box, you should write
${<variable_name>}
. For example, the url for login will be written as ${domain}/login
, and the url for the create-post node - ${domain}/posts
.By doing so, we've followed the DRY principle and improved our little scenario.First, let's send the login request. In the Parsed tab of the response point to the token in the context menu and select Assign to variable.
You'll see a dialog with the following fields:token
in our case).At this point, every time the login node runs, the
token
variable is updated with the value from the response. This variable will be stored in the Project node and will be available in child nodes, thanks to inheritance mechanism.To access dynamic variables, use the
$dynamicVar
. For instance, to get to the saved token you should write ${$dynamicVar.token}
.Previously we've received an authorization token and now we only need to add the Authorization header with the Bearer <tokenValue> value to every request where authorization is needed, including the create-post request.
There are a few ways to do that:Earlier we've saved the token into the
$dynamicVar.token
dynamic variable at the Project node level. Now we have to:1. Define the Authorization default header with the
Bearer ${$dynamicVar.token}
value at the Project node level. To do that, open the default headers dialog (select the Headers button at the top right of the screen) and add the corresponding header. This is how the dialog with the filled fields should look like:2. Disable this header in the login request. Sure thing: at the moment of logging in we don't have a token, we'll set it with this particular request. Thus, uncheck the Authorization checkbox in the Headers tab in the Inherited area.
That's it. The authorization header will now be added to all Project node children, except for the login node. Seems, the scenario is ready, and we only need to run it. To do that, select Run in the Project node context menu.
Let's discuss the first step. Since the id value is defined while running the script, we need to create a dynamic variable (let's name it
postID
) in the create-post node at the Project node level. You already know how to to that, just go to the Storing the token in a variable section. All we have left is sending a request for getting the post by its id.
Create a RequestStep node named get-post with the following parameters:
${domain}/posts/${$dynamicVar.postId}
To go further, you need to take a closer look at nodes. An Assertion node is a node that allows to create tests for specific requests. Each Assertion node may contain several assertions (tests). To learn more about supported assertions you can refer to our . We'll use a Compare assertion with the equal operator.
There are two ways of creation assertions:Wow, we've just created our first test! Simple as that! Now you can run the full scenario and enjoy the result. You can make it even more beautiful if you put
title
into a separate variable though. We leave it to you as an exercise :)P.S. If you feel lazy to follow the steps described in the article, we've have a with this project just for you. Select File -> Open project and choose the Project folder.