Creating mobile browser profiles

How to create mobile browser profiles with different user agents and screen sizes.

The built-in action send command to browser is used within your TestArchitect test to specify a mobile browser profile to be invoked during testing, or even to change the environment for the currently invoked emulator to customize its behaviors. Naturally, within a test, you can call this built-in action any number of times to repeat testing with a variety of profiles for different mobile devices. The profiles are coded in JavaScript Object Notation (JSON), and with Chrome debugging protocol.

Important:
Basic JSON syntax as required for creating profiles is as follows:

Note that you can learn more about JSON syntax here.

Tip:
You can define as many parameters as you need for a mobile browser profile. However, it is recommended that your JSON string contain the following basic information.

  1. User Agent (UA): The browser’s UA string. It identifies the browser and contains information about the browser version, operating system and its version, and specific browser enhancements. For example, Galaxy S5 has this UA:

    Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.23 Mobile Safari/537.36
    

    Tip:
    You can find various mobile UA strings from the following links:

    Remember:
    To define a UA string, use the setUserAgentOverride method with the userAgent parameter. For example: The following JSON string defines a given UA string.

    { "method" : "Network.setUserAgentOverride",
    "params" : { "userAgent" : "Mozilla/5.0(Linux; Android 4.4.4; Nexus 5 Build/KTU84P) AppleWebKit/537.36 (KHTML, like Gecko)Chrome/38.0.2125.114 Mobile Safari/537.36" } }
    
  2. Screen Width/Screen Height: Specify the browser screen size, including width and height, in CSS pixels. Note that this is not necessarily the same as the device’s physical screen size. For example, the iPhone 5 uses 2×2 physical pixels to display 1 CSS pixel, so the browser screen dimensions are half the physical screen dimensions.

    Tip:
    You can find various mobile browser screen sizes here:

    Remember:
    To define screen size, use the setDeviceMetricsOverride method with the width and height parameters. For example: The following JSON string defines the browser screen size.

    { "method" : "Emulation.setDeviceMetricsOverride", "params" : { "width": 260, "height": 640 } }
    
  3. Device Pixel Ratio (DPR): Specify DPR, the number of physical pixels per CSS pixels. For example, iPhone 5 has DPR=2, meaning it uses 2×2 physical pixels to show 1 CSS pixel. Web applications can use the device pixel ratio to conditionally load different CSS or images.

    Tip:
    You can find DPR values for various devices here:

    Remember:
    To define DPR, use the setDeviceMetricsOverride method with the deviceScaleFactor parameter.

  4. Trigger touch events: Toggles mouse event-based touch event emulation. This touch screen emulator lets you accurately test touch events and sequences as if you were using a touch-enabled device.

    Remember:
    To simulate touch events, use the setTouchEmulationEnabled method with the enabled parameter. For example:

    { "method" : "Emulation.setTouchEmulationEnabled", "params" : { "enabled" : true } }
    

In summary, the below JSON string defines the following parameters for a given mobile browser profile:

Tip:
You may want to validate your JSON string with the free resource jsoneditoronline.org/, to ensure that its syntax and format are accurate.

Copy the JSON string into the command argument of the send command to browser built-in action.

                            window            command                                                                                                                                                                                                             variable                        
send command to browser     google            [{"method":"Network.setUserAgentOverride","params":{"userAgent":"Mozilla/5.0 (Linux; Android 4.4.4; Nexus 5 Build/KTU84P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.114 Mobile Safari/537.36"}},      >>emulator
                                              {"method":"Emulation.setDeviceMetricsOverride","params":{"mobile":true,"width":260,"height":640,"deviceScaleFactor":2,"fitWindow":false}},
                                              {"method":"Emulation.setTouchEmulationEnabled","params":{"enabled":true}}]

Copyright © 2024 LogiGear Corporation. All rights reserved. LogiGear is a registered trademark, and Action Based Testing and TestArchitect are trademarks of LogiGear Corporation. All other trademarks contained herein are the property of their respective owners.

LogiGear Corporation

1730 S. Amphlett Blvd. Suite 200, San Mateo, CA 94402

Tel: +1 (650) 572-1400