Introduction to the API Fortress Platform and Visual Test Composer

What You'll Need

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 create a Sauce Labs account and get started with a free trial. You can now access API testing.

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 Sauce Labs, then click API TESTING > Get Started.
  2. From the API Testing page, select the Create Project button.API Fortress: Create Project
  3. The New Project pop-up window will appear. API Fortress: Project Fields
    Input the following for each category:
    • Create from: select Blank Project
    • Project Name: Test Project
    • Project Description: Simple Test against the Sauce Labs User API
    • Project Notes: https://docs.saucelabs.com/dev/api/accounts#user-methods
  4. Click Save.
  5. This will take you to the Tests page of your project.

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

Create a Test File

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

From the project:

  1. Log in to Sauce Labs, then click API TESTING > Get Started.
  2. Go to your project, then select Tests at the top navigation bar to see the project test list.
  3. From the project test list, select + Create Test. API Fortress: Create New Tests
  4. You should now see the New Test popup window.API Fortress: Test Details

    Input the following for each category:
    • Test Name: GET User Info
    • Test Description: Test for /team-management/users method
    • Insert a Tag: GET, user, team-management
  5. Now your test should appear in the project Tests page.API Fortress: Test Status / Interstitial Page

Note:

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. From the navigation, select HTTP Client.API Fortress: HTTP Client button
  2. In the empty Enter Request url field, input https://api.us-west-1.saucelabs.com/team-management/v1/users?limit=3 and click Send.
    API Fortress: Generate Test Step 1

You should receive the following error response to the right of the request input:

"HTTP Code 401: Authorization failed"

API Fortress: HTTP 401 Request Error

You are getting this error because you need to send an authorization header, identifying who you are in order to get a response from the GET request.

We will use this request, however, to generate a test in the next section.

Note:

Lets use the test creation feature to get an authorization header that you can then add to an HTTP request to generate a test with that HTTP request.

Start with the HTTP call to the team management endpoint URL:

https://api.us-west-1.saucelabs.com/team-management/v1/users?limit=3

GET team management

Adding a Test Component

In the previous step, we encountered a common authentication error, HTTP: 401, because we didn't send the username and accesskey that Sauce Labs requires to communicate with their API.

To fix this error, we'll need to add our Sauce Labs Account Credentials as a Basic Authentication Header.

  1. Navigate back to the Tests page and click to edit . API Fortress: Go back to the tests page
  2. Select + Add Request / Assertions. API 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 by inputting 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: under Name, put limit; under String value, put 3. This sets the number of responses to a limit of 3, so that your test doesn't take too long to complete.
  2. Scroll to the bottom of the window and click Add Authentication.
    API Fortress: Authentication Details
  3. Select Basic Authentication.
    API Fortress: Basic Auth Component
  4. Input 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.API Fortress: Basic Auth Details

Note

Copy and Paste the Encoded Auth Header

  1. You'll notice that API Fortress automatically 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'd like (here, it's named GET 3 Users):
    Add Auth details to request
  6. Back in the HTTP Client, click 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

See the Workflow to create a GET request with an Basic Authorization header.

API Fortress: GET call with Basic Auth

Generate a Test from the HTTP Client

  1. Next, click the Generate Test button and API Fortress automagically generates a sample test based on the request data. API Fortress: Generate Test Button
  2. Enter the test details (a name such as First GET Test and a description), click Save, and then click through the prompts. You should now see a full test back in the Tests page. API Fortress: Generated Test
  3. The final step is to run your tests. From the toolbar, select Save, then Run. API Fortress: Run Test Button

To view your test results:

  1. Look for TEST RUNS in the right-hand nav.
  2. To open the report, you can either double-click on your test name — or — hover your mouse over your test, then click Open report document.

API Testing: Test Results nav

API Testing: Test Results nav

  1. Review your results. Any errors encountered will show in the test results report.

API Fortress: Test Results Page 1

Troubleshooting API Test Errors

If you are getting an API test error and want to find out more about what an HTTP call you are making is returning, the HTTP Client (accessible from your project dashboard) can be a useful tool.

You can use the HTTP Client to send a request and even add in headers, such as authorization credentials, or other information.

Add Global Parameter

If you navigate back to the Tests page, you may see an Unpublished changes message in the right-hand nav.

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 Unpublished changes message, then 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, you'll see a test that is published, but not scheduled, indicated by a - underneath the Schedules tab:

API Fortress: Not Scheduled

Below are the steps to schedule a test.

  1. From the page where your projects' tests are listed, select the Schedule Test button. This will bring up the Test Scheduler.API Fortress: Schedule Button
  2. Next, select Create Schedule. API Fortress: Create New Schedule
  3. 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
  4. Enter the desired details and when you're finished, click Save. 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:

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: