Access Browser Local Storage with TestArchitect

Share on facebook
Share on twitter
Share on linkedin

Not too long ago I ran into a scenario where a test that I was composing needed to make an API call. The challenge was that one of the values needed for an API call was being stored in the browser’s session. The tool I was using didn’t support directly accessing the browser session. This post describes how I leveraged a combination of TestArchitect capabilities to achieve accessing the browsers session storage.   Currently, LogiGear’s TestArchitect (TA) doesn’t contain any native keyword commands that would allow users to access values stored in the browsers local and session storage. Fortunately, the building blocks are there so this is what I did:    

  1. Compose a short JavaScript, inject it on the page, and subsequently invoke it.
  2. The JavaScript retrieves the value from the session and attaches to an attribute on an element.
  3. Once it is in the DOM, we can easily retrieve it using the native Get Control Property keyword.
  4. Finally, now that it is in a TA variable it’s fairly straightforward to pass it in the call to the API.   The first thing I did was compose the JavaScript that I would need to inject on the page.

Here’s a sample from JSFiddle:

    After getting the value out of local storage, the script stores the value in an attribute on the body tag. I made a custom action so that I could access any value from local storage as well as make it easy to reuse. Here’s what the final custom action looked like:

Figure2.jpg

    Notice the JavaScript we drafted is on line 11 and subsequently injected and executed on line 17. Lastly, once we have extracted the value (line 24) we delete the attribute as it is no longer needed. Here is a sample call to the custom action, the session variable is stored in retValue. From there, you can do whatever you want with it, including passing it to an API call; which is what set me on this adventure to begin with.

Figure3.jpg

    This post illustrates how we were able to extend capabilities by utilizing a custom action that could be used in numerous tests. Custom actions are a good way to encapsulate complex operations into a simple, easy to use keyword.   Happy testing!

More to explore