Fixing a Bug with the Delivery Context

In this section we will explain how to use the Delivery Context to identify and fix a device specific bug. We assume that you have successfully integrated a website with FIT as shown earlier.

Setup

Let’s create a “buggy” HTML page in public/bug.html:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Misbehaving page</title>
  </head>
  <body>
    <h1>Device Info</h1>
    <ul>
      <li>client/hw/input/touchscreen: <ai-value-of select="boolean(client/hw/input/touchscreen)"/></li>
    </ul>
  </body>
</html>

Make sure that you have enabled DOM filtering in the site configuration (conf/config.xml):

<config>
  <ress>
    <dom-filter/>
  </ress>
</config>

and use an URL map like:

<urlmap>
  <map path="/bug.html" source="fit://site/public/bug.html" />
  <map path="/local/" source="fit://site/public/" />
  <map path="/" source="//example.com/" />
</urlmap>

You should see a small Information about the touch screen support of your device when you navigate to http://local14.sevenval-fit.com/bug.html.

Detect device specifics

Sometimes our assertions do not fit to your application, and you want to behave differently for specific devices or under special circumstances. It is possible to overwrite the delivery context with your values, but you should be as specific as possible when you define when your override should take precedence.

By using a small detection page you can determine as many data points as you need to make the decision.

Create a small helper page in public/detect.html:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Decisions have to be made</title>
  </head>
  <body>
    <h1>Device Info</h1>
    <ul>
      <li>client/hw/vendor:<ai-value-of select="client/hw/vendor"/></li>
      <li>client/hw/name:<ai-value-of select="client/hw/name"/></li>
      <li>client/os/name:<ai-value-of select="client/os/name"/></li>
      <li>client/os/version:<ai-value-of select="client/os/version"/></li>
      <li>client/name:<ai-value-of select="client/name"/></li>
      <li>client/version:<ai-value-of select="client/version"/></li>
      <li>client/render-engine/name:<ai-value-of select="client/render-engine/name"/></li>
    </ul>
  </body>
</html>

Quickly add a new shortcut mapping rule for this page:

<urlmap>
  <map path="/detect.html" source="fit://site/public/detect.html" />
  ...
</urlmap>

“detect” is now accessible under http://local14.sevenval-fit.com/detect.html

Apply a fix

To change the value of a dc property you can use the set-dc Flow action, but be aware that all requests will be affected and you may break existing and working functionality with this.

That is why applying the action conditionally with the formerly determined data points is a good idea:

<flow>
  <!-- depending on the client you used, maybe you will need to set the xpath to `false()` to differ from the original value -->
  <if test="client/hw/name = 'VALUE_FOUND_IN_DETECT_HTML' and client/os/name = 'AGAIN_FOUND_IN_DETECT_HTML'">
    <set-dc property="client/hw/input/touchscreen" xpath="true()"/>
  </if>
  <default-request />
  <parse />
</flow>

Check new behaviour

Having saved the modified flow.xml with the set-dc action, you will get a different value if you check on http://local14.sevenval-fit.com/bug.html with the same device again.

Exercise

Read more about Delivery Context and browse through the different Flow actions.

More…