hi i am new in robot framework
I want to compare two number so
first I have fetch two value from from UI after that i want compare both the value so
${count1}= Set Variable ${xyz}
${count2}= Set Variable ${abc}
${Count3}= Set Variable ${$count1}+${count2}} # o/p=("1234")
${count4} = Replace String ${count3} ${EMPTY} ${EMPTY}
${count5} = Convert to string ${count4}
${count6}= Get Text ${loc_count} # o/p= data (1234)
${Count7} = Remove String ${login} data
${Count8} = Convert to string ${count7}
Log To Console ${count7}
Should Be Equal ${count5} ${count8}
so in console I have get (1234) != (1234)
I dont know why these happen
instead of that I have also try for convert to string i have convert to number but that time
it showed 1234 can not convert into floating point number :value error could nt convert string to float
code
if i try to convert the string to number
${count3} = Convert To Number ${_count2}
Should Be Equal will treat them as different if one is a string and one is a number, or even if one is a float and one is an integer Should Be Equal As <type> will cast both to the same type before comparing them.
It should also have a message telling you why they are not equal.
${ABC} Get Text ${locator_Ac} o/p=1234
${DEF} Get Text ${locator_Bc} 0/p 2356
${count} Evaluate ${ABC} + ${DEf} # o/p=("3590")
${count1}= Get Text ${loc_count} # o/p= data (3590)
${Count2} = Remove String ${count1} data
Log To Console ${count7}
Should Be Equal ${count1} ${count2}
so in console I have get (3590) != (3590)
I dont know why these happen
i have check data type both variable is int
so i have also check with should be equal as integer and should be equal as number buy it showed 3590 can not convert into floating point number :value error could nt convert string to float
It is still no valid robot code you posted there.
And you compare ${count1} with ${count2}
One is “data (3590)” the other one is “(3590)”
Not sure if you also have confusion in your variable names in your real code.
The other thing is that ${code} is an integer. so you should compare both values as number.
i would strongly recommend to use more spelling names for variables.
See this running example:
Second test is a bit shorter, because it replaces all “non digits” (\D) from the string.
Thanks
code is like that
${AC} Get Text ${loc_abc} 2064
${BC} Get Text ${loc_cde} 3625
${count} Evaluate ${AC} + ${BC} output 5689
${count1}= Set Variable (${count}) output (5689)
${CD}= Get Text ${loc_count} output= login (5689)
${count2} = Remove String ${CD} login
${count3} = Remove String ${count2}
Should Be Equal As Numbers ${count1} ${count3}
output is like (5689)' cannot be converted to a floating point number: ValueError: could not convert string to float: '(5689)'
Sorry I didn’t realise the two items you were trying to compare had the brackets ( and ) in them, in this case you should use Should Be Equal As Strings
A couple of other things:
when you start a line with a variable in a test or a keyword you should follow it with an =, e.g. ${AC} becomes ${AC}=
the line ${count3}= Remove String ${count2}, what are you removing? Perhaps you meant to use ${count3}= Remove String ${count2} ${SPACE}
Putting it all together it would look something like this:
${AC}= Get Text ${loc_abc} 2064
${BC}= Get Text ${loc_cde} 3625
${count}= Evaluate ${AC} + ${BC} # output 5689
${count1}= Set Variable (${count}) # output (5689)
${CD}= Get Text ${loc_count} # output= login (5689)
${count2}= Remove String ${CD} login
${count3}= Remove String ${count2} ${SPACE}
Should Be Equal As Strings ${count1} ${count3}