How to output the results of the POST request (a form) into the browser for onwards use

I want to use the response of a POST request (below form) as part of a test case but, I am struggling with two parts.

  • How to output the response of the POST request into the browser for onward use. This would be ideal as I can then complete the rest of the form with the remaining part of the script.
  • How to pass the new cookie value gained from first part of script (updates daily) into the POST request. (I think I have saved the Cookie as a global variable but, unsure how to input this to POST request). Currently I am being redirected to the login page, if I don’t manually update the cookie after running the first half of the script.

The POST Response (form)

Underlying HTML of above form

<input name="double_click" type="hidden">

<input name="course" type="hidden" value="1">

<input name="d_date" type="hidden" value="2019-12-19">

<input name="Time" type="hidden" value="13:58:00">

<input name="bookingCode" type="hidden" value="46661889">

<br>

<table class="form_table" cellspacing="2" cellpadding="3" border="0">

<tbody><tr>

<td class="form_heading" colspan="3" align="center">Select Players</td>

</tr>

<tr class="form_body">

<td>Player 1 :</td>

<td><select name="Player1_uid" size="1">

<option></option>

<option value="675">Reserve</option>

</select>

</td>

<td></td>

</tr>

<input type="hidden" name="Player1_Assist " value=""><input type="hidden" name="Player1_Assist" value=""> <tr class="form_body">

<td>Player 2 :</td>

<td><script>NumDashesInListBox = 2;</script><select name="Player2_uid" size="1">

<option></option>

<option value="Guest">Guest</option>

<option value="Reserved">Reserve</option>

<option value="">------------------------------</option>

</select>

</td>

<td></td>

</tr>

<input type="hidden" name="Player2_Assist" value=""><input type="hidden" name="Player2_Assist" value=""> <tr class="form_body">

<td>Player 3 :</td>

<td><script>NumDashesInListBox = 2;</script><select name="Player3_uid" size="1">

<option></option>

<option value="Guest">Guest</option>

<option value="Reserved">Reserve</option>

<option value="">------------------------------</option>

</select>

</td>

<td></td>

</tr>

<input type="hidden" name="Player3_Assist" value=""><input type="hidden" name="Player3_Assist" value=""> <tr class="form_body">

<td>Player 4 :</td>

<td><script>NumDashesInListBox = 2;</script><select name="Player4_uid" size="1">

<option></option>

<option value="Guest">Guest</option>

<option value="Reserved">Reserve</option>

<option value="">------------------------------</option>

</select>

</td>

<td></td>

</tr>

<input type="hidden" name="Player4_Assist" value=""><input type="hidden" name="Player4_Assist" value=""></tbody></table>

<br>

<table align="left"><tbody><tr><td>

<input name="SubmitButton" type="submit" value="Confirm Booking" align="middle">

</td></tr></tbody></table>

My Current Script

import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint

import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase

import static com.kms.katalon.core.testdata.TestDataFactory.findTestData

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject

import static com.kms.katalon.core.testobject.ObjectRepository.findWindowsObject

import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint

import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW

import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile

import com.kms.katalon.core.model.FailureHandling as FailureHandling

import com.kms.katalon.core.testcase.TestCase as TestCase

import com.kms.katalon.core.testdata.TestData as TestData

import com.kms.katalon.core.testobject.TestObject as TestObject

import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

import com.kms.katalon.core.windows.keyword.WindowsBuiltinKeywords as Windows

import internal.GlobalVariable as GlobalVariable

import org.openqa.selenium.Keys as Keys

import org.openqa.selenium.Cookie

import org.openqa.selenium.WebDriver

import com.kms.katalon.core.webui.driver.DriverFactory

WebUI.openBrowser(’’)

WebUI.navigateToUrl(‘https://www.testcase.com/member/login’)

WebUI.setText(findTestObject(‘Object Repository/Final Capture/Page_Online Time Booking System Co_d560f0/input_Enter your club card number as your u_9e155a’),

‘testuser@testcase.com’)

WebUI.setEncryptedText(findTestObject(‘Object Repository/ Final Capture/Page_Online Time Booking System Co_d560f0/input_Note Passwords are case sensitive__password’),

‘testpassword’)

WebUI.click(findTestObject(‘Object Repository/ Final Capture/Page_Online Time Booking System Co_d560f0/input_Note Passwords are case sensitive_SUBMIT’))

Cookie ck = new Cookie("name", "value");

WebDriver driver = DriverFactory.getWebDriver()

driver.manage().addCookie(ck)

WS.sendRequestAndVerify(findTestObject(‘POST’))

POST Request

https://www.testcase.com/members_booking.php?operation=member_booking_form

Authorisation – None (cookie auth)

HTTP Header –

Content-Type application/x-www-form-urlencoded

Accept text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8

Cookie (manually adding at present from first half of script running)

HTTP Body – x-www-form-urlencoded

Double_click Yes

Course_id 1

D_date (date select)

Time (time select)

SubmitButton Book+Now

Hello,

  1. to get cookie from active session you need to get it in 1st place
    https://www.seleniumeasy.com/selenium-tutorials/how-to-handle-cookies-in-selenium-webdriver
  2. to inject it to post take a look in documentation of Katalon :
    https://docs.katalon.com/katalon-studio/docs/introduction-to-web-services-test-object.html
    hope those documents will help you continue.

I am really new to the whole process so am unfortunately still struggling having reviewed both of the websites suggested.

I dont know how to incorporate the cookies syntax into the script in Katalon, or where they should go.

I have tried to manually run the POST request in the script but, still not really sure how to transfer that into a web browser for onward manipulation.

code should be something like this:
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject

import org.openqa.selenium.Cookie as Cookie
import org.openqa.selenium.WebDriver as WebDriver

import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.driver.DriverFactory as DriverFactory
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

WebUI.openBrowser('')

WebUI.navigateToUrl('https://www.testcase.com/member/login')

WebUI.setText(findTestObject('Object Repository/Final Capture/Page_Online Time Booking System Co_d560f0/input_Enter your club card number as your u_9e155a'), 
    'testuser@testcase.com')

WebUI.setEncryptedText(findTestObject('Object Repository/ Final Capture/Page_Online Time Booking System Co_d560f0/input_Note Passwords are case sensitive__password'), 
    'testpassword')

WebUI.click(findTestObject('Object Repository/ Final Capture/Page_Online Time Booking System Co_d560f0/input_Note Passwords are case sensitive_SUBMIT'))

Cookie ck

WebDriver driver = DriverFactory.getWebDriver()

ck = driver.manage().getCookieNamed("Authorisation")

RequestObject ro

ro = findTestObject('POST')

ro.addProperty("Cookie", ConditionType.EQUALS, ck)

WS.sendRequestAndVerify(ro)

name of cookie must be set according your code