Highlighted
saikumar2019
New Member.
89 views

How to use && operator in if condition to check two different text checks are available or not in TC

Hi Team,

We have a situation to check two different text checks in tru client protocol where one text is available during the normal situation, text will be changed during the testing activity, we have to record a single script using Tru Client protocol and see whether any one of the text check is available or not in both the cases, script should fail if both the text checks are not available on the page. Could you please let me know how to check it using IF condition like if (text check1  doesn't exists && text check 2 doesn't exists) then fail the script else continue the script execution.

Please let me know how to check it in Tru Client protocol 

Thanks,

Sai

0 Likes
2 Replies
Outstanding Contributor.. JHF Remmelzwaal Outstanding Contributor..
Outstanding Contributor..

Re: How to use && operator in if condition to check two different text checks are available

When your two tests are not dependent on synchronization (or you can synchronize on an other object), i.e. you know that the data is available in the DOM, you might insert a small piece of java script before the IF and do there the condition check. Set a global variable depending on the outcome and then use this variable in the TruClient IF condition to take the actions you like.

Signature:
Reward community members who take time to respond and help.
0 Likes
Outstanding Contributor.. JHF Remmelzwaal Outstanding Contributor..
Outstanding Contributor..

Re: How to use && operator in if condition to check two different text checks are available

A second thought, made me think about using JS to select the object. So I created a TruClient script that opens this page and looks to "New Member" and "Outstanding Contributor". I made a temporary 'verify' test on both elements, changed the object ID Method to JS and copied the JS code.

I've now two evalXPath expressions that I can use in an "If object Exists" check. By using JS to identify the the object I can write the following:

var obj1 = evalXPath("//div[text()=\"\n\t\t\tNew Member.\n\t\t\"]");
var obj2 = evalXPath("//div[text()=\"\n\t\t\tOutstanding Contributor..\n\t\t\"]");
ArgsContext.TC.log("Objects found " + ( obj1 != null ) + ", "+ ( obj2 != null), "Status");
// When both objects does not exist return null, else return one of the existing objects.
obj1 == null && obj2 == null ? null : ( obj2 == null ? obj1 : obj2 );

When both conditions fail, I'll return 'null', so you can put your failure code in the 'else' section.

Signature:
Reward community members who take time to respond and help.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.