i working on a robot framework project. The target of the test is to evaluate if the xml file name respect the specific pattern.
First attempt:
*** Variables ***
${FILENAME} 222222_XT211-D(SM211)_Scenario_SetFrameCounter_result_6157_ok_02112024-172720.xml
${PATTERN} ^\d{6}_XT\d{3}-D\(SM\d{3}\)_Scenario_SetFrameCounter_result_\d{4}_ok_\d{8}-\d{6}\.xml$
*** Test Cases ***
Validate Xml Filename Structure
Should Match ${FILENAME} ${PATTERN}
Second attempt:
*** Variables ***
${FILENAME} 222222_XT211-D(SM211)_Scenario_SetFrameCounter_result_6157_ok_02112024-172720.xml
${PATTERN} ^\d{6}_XT\d{3}-D\(SM\d{3}\)_Scenario_SetFrameCounter_result_\d{4}_ok_\d{8}-\d{6}\.xml$
*** Test Cases ***
Validate Xml Filename Structure
Should Match Rexep ${FILENAME} ${PATTERN}
But as result, it always fails and i don't know exactly where's the fail.: This is what i got as result. '222222_XT211-D(SM211)_Scenario_SetFrameCounter_result_6157_ok_02112024-172720.xml' does not match '^d{6}_XTd{3}-D(SMd{3})_Scenario_SetFrameCounter_result_d{4}_ok_d{8}-d{6}.xml$'
You should use double backslashes because Robot Framework itself is using backslashes to escape test data.
So in you case ${PATTERN}
would be:
*** Variables ***
${PATTERN} ^\\d{6}_XT\\d{3}-D\\(SM\\d{3}\\)_Scenario_SetFrameCounter_result_\\d{4}_ok_\\d{8}-\\d{6}\\.xml$