Skip to content

Add "Get Variable Type" keyword to BuiltIn library#5683

Open
b-vamsipunnam wants to merge 1 commit into
robotframework:masterfrom
b-vamsipunnam:feature/add-get-variable-type-keyword
Open

Add "Get Variable Type" keyword to BuiltIn library#5683
b-vamsipunnam wants to merge 1 commit into
robotframework:masterfrom
b-vamsipunnam:feature/add-get-variable-type-keyword

Conversation

@b-vamsipunnam

Copy link
Copy Markdown

Summary

Adds a new BuiltIn keyword Get Variable Type that returns the runtime type of a value using Robot Framework friendly type names.

Motivation

Robot Framework currently lacks a direct BuiltIn keyword for inspecting the runtime type of a value. Users typically rely on Python evaluation syntax:

${type}=    Evaluate    type($value).__name__

While functional, this mixes Python-specific syntax into test data, reduces readability for non-Python users, and is less discoverable than a dedicated keyword.

The new keyword offers a cleaner, more self-documenting alternative:

${type}=    Get Variable Type    ${value}

This is particularly useful for dynamic test data handling, building reusable and generic keywords, debugging variables, and implementing type-aware logic in keyword-driven and data-driven automation.

Implementation

  • Added Get Variable Type keyword in src/robot/libraries/BuiltIn.py

  • Returns normalized, user-friendly type names:

    • string
    • integer
    • float
    • boolean
    • list
    • dictionary
    • tuple
    • set
    • none
  • Returns object for custom classes and other unsupported types

  • Properly handles bool before int because bool is a subclass of int in Python

Tests

Added acceptance tests covering:

  • String values
  • Integer values
  • Float values
  • Boolean values
  • Lists
  • Dictionaries
  • Tuples
  • Sets
  • None values
  • Custom objects

Files Changed

  • src/robot/libraries/BuiltIn.py
  • atest/testdata/standard_libraries/builtin/get_variable_type.robot
  • atest/robot/standard_libraries/builtin/get_variable_type.robot

Related Issues

No existing issue found.

Thank you for your review and feedback.

@pekkaklarck

Copy link
Copy Markdown
Member

What's the use case for this functionality?

@b-vamsipunnam

Copy link
Copy Markdown
Author

Hi @pekkaklarck ,

One use case is building generic, reusable keywords that need to handle different input types at runtime.

For example:

${type}=    Get Variable Type    ${data}

IF    '${type}' == 'list'
    Process List    ${data}
ELSE IF    '${type}' == 'dictionary'
    Process Dictionary    ${data}
ELSE
    Process Scalar    ${data}
END

Another scenario is working with dynamic data returned from APIs, JSON files, variable files, or custom libraries, where it can be helpful to quickly check or debug the runtime type of a value before processing it further. For example, verifying that a returned field is a list or dictionary as expected.

The main motivation is improving readability and discoverability rather than adding functionality that isn't already possible with Evaluate.

@b-vamsipunnam b-vamsipunnam changed the title Add Get Variable Type keyword to BuiltIn library Add "Get Variable Type" keyword to BuiltIn library Jun 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants