Authorisation Bearer Code - expiration issue - Katalon API Testing

Hi All,

I am using Katalon Studio for API testing, I was able to create test cases and Objects . Each time the Authorisation Bearer Code seems to be dynamic

So my approach was to hit a URL and get the access code something like below :

Below is my requirement

  1. Login Application using WEB UI testing
  2. Hit the URL which gives bearer in the body. Get the Authorisation Bearer Code
  3. Save the body to a variable say “Content”
  4. Print content
  5. Pass this content variable as the value in the HTTP header of the API Object of my API testing test cases

I was able to get the bearer by hitting the URL and get text and print

Now how to pass this “content” to my api testing

Please let me know if my approach is right and workable (or)
Suggest me a better to achieve the same.

well why you have to login like GUI ? you can do this with your authentication api and get the access token and pass to rest of requests.

You just need to create auth api request with correct Body parameters

Thanks for replying, any sample project that i can follow to create auth api ? I am using Katalon API testing for the first time. I don’t have much idea.

Go on what you think right.

When you get any errors, show us your code and log. Your code will tell us what you want to do, and then bright guys in this forum would suggest to you one step for betterment.

If you stop and start asking what to do next, it is difficult for us to respond as we do not see what you want to do.

Thanks everyone. @kazurayam You are right, we should not stop thinking.

I went with my approach
Web UI test cases 1

  1. Logged in to my application
  2. Got the Access token by redirecting to another URL
  3. got the text = Bearer
  4. Passed it to Global variable.token

API Test cases 2

  1. Call ‘Web UI test cases 1’
  2. Read API - Https header - set Authorisation - Bearer ${token}

Ran the test case 2 - Works like charm - No access token error now.

Now the problem i am facing is how to make the test suite work, because test suite and collection will not have the web ui - browser related configuration.

Note sure Test suite can be workable, any leads will be appreciated

A Test Suite is just a collection of Test Cases. One Test Case may invoke WebUI API, another Test case may invoke WS API. No problem. You can do it. I do not see what you find problematic.

The current Katalon Studio version didn’t allow me to add Web UI test case in test collection of API testing - Web service project. They are handling Web UI and API test collections separately

When a project is created using Webservice project, test collection shows only webservice in configuration ( Set an Environment ) - Test collections

Then i copied test collection file from another Web UI testing project, pasted it under test suite of API project, changed the path of file entity in notepad and it is now working fine.

OK, I can understand you.

Yes, currently Katalon Studio’s GUI is designed with a naive assumption that nobody would want to call WebUI API and WS API mixed together in a test case script in a project.

I think this assumption is valid in most cases, but some times we get confused as there are many web sites providing various data in RESTful API format prepended with Authentication processing via Web page interaction. RESTful API services for business rarely stand alone.

Current KS differenciates 3 types of project

  • Web
  • API/Web Service
  • Mobile

as the following screenshot shows:

I think, we need only 2.

  1. Web/API/Web Service
  2. Mobile

I suppose that a phrase “Katalon | Simplify Web, API, Mobile Automated Tests” for marketing purpose impressed the Katalon developers; they were convinced to design the API/Web Services features as first class citizen, independent of the “WebUI” features. I regret that they did not think of the case where a user may need both features mixed.

1 Like

If I want to create a Katalon Studio project which consists of mixture of WebUI API and WS API, I will do as follows:

  1. When I create a new project, I will choose the attribute of the project to be WebUI project , rather than API/Web Service project.
  2. for the Test Suite Collection, I will choose some browser (Chrome or Firefix) as its “runtime Environment”. I would ignore Web Service.
  3. In the Test Suite Collection, I will have one or more Test Cases which calls WebServices API. I suppose it will work fine even if I specify Chrome as the “runtime environment” for the Test Suite Collection. I guess WS API does not need to be told of which “runtime environment” to choose at all.

Long time ago, ‘webservice’ runtime was not available, it was implemented later.
But RestAPI calls worked just fine with chrome, or chrome headless or whatever else.

So, will work just fine @kazurayam suggested.
The webservice template (and runtime) was introduced for pure API/DB projects.
For mixed projects, WebUI is more suitable. Yeah, you don’t have the icons available to quickly create RestAPI objects, but can still be created by right-click on OR > Create New > etc

1 Like

Thanks everyone! :slight_smile: