Verify Element Attribute Value

Im trying to verify that the string has been inputted correctly and has saved as expected but when using the VerifyElementText tool it gives me that they are not matched however they are. Am i doing something wrong?

Error log

Test Cases/touchpoint examples/Add a new job - HR - 9.1 FAILED.
Reason:
com.kms.katalon.core.exception.StepFailedException: Verify element text of test object ‘Object Repository/Add a new job/Page_CIPHR Self Service 9.1.0/input_Job Number _Job.JobNumbe’ FAILED. (Root cause: com.kms.katalon.core.exception.StepFailedException: Actual text ‘’ and expected text ‘778267’ of test object ‘Object Repository/Add a new job/Page_CIPHR Self Service 9.1.0/input_Job Number _Job.JobNumbe’ are NOT matched.)
at com.kms.katalon.core.keyword.internal.KeywordMain.stepFailed(KeywordMain.groovy:36)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:65)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:27)
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$8.call(Unknown Source)
at Add a new job - HR - 9.1.run(Add a new job - HR - 9.1:64)
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 TempTestCase1551348940787.run(TempTestCase1551348940787.groovy:22)

Script
if (WebUI.verifyElementNotVisible(findTestObject('Object Repository/Add a new job/Page_CIPHR Self Service 9.1.0/span_HR Admin'))) {
    WebUI.click(findTestObject('Object Repository/Add a new job/Page_CIPHR Self Service 9.1.0/span_Log Out_glyphicons glyphi'))

    WebUI.click(findTestObject('Object Repository/Add a new job/Page_CIPHR Self Service 9.1.0/span_HR Admin'))
} else {
    WebUI.click(findTestObject('V9.1 Testing/Page_CIPHR Self Service 9.1.0/span_HR Admin'))
}

WebUI.click(findTestObject('Object Repository/Add a new job/Page_CIPHR Self Service 9.1.0/div_Jobs'))

WebUI.click(findTestObject('Object Repository/Add a new job/Page_CIPHR Self Service 9.1.0/a_Insert New Record'))

WebUI.setText(findTestObject('Object Repository/Add a new job/Page_CIPHR Self Service 9.1.0/input_Job Number _Job.JobNumbe'), 
    '778267')

WebUI.setText(findTestObject('Object Repository/Add a new job/Page_CIPHR Self Service 9.1.0/input_Job Title _Job.JobTitle'), 
    'AA Boss')

WebUI.click(findTestObject('Object Repository/Add a new job/Page_CIPHR Self Service 9.1.0/span_Department_k-input'))

WebUI.waitForElementVisible(findTestObject('Add a new job/Page_CIPHR Self Service 9.1.0/li_Chief Executive Office'), 0)

WebUI.click(findTestObject('Object Repository/Add a new job/Page_CIPHR Self Service 9.1.0/li_Chief Executive Office'))

WebUI.setText(findTestObject('Object Repository/Add a new job/Page_CIPHR Self Service 9.1.0/input_Date Created_Job.JobCrea'), 
    '12/Feb/2019')

WebUI.click(findTestObject('Object Repository/Add a new job/Page_CIPHR Self Service 9.1.0/button_Update'))

WebUI.delay(5)

WebUI.setText(findTestObject('Object Repository/Add a new job/Page_CIPHR Self Service 9.1.0/textarea_Specification_Job.Job'), 
    'test')

WebUI.click(findTestObject('Object Repository/Add a new job/Page_CIPHR Self Service 9.1.0/button_Update'))

WebUI.delay(4)

WebUI.waitForElementVisible(findTestObject('Add a new job/Verify job created correctly/td_AA Boss'), 0)

WebUI.click(findTestObject('Add a new job/Verify job created correctly/td_AA Boss'))

WebUI.verifyElementPresent(findTestObject('Add a new job/Verify job created correctly/span_Chief Executive Office'), 0)

WebUI.verifyElementText(findTestObject('Add a new job/Page_CIPHR Self Service 9.1.0/input_Job Number _Job.JobNumbe'), '778267', 
    FailureHandling.STOP_ON_FAILURE)

