Forum Discussion

mnaeem's avatar
mnaeem
Occasional Contributor
7 years ago
Solved

Needs help to add a Raw header in SoapUIPRO

Hi,

 

I was trying to learn how we can determine API calls during that session the trainer copy the raw header from the Get request and then added it in Restlet. I need to know how can we add a raw header in RestAPI?

 

Thanks in advance

  • Hi,

     

    > //Checks if the object exists.

    >  (Aliases.browser.pageSignInToYourMicrosoftAccount.textboxTestAccount.exist);

    This is the key point which is not always clear to those who start using TestComplete (TC).

    There are two ways how TestComplete addresses objects in test code. I call them 'explicit' and 'implicit' ones.

    Explicit way is when test code directly addresses objects like in your case. E.g.:

    Aliases.browser.pageSignInToYourMicrosoftAccount.textboxTestAccount

    Such line of code tells TC that you expect that browser, pageSignInToYourMicrosoftAccount and textboxTestAccount objects must exist. As this is expected, TC throws an error if any object along the referenced path does not exist. This is logical, because your explicit expectation was not met, so this means an error which must be reported to test log.

     

    There are cases when you expect that some object may not exist. This may be expected and you know how to handle this. In this case you must not reference objects explicitly but resort to implicit approach.

    With implicit approach, test code tries to find the required object via relevant .FindXXX() or .WaitXXX() methods provided by TC and proceed according to the search result.

    In your case, code might be like this:

    var obj = Aliases.browser.pageSignInToYourMicrosoftAccount.WaitAliasChild("textboxTestAccount", 500);

    if (obj.Exists)

      ...

    else

      ...

     

    Note, however, that the above code snippet will not work if pageSignInToYourMicrosoftAccount object is absent. This is because pageSignInToYourMicrosoftAccount object is referenced explicitly and thus TC expects that this object must exist.

    In this case your code might be like this:

    var obj = Aliases.browser.WaitAliasChild("pageSignInToYourMicrosoftAccount", 500);

    if (obj.Exists) {

      var oTextBox = obj.textboxTestAccount;

      oTextBox.Keys(...);

      ...

    }

    else

      ...

     

    I.e.: you must try to search for the first object that may be absent, but not the last one.

    Note, that the line like

    Aliases.browser.WaitAliasChild("pageSignInToYourMicrosoftAccount", 500).WaitAliasChild("textboxTestAccount", 500);

    will not work either if pageSignInToYourMicrosoftAccount object does not exist.

    This is because you will get an empty object as a result of searching for the pageSignInToYourMicrosoftAccount and then will try to call non-existing .WaitAliasChild() method for this empty object.

    So chaining methods calls do not work when you need to check the existence of more than one object along the objects chain and your test code must explicitly verify the existence of every object.

     

    Additional note should be done for try/catch statements that are also sometimes misinterpreted in the world of TestComplete.

    By design, try/catch handles runtime errors. Like, for example, division by zero or direct reference of some non-existing object's property.

    When some object does not exist within the chain of explicitly referenced objects (like in yours Aliases.browser.pageSignInToYourMicrosoftAccount.textboxTestAccount), this is rather not a runtime error, but the logical issue in test code which is handled by TestComplete. And thus it does not trigger exception and thus you will not get into the catch block of your code.

     

    Hope that above will make things more clear to you.

     

5 Replies

    • Olga_T's avatar
      Olga_T
      Icon for Alumni rankAlumni

      Hi all,

       

      Nastya, thanks for the link provided!

       

      mnaeem, did the article help you sort this out?

      If the question was answered, could you please mark Nastya's reply as a Solution? This makes the search for the answer easier for other Community members in the future.

       

      Thank you in advance!

      • mnaeem's avatar
        mnaeem
        Occasional Contributor

        HI Olga_T,

         

        The article is good but it is not the solution for me. I am looking forward to add the authentication e.g. if for any requrest we need to send User ID and Password, if you know any good resource please share

         

        Thanks and Regards,

        Muhammad Naeem