Execute if/else when Element exists


#21

Hi
Can anyone tell me how to find text in webpage using katalon using xpath


#22

//*[text()='abc']

returns an element with specified text.


#23

Reason:
groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.verifyElementPresent() is applicable for argument types: (java.lang.Boolean) values: [false]
Possible solutions: verifyElementPresent(com.kms.katalon.core.testobject.TestObject, int), verifyElementPresent(com.kms.katalon.core.testobject.TestObject, int, com.kms.katalon.core.model.FailureHandling), verifyAlertPresent(int), verifyElementNotPresent(com.kms.katalon.core.testobject.TestObject, int)
at La_07_Verify_All_ContentOnPage.run(La_07_Verify_All_ContentOnPage:62)
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:328)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:319)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:298)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:290)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:224)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:106)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:97)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1557406130463.run(TempTestCase1557406130463.groovy:22)


#24

I am getting this error when using this method


#25

What arguments are you passing to the keyword? The exception says that you are trying to pass boolean value, which is not expected. You should use one of these overloads:

verifyElementPresent(com.kms.katalon.core.testobject.TestObject, int), verifyElementPresent(com.kms.katalon.core.testobject.TestObject, int, com.kms.katalon.core.model.FailureHandling)


#26

Same as Java or any other language
assert searchResult.equalsIgnoreCase(actualStatus) == true


#27

if (WebUI.verifyElementText(findTestObject(‘Object Repository/Banner/applicationNavigator/SSASECT/Meeting_Times_and_Instructor/search_instructor_inGrid’), ‘FA#219908’,com.kms.katalon.core.model.FailureHandling).TRUE)

	 {
		 delete_record()
		 
		 println("record deleted")
	
	}
	 
	 if (WebUI.verifyElementText(findTestObject('Object Repository/Banner/applicationNavigator/SSASECT/Meeting_Times_and_Instructor/search_instructor_inGrid'), 'FA#219908',com.kms.katalon.core.model.FailureHandling).FALSE)  {
		
		
	
	WebUI.sendKeys(findTestObject('Object Repository/Banner/applicationNavigator/SSASECT/Meeting_Times_and_Instructor/insert_instructor'), Keys.chord(Keys.F6))
	WebUI.setText(findTestObject('Object Repository/Banner/applicationNavigator/SSASECT/Meeting_Times_and_Instructor/session_indicator'),'01')
	WebUI.setText(findTestObject('Object Repository/Banner/applicationNavigator/SSASECT/Meeting_Times_and_Instructor/ID'),'FA#219908')
	WebUI.delay(4)
	WebUI.setText(findTestObject('Object Repository/Banner/applicationNavigator/SSASECT/Meeting_Times_and_Instructor/responsibility_percent'),'100')
	WebUI.click(findTestObject('Object Repository/Banner/applicationNavigator/SSASECT/Page_Application Navigator/next tab'))
	WebUI.delay(2)
	WebUI.sendKeys(findTestObject('Object Repository/Banner/applicationNavigator/SSASECT/Meeting_Times_and_Instructor/save_inserted_record'),Keys.chord(Keys.F10))
	WebUI.delay(3)
	println('record added')
	}
}

getting below error–

Scenario is- I have to run condition wise cases …econd if has to run always , but if first condition met it has to run first.


#28

You must specify one of FailureHandling enum values such as CONTINUE_ON_FAILURE, STOP_ON_FAILURE or OPTIONAL.


#29

if (WebUI.verifyElementText(findTestObject(‘Object Repository/Banner/applicationNavigator/SSASECT/Meeting_Times_and_Instructor/search_instructor_inGrid’), ‘FA#219908’,FailureHandling.CONTINUE_ON_FAILURE).TRUE)

can I use like this, along with TRUE cindition?


#30

Why do you need the TRUE thing? WebUI.verifyElementText() will return true if the element text matches ‘FA#219908’.

Try this

if (WebUI.verifyElementText(findTestObject(‘Object Repository/Banner/applicationNavigator/SSASECT/Meeting_Times_and_Instructor/search_instructor_inGrid’), ‘FA#219908’,FailureHandling.CONTINUE_ON_FAILURE))

#31

I have to skip IF condition in case it gets fail, but what is happening on adding "CONTINUE_ON_FAILURE " it continues inside the If condition rather skipping the block.
I have to skip block.

Verification FAILED.
Reason:
com.kms.katalon.core.exception.StepFailedException: Actual text 'Session Indicator


#32

Can you please post full error message?


#33

my code-
@And(“navigate to Meeting Times and Instructor tab”)
def tab_navigate() {
WebUI.delay(10)
for(int i=0;i<3;i++){
WebUI.click(findTestObject(‘Object Repository/Banner/applicationNavigator/SSASECT/Page_Application Navigator/next tab’))
WebUI.delay(2)
println(i)
}

	if (WebUI.verifyElementText(findTestObject('Object Repository/Banner/applicationNavigator/SSASECT/Meeting_Times_and_Instructor/search_instructor_inGrid'),FA#219908,FailureHandling.CONTINUE_ON_FAILURE)) 
	{
	   delete_record()
	   println("record deleted")
	}
					
	WebUI.sendKeys(findTestObject('Object Repository/Banner/applicationNavigator/SSASECT/Meeting_Times_and_Instructor/insert_instructor'), Keys.chord(Keys.F6))
	WebUI.setText(findTestObject('Object Repository/Banner/applicationNavigator/SSASECT/Meeting_Times_and_Instructor/session_indicator'),'01')
	WebUI.setText(findTestObject('Object Repository/Banner/applicationNavigator/SSASECT/Meeting_Times_and_Instructor/ID'),'FA#219908')
	WebUI.delay(4)
	WebUI.setText(findTestObject('Object Repository/Banner/applicationNavigator/SSASECT/Meeting_Times_and_Instructor/responsibility_percent'),'100')
	WebUI.click(findTestObject('Object Repository/Banner/applicationNavigator/SSASECT/Page_Application Navigator/next tab'))
	WebUI.delay(2)
	WebUI.sendKeys(findTestObject('Object Repository/Banner/applicationNavigator/SSASECT/Meeting_Times_and_Instructor/save_inserted_record'),Keys.chord(Keys.F10))
	WebUI.delay(3)
	println('record added')
	
}

@And("verify success message while adding new record")
def	add_record() {
	def String target = WebUI.getText(findTestObject('Object Repository/Banner/applicationNavigator/SSASECT/Meeting_Times_and_Instructor/message_on _save_record'))
	println(target)
	def String msg_success = "Saved successfully (1 rows saved)"
	WebUI.delay(3)
	println(msg_success)
	assert target.contentEquals(msg_success)
}


@And("verify success message while removing record")
def	public delete_record() {
	WebUI.delay(3)
	def String val = WebUI.getText(findTestObject('Object Repository/Banner/applicationNavigator/SSASECT/Meeting_Times_and_Instructor/delete_instructor'))
	println(val)
	WebUI.click(findTestObject('Object Repository/Banner/applicationNavigator/SSASECT/Meeting_Times_and_Instructor/delete_button'))
	WebUI.delay(3)
	WebUI.sendKeys(findTestObject('Object Repository/Banner/applicationNavigator/SSASECT/Meeting_Times_and_Instructor/save_inserted_record'),Keys.chord(Keys.F10))
	def String target_del = WebUI.getText(findTestObject('Object Repository/Banner/applicationNavigator/SSASECT/Meeting_Times_and_Instructor/message_on _save_record'))
	println(target_del)
	WebUI.delay(2)
	def String msg_success_del = "Saved successfully (1 rows saved)"
	println(msg_success_del)
	WebUI.delay(2)
	assert target_del.contentEquals(msg_success_del)
}

}

ERROR------
0
1
2
2019-07-24 13:55:10.251 ERROR c.k.k.core.keyword.internal.KeywordMain - :x: Actual text ‘Session Indicator
ID
Name
Instructional Workload
Percent of Responsibility
Primary Indicator
Override Indicator
Percent of Session
FA#273208
Gibbs, Austin
0.000
100
100
01
FA%109321
Hew, Kwan
0.000
100
100
01
FA%114427
Hayes, Janeen
0.000
100
100
01
FA#219908
Islam, Azmiri
0.000
100
100’ and expected text ‘FA#219908’ of test object ‘Object Repository/Banner/applicationNavigator/SSASECT/Meeting_Times_and_Instructor/search_instructor_inGrid’ are NOT matched. (Root cause: com.kms.katalon.core.exception.StepFailedException: Actual text ‘Session Indicator
ID
Name
Instructional Workload
Percent of Responsibility
Primary Indicator
Override Indicator
Percent of Session
FA#273208
Gibbs, Austin
0.000
100
100
01
FA%109321
Hew, Kwan
0.000
100
100
01
FA%114427
Hayes, Janeen
0.000
100
100
01
FA#219908
Islam, Azmiri
0.000
100
100’ and expected text ‘FA#219908’ of test object ‘Object Repository/Banner/applicationNavigator/SSASECT/Meeting_Times_and_Instructor/search_instructor_inGrid’ are NOT matched.
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)
at com.kms.katalon.core.webui.keyword.builtin.VerifyElementTextKeyword$_verifyElementText_closure1.doCall(VerifyElementTextKeyword.groovy:57)
at com.kms.katalon.core.webui.keyword.builtin.VerifyElementTextKeyword$_verifyElementText_closure1.call(VerifyElementTextKeyword.groovy)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)
at com.kms.katalon.core.webui.keyword.builtin.VerifyElementTextKeyword.verifyElementText(VerifyElementTextKeyword.groovy:72)
at com.kms.katalon.core.webui.keyword.builtin.VerifyElementTextKeyword.execute(VerifyElementTextKeyword.groovy:40)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:56)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.verifyElementText(WebUiBuiltInKeywords.groovy:3647)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$verifyElementText$4.call(Unknown Source)
at highly_Used_Test_Cases.VerifyUnitDetails.tab_navigate(VerifyUnitDetails.groovy:70)
at cucumber.runtime.Utils$1.call(Utils.java:26)
at cucumber.runtime.Timeout.timeout(Timeout.java:16)
at cucumber.runtime.Utils.invoke(Utils.java:20)
at cucumber.runtime.java.JavaStepDefinition.execute(JavaStepDefinition.java:48)
at cucumber.runtime.PickleStepDefinitionMatch.runStep(PickleStepDefinitionMatch.java:50)
at cucumber.runner.TestStep.executeStep(TestStep.java:55)
at cucumber.runner.TestStep.run(TestStep.java:42)
at cucumber.runner.PickleStepTestStep.run(PickleStepTestStep.java:53)
at cucumber.runner.TestCase.run(TestCase.java:47)
at cucumber.runner.Runner.runPickle(Runner.java:44)
at cucumber.runtime.Runtime.runFeature(Runtime.java:120)
at cucumber.runtime.Runtime.run(Runtime.java:106)
at cucumber.api.cli.Main.run(Main.java:35)
at cucumber.api.cli.Main$run.call(Unknown Source)
at com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords$_runFeatureFile_closure1.doCall(CucumberBuiltinKeywords.groovy:76)
at com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords$_runFeatureFile_closure1.doCall(CucumberBuiltinKeywords.groovy)
at com.kms.katalon.core.keyword.internal.KeywordMain.runKeyword(KeywordMain.groovy:68)
at com.kms.katalon.core.keyword.internal.KeywordMain$runKeyword.call(Unknown Source)
at com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords.runFeatureFile(CucumberBuiltinKeywords.groovy:46)
at com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords$runFeatureFile$0.callStatic(Unknown Source)
at com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords.runFeatureFile(CucumberBuiltinKeywords.groovy:101)
at com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords$runFeatureFile.call(Unknown Source)
at WSVerification1563956544429.run(WSVerification1563956544429:2)
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.WSVerificationExecutor.runScript(WSVerificationExecutor.java:146)
at com.kms.katalon.core.main.WSVerificationExecutor.doExecute(WSVerificationExecutor.java:140)
at com.kms.katalon.core.main.WSVerificationExecutor.processExecutionPhase(WSVerificationExecutor.java:123)
at com.kms.katalon.core.main.WSVerificationExecutor.accessMainPhase(WSVerificationExecutor.java:115)
at com.kms.katalon.core.main.WSVerificationExecutor.execute(WSVerificationExecutor.java:103)
at com.kms.katalon.core.main.TestCaseMain.runFeatureFile(TestCaseMain.java:144)
at com.kms.katalon.core.main.TestCaseMain$runFeatureFile$0.call(Unknown Source)
at TempTempCase1563956540053.run(TempTempCase1563956540053.groovy:21)
)
record added
2019-07-24 13:55:22.124 DEBUG c.k.k.c.c.keyword.CucumberReporter - ✓ navigate to Meeting Times and Instructor tab
2019-07-24 13:55:22.125 DEBUG c.k.k.c.c.keyword.CucumberReporter - STEP verify success message while adding new record
Banner
Integrity error (SATURN.SIRASGN_KEY_INDEX2) - duplicated key
Saved successfully (1 rows saved)
2019-07-24 13:55:25.257 ERROR c.k.k.c.c.keyword.CucumberReporter - :x: verify success message while adding new record FAILED.
Reason:
Assertion failed:

assert target.contentEquals(msg_success)
| | |
| false Saved successfully (1 rows saved)
Banner
Integrity error (SATURN.SIRASGN_KEY_INDEX2) - duplicated key

at highly_Used_Test_Cases.VerifyUnitDetails.add_record(VerifyUnitDetails.groovy:114)
at ✽.verify success message while adding new record(C:/Users/shilpi/Katalon Studio/ACU Sanity Check/Include/features/Banner/Highly_Used_Test_Cases/VerifyUnitDetails.feature:14)

2019-07-24 13:55:25.260 DEBUG c.k.k.c.c.keyword.CucumberReporter - STEP verify success message while removing record
2019-07-24 13:55:25.260 WARN c.k.k.c.c.keyword.CucumberReporter - SKIP verify success message while removing record
2019-07-24 13:55:25.266 ERROR c.k.k.c.c.keyword.CucumberReporter - :x: SCENARIO Verify unit detail FAILED.
Reason:
Assertion failed:

assert target.contentEquals(msg_success)
| | |
| false Saved successfully (1 rows saved)
Banner
Integrity error (SATURN.SIRASGN_KEY_INDEX2) - duplicated key

at highly_Used_Test_Cases.VerifyUnitDetails.add_record(VerifyUnitDetails.groovy:114)
at ✽.verify success message while adding new record(C:/Users/shilpi/Katalon Studio/ACU Sanity Check/Include/features/Banner/Highly_Used_Test_Cases/VerifyUnitDetails.feature:14)

2019-07-24 13:55:25.267 INFO c.k.k.c.c.keyword.CucumberReporter - END SCENARIO Verify unit detail

e[31mFailed scenarios:e[0m
e[31mC:/Users/shilpi/Katalon Studio/ACU Sanity Check/Include/features/Banner/Highly_Used_Test_Cases/VerifyUnitDetails.feature:10 e[0m# Verify unit detail

1 Scenarios (e[31m1 failede[0m)
6 Steps (e[31m1 failede[0m, e[36m1 skippede[0m, e[32m4 passede[0m)
2m58.480s

Assertion failed:

assert target.contentEquals(msg_success)
| | |
| false Saved successfully (1 rows saved)
Banner
Integrity error (SATURN.SIRASGN_KEY_INDEX2) - duplicated key

at highly_Used_Test_Cases.VerifyUnitDetails.add_record(VerifyUnitDetails.groovy:114)
at ✽.verify success message while adding new record(C:/Users/shilpi/Katalon Studio/ACU Sanity Check/Include/features/Banner/Highly_Used_Test_Cases/VerifyUnitDetails.feature:14)

#34

Try setting FailureHandling.OPTIONAL.


#35

What happening here ----
Its working fine on false condition but it should execute method inside the if condition in case condition is true.
If you see my console, as per condition I am verifying element text ‘FA#219908’ which is also present in console but its saying its not matched

I am using using wrong keyword to validate my condition???


#36

Ok, you are using “verify match” that will return true only if the text is exactly the same.

You should use Groovy .contains() string function. Something like this:

def text = WebUI.getText(findTestObject(‘Object Repository/Banner/applicationNavigator/SSASECT/Meeting_Times_and_Instructor/search_instructor_inGrid’))
if (text.contains(‘FA#219908’)) {
        //your code here
}

#37

This topic saved me a lot of time, so thank you all!


#39

STOP_ON_FAILURE = the whole test stops and fails if this one condition is false
CONTINUE_ON_FAILURE = code inside the if condition is still executed if the condition is false
OPTIONAL = code inside the if condition is still executed if the condition is false

If I have an if condition in a test, and that condition is false, the test should not fail and it should not execute the code within the if condition. It should just continue without executing the code.

Can someone please explain how to make if statements work logically?


#40

the flags are implemented only for code bahaviour. to continue or not in case of failure. however, the test case will fail.
if yo need to continue and ignore keyword resolution,use try/catch or custom keywors


#41

Will just leave this here for new users