Implementation:MarketSquare Robotframework browser Device Descriptors Keywords
| Knowledge Sources | |
|---|---|
| Domains | Browser Automation, Device Emulation |
| Last Updated | 2026-02-12 05:40 GMT |
Overview
Provides Robot Framework keywords for retrieving Playwright device descriptors to emulate specific mobile devices during browser testing.
Description
The Devices class extends LibraryComponent and exposes two keywords: Get Devices and Get Device. Get Devices returns a dictionary of all available Playwright device descriptors (viewport size, user agent, device scale factor, etc.). Get Device retrieves a single descriptor by exact device name. These descriptors can be passed directly to New Context to configure a browser context that emulates a specific device such as an iPhone or Pixel phone.
The keywords communicate with the Playwright backend over gRPC, sending Request.Empty or Request.Device messages and deserializing the JSON response into Python dictionaries.
Usage
Use these keywords when you need to emulate a specific mobile device in your Robot Framework browser tests. Retrieve device descriptors at the start of a test and pass them to New Context to set viewport dimensions, user agent strings, and other device-specific properties without manual configuration.
Code Reference
Source Location
- Repository: MarketSquare_Robotframework_browser
- File: Browser/keywords/device_descriptors.py
- Lines: 1-62
Signature
class Devices(LibraryComponent):
@keyword(tags=("Getter", "BrowserControl"))
def get_devices(self) -> dict: ...
@keyword(tags=("Getter", "BrowserControl"))
def get_device(self, name: str) -> dict: ...
Import
from Browser.keywords.device_descriptors import Devices
I/O Contract
Get Devices
| Direction | Name | Type | Description |
|---|---|---|---|
| Output | return | dict | Dictionary of all Playwright device descriptors keyed by device name |
Get Device
| Direction | Name | Type | Description |
|---|---|---|---|
| Input | name | str | Exact name of the device (e.g., "iPhone X", "Pixel 5") |
| Output | return | dict | Single device descriptor dictionary containing viewport, userAgent, deviceScaleFactor, etc. |
Usage Examples
Robot Framework
*** Settings ***
Library Browser
*** Test Cases ***
Emulate iPhone X
New Browser chromium headless=True
${device}= Get Device iPhone X
New Context &{device}
New Page https://example.com
${viewport}= Get Viewport Size
Log Viewport: ${viewport} # { "width": 375, "height": 812 }
List All Available Devices
${devices}= Get Devices
Log ${devices}