If Else Issue (Greater than failing)

What am I missing???
Entering unit price of 3.25
another at 3.35
The result should be between 3.25 and 3.35 ( tried result <= “3.25” && >= “3.35”) But didnt work


Code

WebUI.setText(findTestObject(‘Spending Search_OR/Page_Spending GovSpend/input_UnitPrice_1’), ‘3.25’)

WebUI.sendKeys(findTestObject(‘Spending Search_OR/Page_Spending GovSpend/input_UnitPrice_2’), Keys.chord(Keys.TAB))

WebUI.setText(findTestObject(‘Spending Search_OR/Page_Spending GovSpend/input_UnitPrice_2’), ‘3.35’)

WebUI.click(findTestObject(‘Spending Search_OR/Page_Spending GovSpend/button_Find best range’))

//WebUI.delay(10)

WebUI.setText(findTestObject(‘Spending Search_OR/Page_Bids GovSpend/input_Keyword’), ‘Shoe’)

WebUI.click(findTestObject(‘Spending Search_OR/Page_Spending GovSpend/button_Search1’))

WebUI.waitForElementPresent(findTestObject(‘Spending Search_OR/Page_Spending GovSpend/results_UnitPrice’), 20)

result = WebUI.getText(findTestObject(‘Spending Search_OR/Page_Spending GovSpend/results_UnitPrice’))

if (result < ‘$3.25’) {
KeywordUtil.markFailedAndStop(‘Dang, Something went wrong!!’)
WebUI.closeBrowser()
}
else if (result > ‘$3.35’) {
KeywordUtil.markFailedAndStop(‘Dang, Something went wrong!!’)
WebUI.closeBrowser()
}
else {
KeywordUtil.markPassed(‘Cool. Everything is working!!’)
WebUI.callTestCase(findTestCase(‘Automation/_Sign Out GovSpend Automation’), [:], FailureHandling.STOP_ON_FAILURE)
}

You’re comparing strings not numbers.

if ("rudi" < "russ") -> true
if ("russ" > "rudi") -> true

You should get the numeric values, without the “$” and compare those.

2019-10-25 14:13:33.490 DEBUG icSearch_Items_Keyword_Unit Price Filter - 12: if (result < “3.25”)

2019-10-25 14:13:33.492 DEBUG icSearch_Items_Keyword_Unit Price Filter - 13: else if (result > “3.35”)

2019-10-25 14:13:33.493 DEBUG icSearch_Items_Keyword_Unit Price Filter - 1: markFailedAndStop(“Dang, Something went wrong!!”)

2019-10-25 14:13:33.501 ERROR c.k.katalon.core.main.TestCaseExecutor - :x: Test Cases/WIP/BasicSearch_Items_Keyword_Unit Price Filter FAILED.

You’re still comparing strings, not numeric values.

clue:

if("200" < "4") -> true
if("4" > "200") -> true

Yes I got that but its not reading from the search table object to verify the results are between 3.25 and 3.35

Then I’m confused. This is the code you pasted. Your value I highlighted is a string.

result is assigned the result of calling getText which returns a string:

image

I think you’re comparing strings. Your code says you’re comparing strings. Where, “200” is less than “4”, for example. Because it’s lower alphabetically.

Im confused now
if I change both to lesser than TC passes only if I have the greater than there
results label has the numbers a text

Try this. This will create your result variable as a floating point number and cast the result from getText to a float as well:

float result = (float) WebUI.getText(...)

Then you can write…

if(result < 3.35) // NO QUOTES!!!

That looks like it displays the whole page

Cannot cast object 'Date

expand_more

more_vert
and so on…
Agency Name

You need to remove the $ sign from your string
You can use result = result.replace("$", “”)
Then convert your string into a double then you’ll be able to compare it.

something like:
double result2
result2 = Double.parseDouble(result.replace("$", “”))

I don’t know what you expect me to do with that. Sorry. I give up.

If I paste the error it will be a-lot but here goes (Ive been on this for about 6 hrs so i understand your frustration

10-25-2019 03:08:56 PM Test Cases/WIP/BasicSearch_Items_Keyword_Unit Price Filter

Elapsed time: 31.518s

Test Cases/WIP/BasicSearch_Items_Keyword_Unit Price Filter FAILED.

Reason:

org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'Date

expand_more

more_vert

Agency Name

float result = (float) WebUI.getText(findTestObject(‘Spending Search_OR/Page_Spending GovSpend/results_UnitPrice’))

if (result < 3.25) {
KeywordUtil.markFailedAndStop(‘Dang, Something went wrong!!’)
WebUI.closeBrowser()
}
else if (result > 3.35) {
KeywordUtil.markFailedAndStop(‘Dang, Something went wrong!!’)
WebUI.closeBrowser()
}
else {
KeywordUtil.markPassed(‘Cool. Everything is working!!’)
WebUI.callTestCase(findTestCase(‘Automation/_Sign Out GovSpend Automation’), [:], FailureHandling.STOP_ON_FAILURE)
}

I’ve tried this as well

if (angle >= 90 && angle <= 180) {

// do something

}

This worked

if (result <= ‘3.25’ && result >= ‘3.35’) {

KeywordUtil.markFailedAndStop(‘Dang, Something went wrong!!’)

WebUI.closeBrowser()

}

else {

KeywordUtil.markPassed(‘Cool. Everything is working!!’)

WebUI.callTestCase(findTestCase(‘Automation/_Sign Out GovSpend Automation’), [:], FailureHandling.STOP_ON_FAILURE)

}

thank for your help @Russ_Thomas

That’s a crazy error. Why the hell is it talking about “Date” objects?

Make sure this TestObject is defined correctly: Spending Search_OR/Page_Spending GovSpend/results_UnitPrice

And change the result line to this - I think maybe there’s an issue casting to float so let’s convert instead.

float result = WebUI.getText(...).toFloat()

I thought I had it Dang but I changed the prices and still passes ugh

@Russ_Thomas your latest suggestion gave me the same results as The first float suggestion

example

result = WebUI.getText(findTestObject(‘Spending Search_OR/Page_Spending GovSpend/results_UnitPrice’))

if (result <= ‘0.00’ && result >= ‘0.01’) {

KeywordUtil.markFailedAndStop(‘Dang, Something went wrong!!’)

WebUI.closeBrowser()

}

else {

KeywordUtil.markPassed(‘Cool. Everything is working!!’)

WebUI.callTestCase(findTestCase(‘Automation/_Sign Out GovSpend Automation’), [:], FailureHandling.STOP_ON_FAILURE)

}

If I change the operator TC passes

if (result < “3.25”)

else if (result == “3.35”)

else
markPassed(“Cool. Everything is working!!”)
✓ Cool. Everything is working!!

something about the > maybe a bug?