WebUI.verifyElementText(findTestObject('Add a new job/Page_CIPHR Self Service 9.1.0/input_Date Created_Job.JobCrea'), '12/Feb/2019')
1 Like

You might want to use

WebUI.verifyElementAttributeValue(‘testobject’, ‘value’, ‘expected value’, ‘time for timeout’)

3 Likes

After playing about with the attributes this works for me - Thanks :slight_smile:

1 Like

Actaully i have just tried to cross check to verify if the text isnt as expected it should produce an error however it passes even though the value isnt correct. Please see -

script
WebUI.callTestCase(findTestCase('touchpoint examples/Login to CIPHR as HR - 9.1'), [:], FailureHandling.STOP_ON_FAILURE)

WebUI.maximizeWindow()

if (WebUI.verifyElementNotVisible(findTestObject('Object Repository/Create a course/trying something else/Page_CIPHR Self Service 9.1.0/span_HR Admin'))) {
    WebUI.click(findTestObject('Object Repository/Create a course/trying something else/Page_CIPHR Self Service 9.1.0/span_Log Out_glyphicons glyphi'))

    WebUI.click(findTestObject('Object Repository/Create a course/trying something else/Page_CIPHR Self Service 9.1.0/span_HR Admin'))
} else {
    WebUI.click(findTestObject('V9.1 Testing/Page_CIPHR Self Service 9.1.0/span_HR Admin'))
}

WebUI.mouseOver(findTestObject('Object Repository/Create a course/trying something else/Page_CIPHR Self Service 9.1.0/div_Training Admin'))

WebUI.click(findTestObject('Object Repository/Create a course/trying something else/Page_CIPHR Self Service 9.1.0/div_Course Bank'))

WebUI.click(findTestObject('Object Repository/Create a course/trying something else/Page_CIPHR Self Service 9.1.0/a_Insert New Record'))

WebUI.setText(findTestObject('Object Repository/Create a course/trying something else/Page_CIPHR Self Service 9.1.0/input_Code _Code'), 
    'aa booming')

WebUI.setText(findTestObject('Object Repository/Create a course/trying something else/Page_CIPHR Self Service 9.1.0/input_Title _Title'), 
    'aa testing 123')

WebUI.click(findTestObject('Object Repository/Create a course/trying something else/Page_CIPHR Self Service 9.1.0/span_Days_k-link k-link-increa'))

WebUI.click(findTestObject('Object Repository/Create a course/trying something else/Page_CIPHR Self Service 9.1.0/span_Minimum Places_k-link k-l'))

WebUI.click(findTestObject('Object Repository/Create a course/trying something else/Page_CIPHR Self Service 9.1.0/span_Optimum Places_k-link k-l'))

WebUI.click(findTestObject('Object Repository/Create a course/trying something else/Page_CIPHR Self Service 9.1.0/span_Maximum Places_k-link k-l'))

WebUI.click(findTestObject('Object Repository/Create a course/trying something else/Page_CIPHR Self Service 9.1.0/span_Training CPD_k-link k-lin'))

WebUI.click(findTestObject('Object Repository/Create a course/trying something else/Page_CIPHR Self Service 9.1.0/span_Hours_k-link k-link-incre'))

WebUI.setText(findTestObject('Object Repository/Create a course/trying something else/Page_CIPHR Self Service 9.1.0/input_Administrator_Administra'), 
    'test')

WebUI.setText(findTestObject('Object Repository/Create a course/trying something else/Page_CIPHR Self Service 9.1.0/input_Administrator Job Title_'), 
    'boss')

WebUI.click(findTestObject('Object Repository/Create a course/trying something else/Page_CIPHR Self Service 9.1.0/button_Update'))

WebUI.waitForElementVisible(findTestObject('Create a course/verify course created/td_aa testing 123'), 0)

WebUI.click(findTestObject('Create a course/verify course created/td_aa testing 123'))

WebUI.verifyElementAttributeValue(findTestObject('Create a course/verify course created/input_Days_k-formatted-value k'), 
    'aria-valuenow', '6', 0)

