How to get information from Authorization tab?

Hi,
Is there a predefined function that would get us UserName from the Authorization tab?

Thanks
For example, in this image, I want to get “ABCTEST”.

why would you need that?
is supposed to work opposite, the developper of the test put data there

We are testing whether the Username on this tab matches with the UserName we get in the response? I know how to get the UserName from the response but don’t know how to get UserName from Authorization tab? I don’t want to hard code it.

Thanks

you are confused. by puting data there, you are hard hardcoding it.
read more about katalon and particularily to write testcases by code
forget about test objects, are there only to confuse you
katalon is not postman

I want to access UserName from testcase.
Thanks

The below allows you to get the person that is running the test case–basically the person that is logged in; nothing to do with Authorization tab. I don’t know if this will satisfy your requirement.

import com.sun.jna.platform.win32.Secur32
import com.sun.jna.platform.win32.Secur32Util

// get name as "initial+lastname" like "JSmith"
gPropertyUserName = System.getProperty("user.name");

// get full username like "last_name, given_name" as Smith, John
gUserName = Secur32Util.getUserNameEx(Secur32.EXTENDED_NAME_FORMAT.NameDisplay);

The Authorization tab is just a helper for creating Web Service objects.
What will actually do is to inject the encoded data into the HTTP headers when you hit the 'Update" button.
It will look like this:

So (for basic authentication), you will have to:

  • retrieve the authorization header as a string from the request object
  • take out the Basic part from it (and the space following it)
  • decode the remaining string (it is encoded as base64)
    You will get something like user:password so by splitting the resulting string on : you have the data needed.
  • compare the data with what you get in the response

Side note, a better approach is if you study a bit how Katalon works and, instead putting such verification on the Web Service Test Object (Postman like) you will use a testcase, either with a parametrized TO or with a web request created by code (in memory web request)

Thank you for assisting me. What command do I use to retrieve the authorization header information?

Thanks

Perhaps

https://api-docs.katalon.com/com/kms/katalon/core/testobject/RequestObject.html#getRequestAuthorization()

Please do not ask us for sample code.

Alternate, you can use:
https://api-docs.katalon.com/com/kms/katalon/core/testobject/RequestObject.html#getHttpHeaderProperties()

to retrieve any header

Altough usually I won’t do it, I will post my solutions this time, because seems to be tricky.
I have this in my Verification snippet (first two lines are already generated by Katalon):

//this is autogenerated
RequestObject request = WSResponseManager.getInstance().getCurrentRequest()

ResponseObject response = WSResponseManager.getInstance().getCurrentResponse()

//this code is added by me
auth_by_auth = request.getRequestAuthorization()

auth_by_props = request.getHttpHeaderProperties()[0].getProperties()['value']

println auth_by_auth

println auth_by_props

Output:

2023-01-25 11:36:37.567 DEBUG testcase.                                - 5: println(auth_by_auth)
null
2023-01-25 11:36:37.575 DEBUG testcase.                                - 6: println(auth_by_props)
Basic bXl1c2VyOm15cGFzcw==
2023-01-25 11:36:37.582 INFO  c.k.k.core.main.WSVerificationExecutor   - END Verification

So, using getRequestAuthorization() in the context of Verification snippet, for some reason, does not work (but should be fine for a request built from a testcase I suppose, otherwise this method is useless. I will check this perhaps other time)
It simply returns null.

The solution in this case is to use getHttpHeaderProperties()

@mqamar Note that, in my example, I have a single header, therefore I retrieve it at index [0].
If your Request Object have more headers and Authorization is not the first one, you have to change it accordingly.

1 Like

this is encoded by base64.

You would want to decode “bXl1c...” using Base64.Decoder (Java Platform SE 8 )

1 Like

Well, yeah, I mentioned that in my previous posts, but I will let the user the joy to do the rest (split / decode / split again)

Thanks guys, this is exactly what I needed.