'Robot Framework - Greater than or equal and Less than or equal
I am trying to set value for giftAmt based on Don_Number value. When I try to execute always goes to first ELSE IF condition. Even if Don_Number is 70 it stores GiftAmt as 15 only. I tried with IF and also Run keyword. Please advise how to resolve this.
(example if Don_Number is 250$ then GiftAmt should be 25)
IF ${Don_Number} <= 100
${GiftAmt} Set Variable 10
ELSE IF ${Don_Number} >= 101 or ${Don_Number} <= 149
${GiftAmt} Set Variable 15
ELSE IF ${Don_Number} >= 150 or ${Don_Number} <= 199
${GiftAmt} Set Variable 20
ELSE IF ${Don_Number} >= 200 or ${Don_Number} <= 299
${GiftAmt} Set Variable 25
ELSE IF ${Don_Number} >= 300 or ${Don_Number} <= 399
${GiftAmt} Set Variable 35
END
or Run Keyword If ${Don_Number} >=101 or ${Don_Number} <=149 ${GiftAmt} Set Variable 15 Run Keyword If ${Don_Number} >=150 or ${Don_Number} <=199 ${GiftAmt} Set Variable 20 Run Keyword If ${Don_Number}>=200 or ${Don_Number} <=299 ${GiftAmt} Set Variable 25 Run Keyword If ${Don_Number} >=300 or ${Don_Number} <=399 ${GiftAmt} Set Variable 35
Solution 1:[1]
You need to use and instead of or in the conditions, otherwise for any number greater than 100, ${Don_Number} >= 101 will be evaluated to True causing value 15 to be selected. Another option a bit cleaner will be:
IF ${Don_Number} <= 100
${GiftAmt} Set Variable 10
ELSE IF 101 <= ${Don_Number} <= 149
${GiftAmt} Set Variable 15
ELSE IF 150 <= ${Don_Number} <= 199
${GiftAmt} Set Variable 20
ELSE IF 200 <= ${Don_Number} <= 299
${GiftAmt} Set Variable 25
ELSE IF 300 <= ${Don_Number} <= 399
${GiftAmt} Set Variable 35
END
Solution 2:[2]
Dan has given you a crisp code but if you want it in more detail to understand it better then, You can just modify it slightly , as below:
IF ${Don_Number} <= 100
${GiftAmt} Set Variable 10
ELSE IF ${Don_Number} >= 101 and ${Don_Number} <= 149
${GiftAmt} Set Variable 15
ELSE IF ${Don_Number} >= 150 and ${Don_Number} <= 199
${GiftAmt} Set Variable 20
ELSE IF ${Don_Number} >= 200 and ${Don_Number} <= 299
${GiftAmt} Set Variable 25
ELSE IF ${Don_Number} >= 300 and ${Don_Number} <= 399
${GiftAmt} Set Variable 35
END
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Dan Constantinescu |
| Solution 2 | Sujit Neb |