WebUI.verifyElementAttributeValue(findTestObject('Create a course/verify course created/input_Code _Code'), 'value', 'aa booming', 
    0)

WebUI.verifyElementAttributeValue(findTestObject('Create a course/verify course created/input_Administrator_Administra'), 
    'value', 'test', 0)

WebUI.verifyElementAttributeValue(findTestObject('Create a course/verify course created/input_Administrator Job Title_'), 
    'value', 'boss', 0)

Please note - that when i run the script it flys through all the other very elements but when it gets to these that are wrong, it does think about it for a second and then carries on

1 Like

Tried adding failurehandling?

In your case it would be something like this.

WebUI.verifyElementAttributeValue(findTestObject('Create a course/verify course created/input_Administrator_Administra'), 'value', 'test', 0, FailureHandling.STOP_ON_FAILURE)

its strange i got it to work once, but now trying it again it just passes :face_with_raised_eyebrow:

1 Like

Perhaps a bug in katalon itself

yea maybe @devalex88, is there anything you can advise?

So ive done some playing about with it, if i run my script, then after its verified them that are correct, then change the strings to something not correct and “run from here” just for the last 4 steps it picks up that they are not equal and gives me this error which i would expect -

Test Cases/touchpoint examples/Create course - HR - 9.1 FAILED.
Reason:
com.kms.katalon.core.exception.StepFailedException: Unable to verify if object 'Object Repository/Create a course/verify course created/input_Administrator_Administra' has attribute 'value' with value 'test' (Root cause: com.kms.katalon.core.exception.StepFailedException: Object 'Object Repository/Create a course/verify course created/input_Administrator_Administra' has attribute 'value' with actual value 'fsfgdsg' instead of expected value 'test')
	at com.kms.katalon.core.keyword.internal.KeywordMain.stepFailed(KeywordMain.groovy:36)
	at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:65)
	at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:27)
	at com.kms.katalon.core.webui.keyword.builtin.VerifyElementAttributeValueKeyword.verifyElementAttributeValue(VerifyElementAttributeValueKeyword.groovy:109)
	at com.kms.katalon.core.webui.keyword.builtin.VerifyElementAttributeValueKeyword.execute(VerifyElementAttributeValueKeyword.groovy:70)
	at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:56)
	at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.verifyElementAttributeValue(WebUiBuiltInKeywords.groovy:3234)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$verifyElementAttributeValue.call(Unknown Source)
at Create course - HR - 9.1.run(Create course - HR - 9.1:70)
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.RawTestScriptExecutor.runScript(RawTestScriptExecutor.java:34)
at com.kms.katalon.core.main.RawTestScriptExecutor.doExecute(RawTestScriptExecutor.java:29)
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.runTestCaseRawScript(TestCaseMain.java:143)
at com.kms.katalon.core.main.TestCaseMain$runTestCaseRawScript$0.call(Unknown Source)
at TempTestCase1551355290706.run(TempTestCase1551355290706.groovy:98) 

It seems to be working fine but did have some inconsistent runs

1 Like

Hey @hpulsford

This is what is commonly referred to as a “flaky test”. You should endeavor to find the cause if the flakiness because it will bite you later.

In this kind of situation, it’s good to remember the saying (often attributed to Mark Twain, and here modified a little for modern parlance) …

“It isn’t what you don’t know that is the problem, it’s the thing you think you know that is actually wrong.” It Ain’t What You Don’t Know That Gets You Into Trouble. It’s What You Know for Sure That Just Ain’t So – Quote Investigator®

In other words, be sure you’re not building “truth” from a starting point of falsehood. It’s just too damn easy to do and we ALL do it. With a flaky test, start over, question everything you think you know.

1 Like

Hey @Russ_Thomas

Haha you are so right with that quote, i think im kididng myself that its resolved, ive taken the solution mark away. Im going to do some more digging trying different scenaios to see if i can replicate again and then have a deeper look as to what might be causing it.

2 Likes

:slight_smile:

You almost nailed another well-known quote, this time from Richard Feynman:

