How to modify static test object to dynamic for assertion

Hello All, i hope everyone safe!
I have a concern and i will explain in details.

I have scan an object and that object will contain different values in different cases. See attached screenshot. My objective is that in next test case, another value will display however, the scan object will contain the previous value.

Can someone help me urgently?

???

Please follow this advice:

Hello, i just upload my screenshot

Please help :frowning:

I’m not sure I understand…

Are you saying that td_Tom Hardy might be td_Cillian Murphy in the next test case?

yes but in the same xpath

Difficult to understand this.

I want to see some evidences. Could you try inserting some debug-print statements into your test and try running it twice.

WebUI.delay(3)

// insert this
WebUI.comment("var_checkName=" + var_checkName)
WebUI.comment("var_displayName=" + var_displayName)

if (var_checkName == var_displayName) {
    log.logInfo("Passed")
} else {
    log.logInfo("Failed");
}

What values of var_checkName and var_displaysName do you see? Do the values stay the same or move?

I guess, the var_checkName (which is retrieved from your internal test data) moves while the var_displayName (which is retrieved from the testobject) stays the same.

Yes, your assumption was right and today i prepare a small doc so that this can help you to understand better and provide me with a solution.KatalonIssue.zip (463.6 KB)

@Ziyaad

Thank you very much explaining your question. I understand your issue better.

Still, could you try inserting following debug-print statements and see what value the variables actually contain?

// insert this
WebUI.comment("var_checkName=[" + var_checkName + "]")
WebUI.comment("var_displayName=[" + var_displayName + "]")

I guess you may see the following output:

var_checkName=[Tom Hardy]
var_displayName=[
        Tom Hardy
]

If this is the case, these 2 variables have different values: different number of leading/trailing white spaces. Therefore the test (var_checkName == var_displayName) will be evaluated false.

So I guess, but we should check the fact first.

Hello @kazurayam, i did the test and below the findings:

2020-04-06 13:23:14.657 DEBUG testcase.Basic LDAP auth for mono-user   - 13: comment("var_checkName=" + var_checkName)
2020-04-06 13:23:14.663 INFO  c.k.k.c.keyword.builtin.CommentKeyword   - var_checkName=Tom Hardy
2020-04-06 13:23:14.663 DEBUG testcase.Basic LDAP auth for mono-user   - 14: comment("var_displayName=" + var_displayName)
2020-04-06 13:23:14.664 INFO  c.k.k.c.keyword.builtin.CommentKeyword   - var_displayName=TestObject - 'Object Repository/scr_assertionConsumer/Page_Application Test/td_displayName'
2020-04-06 13:23:14.665 DEBUG testcase.Basic LDAP auth for mono-user   - 15: if (var_checkName == var_displayName)
2020-04-06 13:23:14.665 DEBUG testcase.Basic LDAP auth for mono-user   - 16: else
2020-04-06 13:23:14.666 DEBUG testcase.Basic LDAP auth for mono-user   - 1: println("Failed")
Failed

This must be a surprise for you.

Now it is your turn, find out why the var_displayName got this unexpected value.

I got this because i put this in a variable as show in screenshot.

Is there any solution?

First, you should remove the 4th line (var_displayName) you marked with red line.

In you test case script code, add a few lines like this, run it and see:

def tObj = findTestObject('src_assertionConsumer/Page_Application Test/td_displayName')
WebUI.waitForElementPresent(tObj, 10)
def var_diaplayName = WebUI.getText(tObj)
WebUI.comment("var_displayName=" + var_displayName)

if (var_displayName.contains(var_checkName)) {
   ...
}
1 Like

Thank you, it works now :slight_smile:
However i did a small changes by removing “findTestObject”:

def tObj = (findTestObject(src_assertionConsumer/Page_Application Test/td_displayName))

Stay safe & stay home.