TA: How to get the Session Storage data from your browser

Our test automation suite for a single page application (SPA) called service-hub, takes almost one hour to run all +- 200 scenario's in serie per browser. The amount of scenario's will keep on growing with the expansion of the product. So I needed to start using some clever tricks to speed up the process. One of those tricks is by testing in parallel sessions. This is a very good thing to figure out anyway, but is also taking more resources (and therefore cost more money). Another trick is by using the API for some of the preconditions that take a lot of time. But for that we need a token which is stored in the browsers Session Storage.

Scenario example

For the service-hub product which I'm testing, it takes precious time to add/remove a material from an activity if I need to do this all via the UI. There are many steps to take to make sure I'm on the correct page, tab, breadcrumb, sub-tab and finally the element and to cover all other scenario's that might be failing from other tests that can block any user interaction. Most of the steps I need to perform anyway, but I can make it faster by checking via the API if a material is already in the list and based on the precondition remove or add it before moving on. 

Session Storage

For the API I need a bearer token to be able to perform GET/POST actions. So after I'm a logged in user, I want to extract the bearer token from the browser so I can use the API for some preconditions. And it's easier than I thought.
So with that in place, I can now use this to add materials to the activity like this:
asset_id_1 = "b15940c5-3165-4cb5-a1f7-02dceeab86f0" asset_id_2 = "aaaaaaaa-1111-a1a1-b2b2-000000000000" asset_id_array = [asset_id_1, asset_id_2]
activity_id = "501206de-c88d-4108-9fc7-392c90a962de"
token = Token.get_access_token #Get the access token, for the header (see below)
url = "<base_url>/Activities/Default.AddMaterials"
payload = { "AddMaterialsCommand":{ "ActivityId":activity_id, "AssetsId":asset_id_array } }
headers = { "Authorization" => "Bearer #{token}", "Content-Type" => "application/json" }

# With the 'rest-client' gem we can now execute this command to add the materials to the activity
RestClient.post(url, payload.to_json, headers=headers)

Comments

Popular posts from this blog

PowerShell - How to overcome Azure VM's fixed resolution limitation

TA Basics: Website Test Automation on mobile devices via Appium server

TA: Who doesn't like proxies? Me!