Need Help with one Step

Hello Team,

I need help in automation one scenario.

Our website has some products which are on sale. When an Item is on sale the product price looks like this.

When the product is not on sale it looks like this :

I am trying to save the sale value 25.49 into a variable and to do so I am first trying to see if the product is on sale using :

if (WebUI.verifyElementHasAttribute(findTestObject(‘New Folder/00/h2_30002449’),
‘del’, 0)) {
pdp_product_price_1 = WebUI.getText(findTestObject(‘New Folder/00/span_2449’)).equals(
‘$’)
}

if (WebUI.verifyElementNotHasAttribute(findTestObject(‘New Folder/00/h2_30002449’),
‘del’, 0, FailureHandling.STOP_ON_FAILURE)) {
pdp_product_price_1 = WebUI.getText(findTestObject(‘3_Page_PDP/PDP_Product_Price’)).replace(‘$’, ‘’)
}

But every time I run this I get below error :

Test Cases/WebSite Monitoring/WebSite Sanity/One Big Test Case/Fix PDP FAILED.

Reason:

com.kms.katalon.core.exception.StepFailedException: Unable to verify if object ‘Object Repository/New Folder/00/h2_30002449’ has attribute ‘del’

at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)

at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:26)

at com.kms.katalon.core.webui.keyword.builtin.VerifyElementHasAttributeKeyword.verifyElementHasAttribute(VerifyElementHasAttributeKeyword.groovy:100)

at com.kms.katalon.core.webui.keyword.builtin.VerifyElementHasAttributeKeyword.execute(VerifyElementHasAttributeKeyword.groovy:69)

at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:56)

at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.verifyElementHasAttribute(WebUiBuiltInKeywords.groovy:3182)

at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$verifyElementHasAttribute$9.call(Unknown Source)

at Fix PDP.run(Fix PDP:75)

at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)

at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)

at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:336)

at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:327)

at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:306)

at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:298)

at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:232)

at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)

at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)

at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)

at TempTestCase1556571641692.run(TempTestCase1556571641692.groovy:21)

Caused by: com.kms.katalon.core.exception.StepFailedException: Object ‘Object Repository/New Folder/00/h2_30002449’ does not have attribute ‘del’

at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)

at com.kms.katalon.core.webui.keyword.builtin.VerifyElementHasAttributeKeyword$_verifyElementHasAttribute_closure1.doCall(VerifyElementHasAttributeKeyword.groovy:89)

at com.kms.katalon.core.webui.keyword.builtin.VerifyElementHasAttributeKeyword$_verifyElementHasAttribute_closure1.call(VerifyElementHasAttributeKeyword.groovy)

at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)

… 17 more

First, check that is the correct object, then check it has the del attribute.

I added VerifyElementPresent and it passed. Its the same element which has those 2 attributes

What two attributes? You’re looking for one attribute, called del. Showing me your test outcome a second time doesn’t help. Show me the HTML. (And if, by chance, it doesn’t have a del attr, you know what your problem is, right?)

Do I really need to send you here, Manpreet?

I posted the screenshot of the element in my 1st Post. I am posting it again here. Let me know if I am missing anything. The element I am targeting has 2 attributes and by using

WebUI.verifyElementHasAttribute(findTestObject(‘New Folder/00/h2_30002449’),‘del’, 0)

I am just trying to verify the element contains one of the attribute “del”

Oops. My bad.

Those are elements not attributes.

The element you highlighted has one child element (h2). The h2 has two children, del and span. Change your Test Object to target the del element (or the span).

1 Like

Woooooo, Its working now.

Thanks,

@Russ_Thomas Now I am facing another issue but that is programming issue I believe.

I have code below :

if (WebUI.verifyElementPresent(findTestObject(‘New Folder/00/del_3000’), 0, FailureHandling.STOP_ON_FAILURE)) {

pdp_product_price_1 = WebUI.getText(findTestObject('New Folder/00/span_2449'), FailureHandling.STOP_ON_FAILURE).replace(
    '$', '')

/* Converting the value of pdp_product_price to BigDecimal  */

BigDecimal pdp_product_price = new BigDecimal(pdp_product_price_1)

WebUI.println('The Price of Product on PDP page is : ' + pdp_product_price)

}

else {

pdp_product_price_1 = WebUI.getText(findTestObject('3_Page_PDP/PDP_Product_Price')).replace('$', '')

/* Converting the value of pdp_product_price to BigDecimal  */
	
BigDecimal pdp_product_price = new BigDecimal(pdp_product_price_1)
	
WebUI.println('The Price of Product on PDP page is : ' + pdp_product_price)

}

The issue I am facing is I am not able to use variable pdp_product_price outside of this if else statement. I would like to do some other calculations using the variable pdp_product_price but I am getting error :

================================================================================

Test Cases/WebSite Monitoring/WebSite Sanity/One Big Test Case/Fix PDP FAILED.

Reason:

groovy.lang.MissingPropertyException: No such property: pdp_product_price for class: Script1556570487648

at Fix PDP.run(Fix PDP:336)

at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)

at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)

at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:336)

at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:327)

at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:306)

at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:298)

at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:232)

at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)

at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)

at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)

at TempTestCase1556575840872.run(TempTestCase1556575840872.groovy:21)

Hi,

First, you have to use FailureHandling.OPTIONAL. If not, you can’t go inside the else statement.

Because you define the varaible inside the if and the else statement.
Before if else, write
BigDecimal pdp_product_price
and in the if statement and the else statement
pdp_product_price = new BigDecimal(pdp_product_price_1)

1 Like

@HeleneB The solution worked perfectly, Thanks for the help.