# API and web test combined

**URL:** <https://forum.katalon.com/t/api-and-web-test-combined/14000>\
**Category:** API Testing\
**Tags:** api-testing, katalon-studio\
**Created:** [October 30, 2018, 12:25am UTC](https://forum.katalon.com/t/api-and-web-test-combined/14000 "2018-10-30T00:25:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Manual\_Tester](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/manual_tester/32/23869_2.png) [@Manual\_Tester](https://forum.katalon.com/u/Manual_Tester)\
**Post date:** [October 30, 2018, 12:25am UTC](https://forum.katalon.com/t/api-and-web-test-combined/14000/1 "2018-10-30T00:25:40Z")

</div>

Is it possible to combine API and web test and use the response from API test as test data for Web Tests?

Thanks

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [October 30, 2018, 2:24am UTC](https://forum.katalon.com/t/api-and-web-test-combined/14000/2 "2018-10-30T02:24:00Z")

</div>

Yes, you can.

When you create a test case in Katalon Studio, it generates the following import statements:

```auto
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webservice.keyword.WindowsBuiltinKeywords as Windows

```

This means your test case can call both of WebUI.xxx keywords and WS.xxx keywords wherever you like.

---

<div class="post-metadata">

**Author:** ![Manual\_Tester](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/manual_tester/32/23869_2.png) [@Manual\_Tester](https://forum.katalon.com/u/Manual_Tester)\
**Post date:** [October 30, 2018, 4:58am UTC](https://forum.katalon.com/t/api-and-web-test-combined/14000/3 "2018-10-30T04:58:29Z")

</div>

That’s right direction to start with. Do you have any samples or any examples you can point me to?

Thanks

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [October 30, 2018, 6:27am UTC](https://forum.katalon.com/t/api-and-web-test-combined/14000/4 "2018-10-30T06:27:29Z")

</div>

I made a Katalon Studio project. The project does the following:

1. get the Yahoo! RSS feed at [Yahoo News - Latest News & Headlines](https://news.yahoo.com/rss/mostviewed) using Katalon Web Service keyword WS.sendRequest(TestObject)
2. parse the XML document and find a list of URLs of contained news pages using XPath. Basic knowledge about XML processing in Java is required.
3. iterate over the list of URLs found; open the URL in browser, take screenshots and save the image into /tmp folder

![](https://s3.amazonaws.com/katalon-forum/editor/6k/woeub0di9zmn.png "Image: https://s3.amazonaws.com/katalon-forum/editor/6k/woeub0di9zmn.png")

```auto
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import java.nio.file.Path
import java.nio.file.Paths
import javax.xml.parsers.DocumentBuilder
import javax.xml.parsers.DocumentBuilderFactory
import javax.xml.xpath.XPath
import javax.xml.xpath.XPathConstants
import javax.xml.xpath.XPathFactory
import org.w3c.dom.Document
import com.kms.katalon.core.configuration.RunConfiguration
import com.kms.katalon.core.testobject.HttpBodyContent
import com.kms.katalon.core.testobject.ResponseObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance()
    dbfactory.setNamespaceAware(true)ResponseObject response = WS.sendRequest(findTestObject('Yahoo.com RSS mostviewed'))
if (response.isXmlContentType()) {
    println "is XML"
    HttpBodyContent content = response.getBodyContent()
    println "content encoding: ${content.getContentEncoding()}"
    println "content length: ${content.getContentLength()}"
    println "content type: ${content.getContentType()}"
    InputStream is = content.getInputStream()
    // parsing XML document
    DocumentBuilder db = dbfactory.newDocumentBuilder()
    Document document = db.parse(is)
    // get access to Items using XPath
    XPath xpath = XPathFactory.newInstance().newXPath()
    WebUI.openBrowser('')
    Path outdir = Paths.get(RunConfiguration.getProjectDir()).resolve('tmp')
    for (int x = 1; x <= 3; x++) {
        String url = (String)xpath.evaluate("/rss/channel/item[${x}]/link", document, XPathConstants.STRING)
        println "url: ${url}"
        if (url != null) {
            // taking evidence screenshot
            WebUI.navigateToUrl(url)
            WebUI.delay(2)
            Path outfile = outdir.resolve(URLEncoder.encode(url,'UTF-8') + ".png")
            WebUI.takeScreenshot(outfile.toString())
        }
    }
    WebUI.closeBrowser()
}

```

I got 3 png files successfully.

You can downlowd the zip file of this sample project at [Releases · kazurayam/KatalonDiscussion10444 · GitHub](https://github.com/kazurayam/KatalonDiscussion10444/releases)

---

<div class="post-metadata">

**Author:** ![Manual\_Tester](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/manual_tester/32/23869_2.png) [@Manual\_Tester](https://forum.katalon.com/u/Manual_Tester)\
**Post date:** [October 31, 2018, 8:55am UTC](https://forum.katalon.com/t/api-and-web-test-combined/14000/5 "2018-10-31T08:55:16Z")

</div>

> kazurayam said:
> 
> I made a Katalon Studio project. The project does the following:
> 
> 1. get the Yahoo! RSS feed at [Yahoo News - Latest News & Headlines](https://news.yahoo.com/rss/mostviewed) using Katalon Web Service keyword WS.sendRequest(TestObject)
> 2. parse the XML document and find the URL of contained news pages using XPath. Basic knowledge about XML processing in Java is required.
> 3. iterate over the list of URLs found; open the URL in browser, take screenshots and save the image into /tmp folder
> 
> ![](https://s3.amazonaws.com/katalon-forum/editor/6k/woeub0di9zmn.png)
> 
> ```auto
> import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
> 
> ```

import java.nio.file.Path  
import java.nio.file.Paths  
import javax.xml.parsers.DocumentBuilder  
import javax.xml.parsers.DocumentBuilderFactory  
import javax.xml.xpath.XPath  
import javax.xml.xpath.XPathConstants  
import javax.xml.xpath.XPathFactory  
import org.w3c.dom.Document  
import com.kms.katalon.core.configuration.RunConfiguration  
import com.kms.katalon.core.testobject.HttpBodyContent  
import com.kms.katalon.core.testobject.ResponseObject  
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS  
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI  
DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance()  
dbfactory.setNamespaceAware(true)ResponseObject response = WS.sendRequest(findTestObject(‘[Yahoo.com](http://Yahoo.com) RSS mostviewed’))  
if (response.isXmlContentType()) {  
println “is XML”  
HttpBodyContent content = response.getBodyContent()  
println “content encoding: ${content.getContentEncoding()}”  
println “content length: ${content.getContentLength()}”  
println “content type: ${content.getContentType()}”  
InputStream is = content.getInputStream()  
// parsing XML document  
DocumentBuilder db = dbfactory.newDocumentBuilder()  
Document document = db.parse(is)  
// get access to Items using XPath  
XPath xpath = XPathFactory.newInstance().newXPath()  
WebUI.openBrowser(‘’)  
Path outdir = Paths.get(RunConfiguration.getProjectDir()).resolve(‘tmp’)  
for (int x = 1; x \<= 3; x++) {  
String url = (String)xpath.evaluate(“/rss/channel/item[${x}]/link”, document, XPathConstants.STRING)  
println “url: ${url}”  
if (url != null) {  
// taking evidence screenshot  
WebUI.navigateToUrl(url)  
WebUI.delay(2)  
Path outfile = outdir.resolve(URLEncoder.encode(url,‘UTF-8’) + “.png”)  
WebUI.takeScreenshot(outfile.toString())  
}  
}  
WebUI.closeBrowser()  
}

> ```auto
> 
>   
>   
> I got 3 png files successfully.  
>   
> You can downlowd the zip file of this sample project at https://github.com/kazurayam/KatalonDiscussion10444/releases
> 
>   
> 
> ```

> kazurayam said:
> 
> I made a Katalon Studio project. The project does the following:
> 
> 1. get the Yahoo! RSS feed at [Yahoo News - Latest News & Headlines](https://news.yahoo.com/rss/mostviewed) using Katalon Web Service keyword WS.sendRequest(TestObject)
> 2. parse the XML document and find the URL of contained news pages using XPath. Basic knowledge about XML processing in Java is required.
> 3. iterate over the list of URLs found; open the URL in browser, take screenshots and save the image into /tmp folder
> 
> ![](https://s3.amazonaws.com/katalon-forum/editor/6k/woeub0di9zmn.png)
> 
> ```auto
> import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
> 
> ```

import java.nio.file.Path  
import java.nio.file.Paths  
import javax.xml.parsers.DocumentBuilder  
import javax.xml.parsers.DocumentBuilderFactory  
import javax.xml.xpath.XPath  
import javax.xml.xpath.XPathConstants  
import javax.xml.xpath.XPathFactory  
import org.w3c.dom.Document  
import com.kms.katalon.core.configuration.RunConfiguration  
import com.kms.katalon.core.testobject.HttpBodyContent  
import com.kms.katalon.core.testobject.ResponseObject  
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS  
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI  
DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance()  
dbfactory.setNamespaceAware(true)ResponseObject response = WS.sendRequest(findTestObject(‘[Yahoo.com](http://Yahoo.com) RSS mostviewed’))  
if (response.isXmlContentType()) {  
println “is XML”  
HttpBodyContent content = response.getBodyContent()  
println “content encoding: ${content.getContentEncoding()}”  
println “content length: ${content.getContentLength()}”  
println “content type: ${content.getContentType()}”  
InputStream is = content.getInputStream()  
// parsing XML document  
DocumentBuilder db = dbfactory.newDocumentBuilder()  
Document document = db.parse(is)  
// get access to Items using XPath  
XPath xpath = XPathFactory.newInstance().newXPath()  
WebUI.openBrowser(‘’)  
Path outdir = Paths.get(RunConfiguration.getProjectDir()).resolve(‘tmp’)  
for (int x = 1; x \<= 3; x++) {  
String url = (String)xpath.evaluate(“/rss/channel/item[${x}]/link”, document, XPathConstants.STRING)  
println “url: ${url}”  
if (url != null) {  
// taking evidence screenshot  
WebUI.navigateToUrl(url)  
WebUI.delay(2)  
Path outfile = outdir.resolve(URLEncoder.encode(url,‘UTF-8’) + “.png”)  
WebUI.takeScreenshot(outfile.toString())  
}  
}  
WebUI.closeBrowser()  
}

> ```auto
> 
>   
>   
> I got 3 png files successfully.  
>   
> You can downlowd the zip file of this sample project at https://github.com/kazurayam/KatalonDiscussion10444/releases
> 
>   
> 
> ```

> kazurayam said:
> 
> I made a Katalon Studio project. The project does the following:
> 
> 1. get the Yahoo! RSS feed at [Yahoo News - Latest News & Headlines](https://news.yahoo.com/rss/mostviewed) using Katalon Web Service keyword WS.sendRequest(TestObject)
> 2. parse the XML document and find the URL of contained news pages using XPath. Basic knowledge about XML processing in Java is required.
> 3. iterate over the list of URLs found; open the URL in browser, take screenshots and save the image into /tmp folder
> 
> ![](https://s3.amazonaws.com/katalon-forum/editor/6k/woeub0di9zmn.png)
> 
> ```auto
> import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
> 
> ```

import java.nio.file.Path  
import java.nio.file.Paths  
import javax.xml.parsers.DocumentBuilder  
import javax.xml.parsers.DocumentBuilderFactory  
import javax.xml.xpath.XPath  
import javax.xml.xpath.XPathConstants  
import javax.xml.xpath.XPathFactory  
import org.w3c.dom.Document  
import com.kms.katalon.core.configuration.RunConfiguration  
import com.kms.katalon.core.testobject.HttpBodyContent  
import com.kms.katalon.core.testobject.ResponseObject  
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS  
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI  
DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance()  
dbfactory.setNamespaceAware(true)ResponseObject response = WS.sendRequest(findTestObject(‘[Yahoo.com](http://Yahoo.com) RSS mostviewed’))  
if (response.isXmlContentType()) {  
println “is XML”  
HttpBodyContent content = response.getBodyContent()  
println “content encoding: ${content.getContentEncoding()}”  
println “content length: ${content.getContentLength()}”  
println “content type: ${content.getContentType()}”  
InputStream is = content.getInputStream()  
// parsing XML document  
DocumentBuilder db = dbfactory.newDocumentBuilder()  
Document document = db.parse(is)  
// get access to Items using XPath  
XPath xpath = XPathFactory.newInstance().newXPath()  
WebUI.openBrowser(‘’)  
Path outdir = Paths.get(RunConfiguration.getProjectDir()).resolve(‘tmp’)  
for (int x = 1; x \<= 3; x++) {  
String url = (String)xpath.evaluate(“/rss/channel/item[${x}]/link”, document, XPathConstants.STRING)  
println “url: ${url}”  
if (url != null) {  
// taking evidence screenshot  
WebUI.navigateToUrl(url)  
WebUI.delay(2)  
Path outfile = outdir.resolve(URLEncoder.encode(url,‘UTF-8’) + “.png”)  
WebUI.takeScreenshot(outfile.toString())  
}  
}  
WebUI.closeBrowser()  
}

> ```auto
> 
>   
>   
> I got 3 png files successfully.  
>   
> You can downlowd the zip file of this sample project at https://github.com/kazurayam/KatalonDiscussion10444/releases
> 
>   
> 
> ```

Kazurayam, Thanks a lot for the example, there is lot to learn about the abilities of this tool from this example, really appreciate your help.

---

<div class="post-metadata">

**Author:** ![Manual\_Tester](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/manual_tester/32/23869_2.png) [@Manual\_Tester](https://forum.katalon.com/u/Manual_Tester)\
**Post date:** [October 31, 2018, 8:57am UTC](https://forum.katalon.com/t/api-and-web-test-combined/14000/6 "2018-10-31T08:57:07Z")

</div>

Kazurayam, Thanks a lot for the example, there is lot to learn about the abilities of this tool from this example, really appreciate your help.
