Role of User Agent String in Software Testing

In this blog post, we will discuss about one of the key topics in Software Testing. Usage of mobiles, tablets and other handheld devices are sky rocketing now-a-days. It is vital to validate compatibility, functionality and performance of the devices and it applications (apps).

Role of user agent plays a critical role in testing web and software apps across various platforms.

What is User Agent?

User Agent is an identity of a client (user). A user agent has details about the client such as OS and its version, browser name and its version. Server processes the requests and provides responses for your browser by identifying using User Agent.

User Agent string resides in the header section of each request. Below is the sample header which has a user agent.

Please note Microsoft Internet Explorer identifies as a Mozilla for historical reasons. Below is the significance of each parameter in user agent. Pipe symbol ‘|’ is used only to separate the values. It will not be there in the actual request headers.

  • Mozilla/4.0 | Browser name and its version
  • Compatible | Compatibility token
  • MSIE 8.0 | Microsoft Internet Explorer 8.0 identifies as a current browser and its version
  • Windows NT6.1 | OS version i.e. this is for Windows 7
  • Trident/4.0 | Version of MSHTML which validates the compatibility view of the webpage.

Following code displays your user agent string:

alert(navigator.userAgent);

How user agent useful in testing?

To validate the compatibility and performance of the web applications in various platforms, user agent plays a vital role by sniffing.

How to change user agent in your browser?

If you are a Mozilla user, there is an add-on which switches the user agent of your browser. Download User Agent Switcher

Once you installed, it will adds a menu. See below snapshot.

You can see all the user agents in the form of XML here. For instance, if you want to validate how my website www.QAInsights.com will look in iPad. How do we achieve this? Read on.

Step 1

Get the user agent of iPad from the XML file. User agent of iPad is Mozilla/5.0 (iPad; U; CPU OS 4_2_1 like Mac OS X; ja-jp) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C148 Safari/6533.18.5

Step 2

  • Launch Mozilla. Go to Tools > Default User Agent > Edit User Agents…
  • Click on New > New User Agent. See below snapshot.

Step 3

In New User Agent dialog box, enter Description and paste the above user agent in User Agent field and other details as shown below and then click on OK.

Step 4

Type the www.QAInsights.com in the address bar and press enter. Mozilla displays the webpage as same as how it displays in iPad.

This add-on helps to validate the webpage look and feel. Also it reveals more cosmetic defects, if you use it in early stages of Software Development Life Cycle (SDLC).

How to perform performance testing using User Agent?

Using JMeter tool, it is much easy to send user agent string the request header by parameterizing user agents. We will see it in next blog post.

Advantages:

  • Quick Testing of apps and webpages across mobiles, tablets, and other handheld devices in different platforms
  • Easy Implementation
  • Freeware
  • Saves time and effort
  • Performance and Compatibility Testing can be achieved by changing the user agents

Happy Testing!

Subscribe to our QAInsights YouTube Channel. If you are enjoying our work, please do subscribe our free weekly newsletter or Google feeds.

About the Author

1 thought on “Role of User Agent String in Software Testing”

  1. Should we still be explicily changing our Useragent when testing via an emulation? Or is the emulation itself sufficient? Chrome, for example, has substantial device emulation tools in DevTools, but I do not think the device selection actually changes the Useragent being used. Useragent can be manually specified under Network conditions. Perhaps the DevTools device emulator IS also specifying the Useragent – the more I test with it, the more convinced I am that it is.

    Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Hamster - Launch JMeter Recent Test Plans SwiftlyDownload for free
+
Share via
Copy link