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

Parents
  • 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.

Reply
  • 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.

Children
  • 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.