Hi Team,
I want to compare a string to a list and see if the string is present in the list.
The string is - phy-interface [test] of type [Control] with port [1] and slot [1] has invalid name
But the test case is failing saying pattern does not match.
Is it because of the square brackets present in the code?, Please suggest
My Code
Get Verify Config Results
${verify_results}= Create List
@{results_list} Get WebElements ${VERIFY CONFIG RESULTS}
FOR ${element} IN @{results_list}
${results} Get Text ${element}
Append To List ${verify_results} ${results}
END
[Return] ${verify_results}
Verify Message In Verify Config Results
Open Verify Drawer
${config_results} Get Verify Config Results
Should Contain Match ${config_results}
… phy-interface [test] of type [Control] with port [1] and slot [1] has invalid name
At first I was going to ask you to add a Log ${config_results} to verify it’s actually a list of strings, but then I tried it and got the same result as you using Robot Framework 5.0 (Python 3.9.10 on darwin), I then upgraded to Robot Framework 6.0.2 (Python 3.9.10 on darwin) and reproduced the same result again.
I also confirmed this behaviour with square brackets is different to the equivalent string using round or curly brackets, this issue is specific to square brackets.
I believe you may have found a bug. @pekkaklarck do you know who maintains Collections Library?
Here is my test example (Only uses BuiltIn and Collections Libraries)
madhurya.robot
*** Settings ***
Library Collections
*** Variables ***
${verify_message} phy-interface [test] of type [Control] with port [1] and slot [1] has invalid name
*** Test Cases ***
madhurya
${config_results} Get Verify Config Results
Log ${config_results}
# Should Contain Match ${config_results}
# ... phy-interface [test] of type [Control] with port [1] and slot [1] has invalid name
Should Contain Match ${config_results} ${verify_message}
madhurya 2
${verify_message}= Set Variable madhurya_3
@{results}= Create List madhurya_1 madhurya_2 madhurya_3 madhurya_4 madhurya_5 madhurya_6
Log ${results}
Should Contain Match ${results} ${verify_message}
madhurya 3
@{config_results}= Get Verify Config Results Strings
Log ${config_results}
# Should Contain Match ${config_results}
# ... phy-interface [test] of type [Control] with port [1] and slot [1] has invalid name
Should Contain Match ${config_results} ${verify_message}
madhurya 4
${verify_message}= Set Variable example [1] string [1]
@{config_results}= Build a list of strings with square brackets
Log ${config_results}
Should Contain Match ${config_results} ${verify_message}
madhurya 5
${verify_message}= Set Variable example (1) string (1)
@{config_results}= Build a list of strings with round brackets
Log ${config_results}
Should Contain Match ${config_results} ${verify_message}
madhurya 6
${verify_message}= Set Variable example {1} string {1}
@{config_results}= Build a list of strings with curly brackets
Log ${config_results}
Should Contain Match ${config_results} ${verify_message}
*** Keywords ***
Get Verify Config Results
@{results}= Create List phy-interface [test] of type [Control] with port [0] and slot [0] has invalid name
Append To List ${results} phy-interface [test] of type [Control] with port [0] and slot [1] has invalid name
Append To List ${results} phy-interface [test] of type [Control] with port [0] and slot [2] has invalid name
Append To List ${results} phy-interface [test] of type [Control] with port [1] and slot [0] has invalid name
Append To List ${results} phy-interface [test] of type [Control] with port [1] and slot [1] has invalid name
Append To List ${results} phy-interface [test] of type [Control] with port [2] and slot [0] has invalid name
Append To List ${results} phy-interface [test] of type [Control] with port [2] and slot [1] has invalid name
Append To List ${results} phy-interface [test] of type [Control] with port [3] and slot [0] has invalid name
Append To List ${results} phy-interface [test] of type [Control] with port [3] and slot [1] has invalid name
[Return] ${results}
Get Verify Config Results Strings
@{results}= Create List
FOR ${i} IN RANGE 3
FOR ${j} IN RANGE 3
${strng}= Set Variable phy-interface [test] of type [Control] with port [${i}] and slot [${j}] has invalid name
Append To List ${results} ${strng}
END
END
[Return] ${results}
Build a list of strings with square brackets
@{results}= Create List
FOR ${i} IN RANGE 3
FOR ${j} IN RANGE 3
${strng}= Set Variable example [${i}] string [${j}]
Append To List ${results} ${strng}
END
END
[Return] ${results}
Build a list of strings with round brackets
@{results}= Create List
FOR ${i} IN RANGE 3
FOR ${j} IN RANGE 3
${strng}= Set Variable example (${i}) string (${j})
Append To List ${results} ${strng}
END
END
[Return] ${results}
Build a list of strings with curly brackets
@{results}= Create List
FOR ${i} IN RANGE 3
FOR ${j} IN RANGE 3
${strng}= Set Variable example {${i}} string {${j}}
Append To List ${results} ${strng}
END
END
[Return] ${results}
I’m not sure where Collections Library is maintained, I think it’s one of the BuitIn Libraries, but most issue tracking systems have a follow option if there’s an existing issue, otherwise if you need to raise it you’ll automatically get notified.
Hopefully we’ll both find out in the next few days.
This keyword uses glob patterns for matching and with them square brackets have a special meaning so that, for example, [abc] matches either a, b or c. If you want to have literal [abc] in a glob pattern, you need to escape it like [[]abc]. You could also use ?abc], but then then any character will match ?. If you use [[], it will only match [.