Fix Open Test Browser Viewport Error in Salesforce Playwright Robot Framework

Summary

  • Problem: Open Test Browser keyword from SalesforcePlaywright.robot throws viewport.width: expected integer, got string when any arguments are supplied.
  • Root cause: The keyword expects numeric arguments (width/height) without the x separator and parses them as integers; passing a string like "1920x1080" or omitting the required integer conversion leads to a type mismatch in Playwright’s browser.newContext call.

Root Cause

  • The underlying Playwright library requires integer values for viewport.width and viewport.height.
  • The Robot Framework wrapper incorrectly forwards the raw argument string to Playwright, so "1920x1080" (or any quoted value) is treated as a string.
  • When the keyword is called with no arguments, the wrapper falls back to defaults, which are already integers, so it works.

Why This Happens in Real Systems

  • Loose typing in Robot Framework variables makes it easy to pass strings inadvertently.
  • Many examples omit explicit size arguments, hiding the conversion step.
  • The SalesforcePlaywright.robot resource file does not perform validation or conversion for size, width, or height parameters, assuming the caller supplies proper integer types.

Real-World Impact

  • Test suites abort during the browser initialization phase, preventing any subsequent UI verification.
  • Flaky pipelines: runs without arguments succeed, but runs that set a custom viewport fail, leading to inconsistent CI results.
  • Junior engineers spend excessive time debugging unrelated test logic, wasting valuable sprint time.

Example or Code (if necessary and relevant)

*** Settings ***
Resource    cumulusci/robotframework/SalesforcePlaywright.robot

*** Test Cases ***
Open Custom Browser Correctly
    Open Test Browser    size=1920,1080

Note: The size argument is split into two integer parameters (width,height) separated by a comma, not an x.

How Senior Engineers Fix It

  • Validate input before passing to the keyword: split "1920x1080" into two integers.

  • Create a wrapper keyword that performs the conversion:

    • Parse the string with a regular expression.
    • Convert each part to int.
    • Call Open Test Browser with width=<int> and height=<int> arguments.
  • Update the resource file (if maintainable) to accept the size argument in WxH format and perform the conversion internally.

  • Add type‑checking tests to ensure future contributors cannot re‑introduce the bug.

Why Juniors Miss It

  • They assume Robot Framework will automatically coerce a "1920x1080" string to two integers.
  • Lack of familiarity with Playwright’s strict type requirements.
  • Overreliance on copy‑pasting examples that hide the conversion step.
  • Insufficient unit tests around custom keyword wrappers, so the problem surfaces only at runtime.

Leave a Comment