Pandit Biradar
Pandit Biradar

Reputation: 1877

robot test cases passing formatted variables from python to robot file

Can you please help me is there way to pass formatted string from python file to robot file suppose say below is my specific language py file

English.py file has below variable assigned

FILTERED_TEXT_LANG = "{} Selected"

Robot test cases is setting the variable is like below in robot file (user.robot)

${element} =     Set Variable    xpath=*//div[contains(@id,'org-selection-counter') and contains(text(),'${FILTERED_TEXT_LANG}.format(some_filtered_count)')]

This is required since different language is displaying the some_filtered_count in different way , is there way can make the changes from string formatted not if else conditions

Upvotes: 0

Views: 41

Answers (1)

pavelsaman
pavelsaman

Reputation: 8352

Well, there's a way, but not like this:

${element} =     Set Variable    xpath=*//div[contains(@id,'org-selection-counter') and contains(text(),'${FILTERED_TEXT_LANG}.format(some_filtered_count)')]

you can't use Python keywords, methods etc. directly in RF. But what you can do is create your custom keyword, either in RF, or in Python, that you latter use in RF and it will fill in a language into the string. Actually, you don't even need to create anything, just reuse what's already available in String library

I can imagine something like this:

${str_with_language}=    Replace String    ${FILTERED_TEXT_LANG}    {}    ENG
${element} =     Set Variable    xpath=*//div[contains(@id,'org-selection-counter') and contains(text(),'${str_with_language}')]

Upvotes: 1

Related Questions