“The first principle is that you must not fool yourself - and you are the easiest person to fool.”

1 Like

Ok so its definately not fixed - I have changed a few elements to try a different scenario and it is passing. I have changed the attribute value to something different to what has been inputted in previous steps, so from my understanding because it doesnt equal ‘hfhar’ instead the field is populated with ‘test’ it should through me an error?

Ultimately im attempting to verify the input into a element is correct - if anyone knows a way to do this any help will be appreciated :smiley:

WebUI.verifyElementAttributeValue(findTestObject('Create a course/verify course created/input_Days_k-formatted-value k'), 
    'aria-valuenow', '6', 0, FailureHandling.STOP_ON_FAILURE)

WebUI.verifyElementAttributeValue(findTestObject('Create a course/verify course created/input_Code _Code'), 'value', 'aa booming', 
    0, FailureHandling.STOP_ON_FAILURE)

WebUI.verifyElementAttributeValue(findTestObject('Create a course/verify course created/input_Administrator_Administra'), 
    'value', 'hfhar', 0, FailureHandling.STOP_ON_FAILURE)

WebUI.verifyElementAttributeValue(findTestObject('Create a course/verify course created/input_Administrator Job Title_'), 
    'value', 'boss', 0, FailureHandling.STOP_ON_FAILURE)
1 Like

@Russ_Thomas

King of quotes :crown:

1 Like

Perhaps a silly question, but with the update button you save your changes before you verify the new text right?

Yes i update the record, get brought back to the summary page > go back into the record > then want to verify that the strings are correct

1 Like

This is the failing line, correct?

Let’s do this so we can see a bit better and try waiting a little:

String vcc = "Create a course/verify course created/"
def to

// assuming your default failure handling is set to STOP_ON_FAILURE:

to = findTestObject(vcc + 'input_Days_k-formatted-value k')
WebUI.verifyElementAttributeValue(to, 'aria-valuenow', '6', 20)

to = findTestObject(vcc + 'input_Code _Code')
WebUI.verifyElementAttributeValue(to, 'value', 'aa booming', 20)

to = findTestObject(vcc + 'input_Administrator_Administra')
WebUI.verifyElementAttributeValue(to, 'value', 'hfhar', 20)

to = findTestObject(vcc + 'input_Administrator Job Title_')
WebUI.verifyElementAttributeValue(to, 'value', 'boss', 20)

See how that performs.

1 Like

Thanks for the help mate, so it stopped on this step for the 20 secs then carried on, yes my default is set to STOP_ON-FAILURE so surely it should have thrown an error?

1 Like

And the value looked to be correct when you viewed the page? If yes, then there’s something screwy going on.

Let’s be clear: what is the error? (Your previous error message indicates it expects “test” but has “fsfgdsg”)

Please don’t make me chase unicorns. (I’m old, they run too fast)

hahah - So the value thats in the element (administrator) is test (so its wrong) so im expecting an error telling me that it expects “hfhar” but has “test”. All im doing is verifing after to check that the correct string was inputted as on some pages we have had this bug in the past.

Hope that make sense, sorry if i confused you earlier

1 Like

There’s nothing wrong with what you’e trying to do (assuming I’m understanding you correctly). However, start from a known state. This goes back to the earlier conversation. I don’t think you have a known state.

Steps:

  1. Make the test work for reasons you can prove.
  2. Now check your reasoning: Break it. Break it in such a way that it challenges your reasoning.

Did it break exactly how you expected? No? Then you failed at #1 - NOT #2

If you can break it in ways you can predict, then you have a known state. From there, you repeat the steps above in multiple different ways (each little test then “shores up” your reasoning and makes you feel good about the test as whole).

Or you can do what the pretenders do. Wing it and hope for the best. Your call.

I should add: If Katalon is broken in the way you’re suggesting, where’s the evidence? Where are the many hundreds of reports we would surely see if that were the case?

So I’m saying, take a long hard look at steps 1 and 2. The time is worth it.

(Aside: I’ve changed the title of this thread to better reflect what’s going on)