# Getting Started

{% hint style="info" %}
In this guide we're going to test a back-end server running the following scenario for post records:

* request all records from the server;
* add a new record;
* check if the record was added correctly;
* update the record and check the update with a server response;
* request the updated record from the server;
* check if the record on the server is updated;
* delete the record;
* check if the record was deleted from the server.

**You'll need about 10 min to do that after running the app.**
{% endhint %}

## Installation

Go to our site <https://client.testmace.com>  or use the following links to download TestMace:

* Windows <https://download.testmace.com/TestMace.exe>
* Mac OS <https://download.testmace.com/TestMace.dmg>
* Linux <https://download.testmace.com/TestMace.AppImage>

Run the installer and follow the instructions. You will be prompted to choose an installation directory.

{% hint style="warning" %}
&#x20;*To install TestMace on Windows run the installer **as an administrator**.*
{% endhint %}

Once the installation is complete, run the app. You'll see a new project.

## Interface Overview

![](https://1550208191-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYfhIaTTw23Sf3L5jfe%2F-LhFUOLTSKsreXOFBI39%2F-LhFUVgv2a4VQpeSBF9V%2Fmain_screen_1.png?alt=media\&token=8d31cd2a-360a-4bf5-9c7e-496ae4dd0694)

## Your First GET Request

To make your first request create a new tab by clicking on **+**. При этом в зоне  You'll see a new **Scratch 1** node in the Scratches Area. Insert this address in the URL field: <https://testmace-stage.herokuapp.com/posts>. You can now test server response right from Scratches Area or add your scratch to the project. Rename the node to **getPosts** for convenience.

{% hint style="info" %}
Note that all changes to the project are automatically saved in real-time.
{% endhint %}

![Creating a GET request template](https://1550208191-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYfhIaTTw23Sf3L5jfe%2F-LhJpQ_vCIZWrro6TJZk%2F-LhJpUafiA17-CXuQAp9%2Fgetting_started_1.gif?alt=media\&token=844a0955-59f9-404d-aa2b-2bc95667611e)

In your project create a [Folder](https://docs.testmace.com/node-types/folder) node named **posts** and move the scratch **getPosts** from the Scratches Area to the Project Area.

![Creating a Folder node and GET request template moving](https://1550208191-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYfhIaTTw23Sf3L5jfe%2F-LhJpQ_vCIZWrro6TJZk%2F-LhJq2k6iMb_jD3VQw8e%2Fgetting_started_2.gif?alt=media\&token=403bb656-0f43-498a-b52a-4e50ab2fc092)

Double click on the created request **getPosts** to open it and then run it with the Run button.

![Running a GET request](https://1550208191-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYfhIaTTw23Sf3L5jfe%2F-LhJpQ_vCIZWrro6TJZk%2F-LhJqgooGAEXyLj0QBA7%2Fgetting_started_3.gif?alt=media\&token=5b1e83b5-197d-46aa-9baf-0b7b89d0f9f7)

As you see, the request was successfully run, and you have a list of existing records in **Response Area**. Let's take a closer look at this window:

![](https://1550208191-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYfhIaTTw23Sf3L5jfe%2F-LhFUOLTSKsreXOFBI39%2F-LhFV_hy2ssJx_CXd937%2Frun%20screen.png?alt=media\&token=af2309ed-b0ae-4ca3-8284-130ed9b81c54)

{% hint style="info" %}

#### Request parameters

Here you can specify http headers and pass parameters to the request with the help of the autocomplete feature and variables.

#### Request type

* **GET** — get a resource
* **POST** — create a resource
* **PUT** — update a resource
* **DELETE** — delete a resource
* **PATCH** — make some changes to a resource
* **OPTIONS** — specify resource connection parameters

#### URL

The URL field supports autocompletion and using variables. We'll take advantage of these features later.

#### Make Request

Sending a request or a group of requests while running from the project root or a folder node.

#### Response area

A server response area. The Response Body tab contains parsed, JSON, and text representations of a response. On the tabs next to it you can see Response Headers and create or view existing Assertion nodes to make a request.
{% endhint %}

## POST Request and Assertion

Now let's add a new post record to the server, and to do that we need to create a new [RequestStep](https://docs.testmace.com/node-types/request-step) node.&#x20;

{% hint style="info" %}
A new node can be created in three different ways:

1. Create a Scratch by clicking on **+** and drag and drop it to the project later.
2. Right-click on the parent node and choose **Add node -> Request step.**
3. Click on the button **Add project node-> Add node -> Request step**.&#x20;
   {% endhint %}

Use any of these ways to create a node and name it **createPost**.&#x20;

1. Set POST as its **Request type**.
2. Insert <https://testmace-stage.herokuapp.com/posts> in the URL field.
3. Chose JSON on the response body tab and add `{"title": "Testing post", "content": "Sendt via TestMace"}`
4. Click on the RUN button and send the request.&#x20;

You'll get a response telling you that the record has been successfully added, but we need to check if it was added correctly. And to do that we'll use the quickest way of creating [Assertion](https://docs.testmace.com/node-types/assertion-node) nodes. We'll compare the sent data with the data received from the server.

In Response Area open the tab with the parsed response and right-click on the **title value**, that you passed in the request and choose **Create Assertion -> Compare -> Equal.** It'll create and open the [Assertion](https://docs.testmace.com/node-types/assertion-node) node, and as you're not going to configure it, just close it. Create an Assertion node for the Content value in the same way.

Now send the **createPost** request, and you'll see that the test was successful. The task is really easy. Have a look at the animation below:

![Sending POST request and creating an Assertion node](https://1550208191-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYfhIaTTw23Sf3L5jfe%2F-LhJpQ_vCIZWrro6TJZk%2F-LhK0GR6pYAbucRUToRZ%2Fgetting_started_4.gif?alt=media\&token=94e64916-b469-4eaa-8575-925e4922f0a6)

### Dynamic Variables

To be able to interact with the newly added node you should pass its **Id** to all subsequent [Request step](https://docs.testmace.com/node-types/request-step) nodes. Define a dynamic variable **postId** and assign to it the Id value, received in the record after running **CreatePost**.&#x20;

1. &#x20;Right-click on the **Id** value in the **CreatePost** node's response body.&#x20;
2. Choose **Assign to variable**.&#x20;
3. In a pop-up window choose the **posts** project directory as a node, enter the variable name (**postId**) and press **OK**.

To access the variable use a[ default variable](https://docs.testmace.com/variables/variables) `$dynamicVar`:

```
${$dynamicVar.postId}
```

![Creating a dynamic variable](https://1550208191-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYfhIaTTw23Sf3L5jfe%2F-LhK0SAV-59GBQjAg6hd%2F-LhK1BRwGcPnJZvbxbS4%2Fgetting_started_5.gif?alt=media\&token=b89564f3-3b67-40ee-853a-537d4a89cea0)

## PUT Request

It's time we sent a PUT request.  Let's access the previously created record using a dynamic variable `${$dynamicVar.postId}` and update its **title** and **content** values.

1. Create a [RequestStep](https://docs.testmace.com/node-types/request-step) node named **updatePost**.
2. Set **PUT** as its request type.
3. URL: [https://testmace-stage.herokuapp.com/posts/${$dynamicVar.postId}](https://testmace-stage.herokuapp.com/posts/$%7B$dynamicVar.postId%7D)
4. Body: `{"title": "Testing post updated", "content": "Updated via TestMace"}`
5. &#x20;Send the request and, just like we did with the **POST** request, create two [Assertion](https://docs.testmace.com/node-types/assertion-node) nodes to compare sent and received **title** and **content** values.

![Creating a PUT request](https://1550208191-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYfhIaTTw23Sf3L5jfe%2F-LhK0SAV-59GBQjAg6hd%2F-LhK3Y9OgAtw8zYool2I%2Fgetting_started_6.gif?alt=media\&token=7c828698-04e5-4264-8182-857fc11fae20)

## Verifying Changes

In some situations you might want to additionally verify changes in the record, because the server may give a successful response of PUT, but sending a GET request you receive the old version.&#x20;

To do that create a GET request at the record's URL using a dynamic variable.

1. Create a new [RequestStep](https://docs.testmace.com/node-types/request-step) node named **getPost**.
2. Request type: GET.
3. URL: [https://testmace-stage.herokuapp.com/posts/${$dynamicVar.postId}](https://testmace-stage.herokuapp.com/posts/$%7B$dynamicVar.postId%7D)
4. Send the request and create 2 [Assertion](https://docs.testmace.com/node-types/assertion-node) nodes to compare **title** and **content** values.

![Verifying changes using a GET request](https://1550208191-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYfhIaTTw23Sf3L5jfe%2F-LhK0SAV-59GBQjAg6hd%2F-LhK4Oj-daBXeUD9mVGk%2Fgetting_started_7.gif?alt=media\&token=2152423d-0a73-4d9b-beb8-7226cfa0e1c5)

## DELETE Request

Our next step is deleting our record at the provided URL using a dynamic variable.

1. Create a [RequestStep](https://docs.testmace.com/node-types/request-step) node named **deletePost**.
2. Request type: DELETE.
3. URL: [https://testmace-stage.herokuapp.com/posts/${$dynamicVar.postId}](https://testmace-stage.herokuapp.com/posts/$%7B$dynamicVar.postId%7D)

![DELETE request](https://1550208191-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYfhIaTTw23Sf3L5jfe%2F-LhK59c6K51LChtOFa3G%2F-LhK5CKZiNZ92uvFMQqo%2Fgetting_started_8.gif?alt=media\&token=fc0eb164-f908-4991-a96b-6c6ecb33e8c0)

## DELETE Verifying

To ensure that the record was deleted from the server, create a GET request at that record's URL using a dynamic variable. We expect to get a 404 response from the server, and so we create an Assertion node:

1. Create a new [RequestStep](https://docs.testmace.com/node-types/request-step) node named **checkIfNodeExists**
2. Request type: GET
3. URL: [https://testmace-stage.herokuapp.com/posts/${$dynamicVar.postId}](https://testmace-stage.herokuapp.com/posts/$%7B$dynamicVar.postId%7D)
4. Send the request, open the **Assertions** and add a new [Assertion](https://docs.testmace.com/node-types/assertion-node) node, by clicking ADD. Set the node data:
   1. Actual value: `${$response.code}`
   2. Operator: `=`
   3. Expected value: `404`

![Verifying if the record was deleted via the server response](https://1550208191-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYfhIaTTw23Sf3L5jfe%2F-LhK6MDYKbETOBDIIY1v%2F-LhKAIKXMtt4o0-LWhwL%2Fgetting_started_9.gif?alt=media\&token=c80f7d78-f462-4fb7-8e0a-97fed0a858c9)

## Summary

In the end we've got a test set for our server that we can run in a scenario. Just go to **posts** and click RUN.&#x20;

![Running a scenario](https://1550208191-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYfhIaTTw23Sf3L5jfe%2F-LhK6MDYKbETOBDIIY1v%2F-LhKB-vkAz_pWK1QmcFi%2Fgetting_started_10.gif?alt=media\&token=e0a178fb-008e-4145-acd2-3e1095d875ab)

## Video Instruction

Watch a video of the entire process of creating a scenario described in this guide.

{% embed url="<https://youtu.be/Gyg_4w78KBo>" %}

## Getting started code for a [shared](https://docs.testmace.com/other-features/import/shared) import

{% file src="<https://1550208191-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYfhIaTTw23Sf3L5jfe%2F-LhKOkzXZuwhq12_irUr%2F-LhKOt6yJc6_lHN7SVh1%2Fgetting_started_shareCode.txt?alt=media&token=50c523bc-5cdb-413d-811f-bbf214186fc9>" %}
Getting Started Share Code
{% endfile %}

## Download the Project

Unzip in the TestMace projects directory.

{% file src="<https://1550208191-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LYfhIaTTw23Sf3L5jfe%2F-LfxX0v_QAhPX2I_1Af2%2F-LfxYBWoktxgpSwpf33U%2FTestMace_getting_started.zip?alt=media&token=328c93b9-51e6-41e2-98c2-ebbfdbc57521>" %}
Quick start project
{% endfile %}
