Log to Console and Should be equal issues in Robot Framework

I have below application under test.

I am using Selenium2Library-Python-RobotFramework.
Below is my code where I am fetching the expected price with the help of xpath. For original price I have already set the variables in variable.robot.

    ${ExpectedPriceProductAPrice} =   Get Text   xpath=//span[@id='Price']
    sleep  2
    Log To Console    Price is  ${ExpectedPriceProductAPrice}
    ${ExpectedPriceProductACount} =   Get Text   xpath=//span[@id='Count']
    sleep  2
    Log To Console    Count is   ${ExpectedPriceProductACount}

    should be equal   ${ExpectedPriceProductAPrice}   ${OriginalPriceProductAPrice}
    should be equal   ${ExpectedPriceProductACount}   ${OriginalPriceProductACount}
    should be equal   ${ExpectedPriceProductBPrice}   ${OriginalPriceProductBPrice}
    should be equal   ${ExpectedPriceProductBCount}   ${OriginalPriceProductBCount}

I am facing two issues :

  1. Values are not getting log to console.
  2. If should be equal is failed for first statement then it is not moving ahead to check all other should be equal conditions

Should keywords are strict conditions, they will stop test execution and mark the test failed, as soon it fails.

For you case, you should collect each assertion and only fail in the end (or just report the results).
You can use at least three different techniques:

  • ${result_1}= Set Variable ${ExpectedPriceProductAPrice} == ${OriginalPriceProductAPrice}
  • ${var_2} ${result_2}= Run Keyword and Ignore Error Should Be Equal ${ExpectedPriceProductACount} ${OriginalPriceProductACount}
  •      IF    ${ExpectedPriceProductBPrice} == ${OriginalPriceProductBPrice}
             ${result}=    Set Variable    ${True}
         END    # just an example, in this case is better Set Variable If
    

You can create a list or dictionary and append results to it. You could use a loop, and variables with a dynamic name…

3 Likes