Ask a Question

Calling a REST API from a keyword test

SOLVED
RobertDAltman
Occasional Contributor

Calling a REST API from a keyword test

Ok... I've looked at the docs and searched the web, and I can't believe I haven't found an obvious answer to this question: Is there an easy way for me to call a REST API during my keyword test and easily extract an answer from the result? Here are a couple of scenarios I need to implement:

 

  • I want to call the API at https://validator.w3.org/nu to validate the HTML markup on each of my web pages
  • As part of my website's "Forgot my password" workflow, the user has to enter a validation code that I send to the user's phone. I would like to expose an API on my website that returns the validation code for my "test user" account, so that I can fetch the validation code and enter it on the page in my workflow where the user would read it from the phone and manually enter it.

 

1 ACCEPTED SOLUTION

Accepted Solutions
HKosova
Moderator

Re: Calling a REST API from a keyword test

In TestComplete 12.40+, you can use the Send Request operation to call REST APIs.


Helen Kosova
SmartBear Documentation Team Lead
________________________
Join Wintertainment 2021 to share your stories, have fun, earn community badges, and more!

View solution in original post

5 REPLIES 5
tristaanogre
Community Hero

Re: Calling a REST API from a keyword test

You can include the "WebServices" object in your project and utilize that for consuming API's.  


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
HKosova
Moderator

Re: Calling a REST API from a keyword test

In TestComplete 12.40+, you can use the Send Request operation to call REST APIs.


Helen Kosova
SmartBear Documentation Team Lead
________________________
Join Wintertainment 2021 to share your stories, have fun, earn community badges, and more!

View solution in original post

HKosova
Moderator

Re: Calling a REST API from a keyword test


@tristaanogre wrote:

You can include the "WebServices" object in your project and utilize that for consuming API's.  


The WebServices project item is for SOAP services only.


Helen Kosova
SmartBear Documentation Team Lead
________________________
Join Wintertainment 2021 to share your stories, have fun, earn community badges, and more!
RobertDAltman
Occasional Contributor

Re: Calling a REST API from a keyword test

Not sure if it's better to "reply" or to post a new question.  Guess I'll find out...

 

Ok, so now that I've successfully called my REST API from my keyword test, how do I parse the result (presumably JSON, although I can just as easily return XML)?  Do I need to roll my own script code or is there something in the world of keyword tests that will help me?  And if I need to write script code, is there anything in that world that makes it easy to parse parameter values out of the JSON returned by the previous operation?

RobertDAltman
Occasional Contributor

Re: Calling a REST API from a keyword test

Never mind the "follow up" question about parsing the result... I asked about that as a separate question.

cancel
Showing results for 
Search instead for 
Did you mean: