Testing

A list of tips and procedures to test your HTML-based application on Stagecast infrastructures.

Creating a Development Sandbox

When a webview (for example the one integrated in the Stagecast app) launches a Moment, it will pass certain information to the Moment. Because we will develop and test our Moment on our locale machine first, before pushing it to a staging server, we have to create a development sandbox, which takes care of passing test data to our Moment.

To mimic the data being passed to the moment we have to retrieve an API token and some information about our moment first. Currently you have to make two POST requests to the Stagecast API manually. Feel free to use a HTTP client like Postman to make your life easier.

Get the token

POST https://stagecast.se/api/users/login

First we will have to get our API token by making a login request to Stagecast’s API. Only the token property of the response will be relevant for us.

Request Body

{
  ...
  "token": "<YOUR_API_TOKEN>"
  ...
}

Next we have to retrieve the momentID and the momentClassID from the Stagecast Sandbox API. You will need your eventID for this request. You can find the eventID in the URL when opening an event in the Stagecast Web Platform: https://stagecast.se/dashboard/events/<YOUR_EVENT_ID>/launchpad

Create the Sandbox

POST https://stagecast.se/api/sandbox/<YOUR_EVENT_ID>

{
  "momentID": "<YOUR_MOMENT_ID>",
  "momentClassID": "<YOUR_MOMENT_CLASS_ID>",
  "eventID": "<YOUR_EVENT_ID>",
  "creationTime": 1584007941692
}

After retrieving those values from the API we can start setting up our sandbox.

Our sandbox/adapter is a simple HTML/JS application itself, which will launch the Moment inside an iframe.

For this we will create a few files in the directory src/adapters/tests (you have to create this directory manually).

The content of the folder is the following:

<!DOCTYPE html>
<!DOCTYPE html>
<!-- Use this file to test your Moment -->
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no">
    <title>Treasure Hunt Moment Tester</title>
<style>body {
    position:fixed;
    padding: 0px;
    margin: 0px;
    overflow:hidden;
    height:100vh;
    width:100vw;
}

#frame {
    position: absolute;
    width: 100%;
    height: 100%;
    top:0;
    left:0;
    margin:0;
    padding:0;
    overflow: hidden;
    box-sizing: border-box;
    border-style: none;
}
</style>
</head>
<body>
<!-- iframe where the treasure hunt moment will be loaded. -->
<iframe id="frame" title="Treasure Hunt Moment" onload="iframeLoaded()" src="../../mobile/index.html"></iframe>
<script src="./test-data.js"></script>
<script src="./loader.js"></script>
</body>
</html>

src/adapters/tests/mobile.adapter.html: With this file we create an iframe, and link it to the index.html inside our src/mobile folder (So our Moment will launch inside this iframe).

src/adapters/tests/test-data.js: This is the data we will seed the Moment with. This JavaScript object is normally passed to the Moment via the Stagecast App/Webview integration. Now we have to inject the test data we’ve just created into the iframe in our mobile.adapter.html. This is done in the loader.js file we include right after the test-data.js.

src/adapters/tests/loader.js: Inside this file we define the functioniframeLoaded() which will be called as soon as the iframe finishes loading. Once loaded, we will pass the variable momentData we’ve just created to our iframe with the postMessage() method. That’s it. From now on we can launch our moment by opening the src/adapters/tests/mobile.adapter.html file. Right now you won’t see much, because our moment is still an empty HTML file, but let’s change that!

Last updated