1. Introduction to the API Fortress Platform and Visual Test Composer
    • Create a project & test file
    • Use the HTTP Client to generate a GET request
    • Use the Test Component Library to create a request
    • Add authorization credentials to a request
    • Generate a test from a valid GET request
    • View the test results
    • Publish and schedule a test run

API Fortress is the API Testing Platform of Sauce Labs. We will use this platform throughout the remainder of this course. Some concepts we cover during this course require the API Fortress platform.

However, you can try and follow along using other tools like Postman, and then import your requests later on.

Getting Started with API Fortress

If you don't have an API Fortress account you can visit the API Fortress home page, and select the Free Trial button at the top to request a 30-day free trial.

After you fill out the necessary fields, you then receive an email with your login credentials for the platform.

NOTE: If you don't receive an email confirmation, check your spam folder or please email support@saucelabs.com for assistance.

Create a Project

For this first test project we will test against the Sauce Labs API.

  1. Log in to the platform
  2. Select the Create Project button. API Fortress: Create Project
  3. The Add New Project alert window appears. API Fortress: Project FieldsAdd the following for each category:
    • Project Name: Test Project
    • Description: Simple Test against the Sauce Labs User API
    • Notes: https://docs.saucelabs.com/dev/api/accounts#user-methods
  4. Find your project and select the Tests Icon to continue.API Fortress:Test Icon Button

We now have a project in which we can begin writing API Tests. Let's create the first API Test!

Note:

Negative : You must have a API Fortress account in order to follow along in this step. Use this link to sign up for a free trial. If you have an account, Sign In.

Create a Test File

We're going to test against the Sauce Labs GET user endpoint. In order to successfully create this test we need to complete the following steps using the Visual Editor :

From the project:

  1. Select Tests at the top navigation bar in order to see the project test list
  2. From the project test list, select + Create TestAPI Fortress: Create New Tests
  3. You should now see the new Test Details alert window API Fortress: Test DetailsAdd the following for each category:
    • Test Name: GET User Info
    • Description: Test for /team-management/users method
    • Tags: GET, user, team-management
  4. Now your test should appear in the project Tests page.API Fortress: Test Status / Interstitial Page

Note:

Negative : Enter tags individually an then press ‘Enter' to submit the tag. These will be helpful down the road when you want to search or query test results by tag name.

At the moment, the test content is empty. So from here, we can generate a test with the following options:

For the purposes of this lesson, we will generate a test manually with the HTTP Client.

From the Tests page:

  1. Select the HTTP Client in the top navigation bar. API Fortress: HTTP Client button
  2. At the bottom of the UI, enter the following URL where it says Request url in the HTTP Client:
    https://api.us-west-1.saucelabs.com/team-management/v1/users?limit=3
    
  3. Select the Send button:API Fortress: Generate Test Step 1You should receive the following error response to the right of the request input:
    "HTTP Code 401: Authorization failed"
    
    API Fortress: HTTP 401 Request Error

Note:

Negative : To see the raw response body in the HTTP Client select Body and then either Raw or Parsed

Adding a Test Component

Let's add a GET component that makes a successful API call against the Sauce Labs REST API.

In the previous step we encountered a common authentication error, HTTP: 401, because you didn't send the username and accesskey that Sauce Labs requires to communicate with their API. In order to fix this error we must add our Sauce Labs Account Credentials as a Basic Authentication Header.

  1. Navigate back to the Tests page and click to edit the test you created. API Fortress: Go back to the tests page
  2. Select + Add Request / AssertionsAPI Fortress: Add Component Button
  3. From the dropdown list, select GET:API Fortress: Select GET Component

Create A GET Component

  1. In the next screen, recreate your HTTP Client request with the following information
    • Url: https://api.us-west-1.saucelabs.com/team-management/v1/users – The URL that you are retrieving data from
    • Variable: payload - The variable where the response to GET is stored
    • Expect: Leave blank
    • Mode: json - The format of the information from the GET call
    • Query Params: Name: limit String value: 3 – Sets the number of responses to a limit of 3, so that your test doesn't take too long to complete
  2. Then select Add Authentication at the bottom right. API Fortress: Authentication Details
  3. Select Basic Authentication, then add your Sauce Labs Username and Access Key in the relevant fields. When you're finished, select the green check mark API Fortress: Green Check Mark in the top right.API Fortress: Basic Auth ComponentAPI Fortress: Basic Auth Details

Note

Negative : There is no autosave! It's important to save each time you make a change to your test and/or an HTTP Request. API Fortress: Save

Copy and Paste the Encoded Auth Header

  1. You'll notice that API Fortress automagically encodes and adds the Base64 Authorization header for you. Double-click the component to see the details: API Fortress: New Auth Component
  2. Copy the base64 Basic Authorization value (e.g. Basic anRhY2s0Oxxxxxxxxxxxxxxxxxxxxxxxx==) to your clipboard
  3. Return to the HTTP Client tab in your project.
  4. Paste the base64 Basic Authorization value into your HTTP Client Headers section and type Authorization into the Key field. Also, make sure the endpoint URL: https://api.us-west-1.saucelabs.com/team-management/v1/users?limit=3 is still there: Add Auth details to request
  5. Save your HTTP request in your project to use later. Name it whatever you wish (here it is named GET 3 Users): Add Auth details to request
  6. Back in the HTTP Client, select the Send button again. To the right, you should see a 200 response code and something similar in the response headers: API Fortress: Response Body Example
  7. Next, select the Generate Test button and API Fortress automagically generates a sample test based on the request data. API Fortress: Generate Test Button
  8. Enter the test details (a name such as First GET Test and a description), select Save, and click through the prompts, and you should now see a full test back in the Tests page. API Fortress: Generated Test
  9. The final step is to run your tests. At the top of the toolbar, select Save then RunAPI Fortress: Run Test Button

If your previous step ran without any errors you should see the following test results page: API Fortress: Test Results Page 1

If you ran into any errors, they appear here along with troubleshooting tips.

If you navigate back to the Tests page, you may notice to the right is a message stating: Unpublished changes

API Fortress: Unpublished Status

There's either one of two reasons for this:

Publish the Working Copy

All the work we previously completed only exists as a Working Copy. It's basically still in rough draft form, and we need to publish the test in order to actually use it in production.

From the Test editing page, hover over the message that states "Unpublished changes" and select the Publish button to publish the working copy.

API Fortress: Publish Button

Immediately, the Publish button turns green to indicate your test is ready for a scheduled a test run. Save your test.

API Fortress: Publish Status

Schedule a Test

Scheduling a test basically means we can set up a recurring job (sort of like a cron job) that can run our published tests at a specific time, along with other test parameters. If you look on the project page where your tests are listed, a test that is published, but not scheduled, appears with a - underneath the Schedules tab like this:

API Fortress: Not Scheduled

Below are the steps to schedule a test.

From the page where your projects' tests are listed, select the Schedule Test button:

API Fortress: Schedule Button

You should now see the Test Scheduler:

  1. Next select Create ScheduleAPI Fortress: Create New Schedule
  2. In the next page you can set the test run parameters and scheduling details such as when and how often tests run. API Fortress: Schedule Details
  3. Enter the desired details and when you're finished, select Save at the bottom. Below is an example of a schedule that runs on the 55th minute at noon and midnight, during every day of every month. API Fortress: High Noon Schedule

If everything worked correctly, you should see the following status on the Schedule page: API Fortress: Schedule Example

Also, you will see the following on the page where the tests for your project are listed: API Fortress: Schedule Icon

Congratulations on running, publishing, and scheduling your first API Test!

In the next module, we will take a step back and dive deeper into the API Fortress Test Component Library where we cover such topics as: