Passing parameteres

how to pass parameters between the test cases.
To elaborate,
Step1: create a booking test case
Step2:This requires a value or booking id which is generated in step 1 or coming from step1
How can i get the value generated in the first testcase into second testcase

can you please tell me how can i do the groovy scripting for this?
Please help me out its very essential for me

1 Like

How the global variables can be set dynamically

To ellaborate:
Test case 1: create a booking
booking id is generated

Testcase 2 : need that booking id to submit it to a particular agency.

What to do so that i can get the booking id automatically which is generated in the testcase 1

please help me out in ths?

Hi Jayshree,

Another way to do this is:

In your test case 1:

  1. create a variable named booking_id as Integer
  2. let say the value of booking_id = 1234

In your test case 2:

  1. do the code like this:
int value = WebUI.callTestCase(findTestCase("your_TestCase_2"), null)

println value

Hope that helps. . . :slight_smile:

Thanks Arnel got that but the booking id is not static it will change as we create another booking
so is there any way to set the global variable as dynamic

testcase 1 code:
__Create booking

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 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 internal.GlobalVariable as GlobalVariable

WebUI.openBrowser(’’)

WebUI.navigateToUrl(’’)

WebUI.setText(findTestObject(‘requestor bookingg/Page_Primaxis Sign in/input_Sign in_username’), ‘R1/IMS Trial’)

WebUI.setEncryptedText(findTestObject(‘requestor bookingg/Page_Primaxis Sign in/input_Sign in_password’), ‘oagVfJEzz+A=’)

WebUI.click(findTestObject(‘requestor bookingg/Page_Primaxis Sign in/button_Sign in’))

WebUI.click(findTestObject(‘requestor bookingg/Page_Interpreter Management System/span_BOOK’))

WebUI.delay(3)

WebUI.setText(findTestObject(‘requestor bookingg/Page_Interpreter Management System/input_Search Patient by UR Num’), ‘D123123’)

WebUI.delay(3)

WebUI.click(findTestObject(‘requestor bookingg/Page_Interpreter Management System/strong_1234’))
WebUI.delay(2)
WebUI.click(findTestObject(‘create new booking as a coordinator/Page_Interpreter Management System/input_Inpatient’))
WebUI.delay(2)
WebUI.setText(findTestObject(‘requestor bookingg/Page_Interpreter Management System/input_Dec_view’), ‘16 July 2019’)

WebUI.setText(findTestObject(‘requestor bookingg/Page_Interpreter Management System/input_Time_view’), ‘10:30’)

WebUI.delay(3)

WebUI.setText(findTestObject(‘requestor bookingg/Page_Interpreter Management System/input_WardClinicUnit’), ‘wa’)

WebUI.delay(2)

WebUI.click(findTestObject(‘requestor bookingg/Page_Interpreter Management System/strong_wa’))

WebUI.delay(2)

WebUI.selectOptionByValue(findTestObject(‘requestor bookingg/Page_Interpreter Management System/select_center’), ‘841581’,true)

WebUI.delay(3)
WebUI.setText(findTestObject(‘create new booking as manager/Page_Interpreter Management System/input_Language_view’), ‘hindi’)
WebUI.delay(2)
WebUI.click(findTestObject(‘Object Repository/create new booking as manager/Page_Interpreter Management System/strong_Hi’))
WebUI.setText(findTestObject(‘requestor bookingg/Page_Interpreter Management System/input_notes to interpreter’), ‘create a booking’)
WebUI.delay(2)
WebUI.selectOptionByValue(findTestObject(‘create new booking as a requestor/Page_Interpreter Management System/select-MaleFemale’),
‘F’, true)
WebUI.delay(3)
WebUI.selectOptionByValue(findTestObject(‘create new booking as a requestor/Page_Interpreter Management System/select_MaleFemaleNo’),
‘F’, true)

WebUI.click(findTestObject(‘requestor bookingg/Page_Interpreter Management System/span_Save’))

testcase 2 code
Submit booking

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 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 internal.GlobalVariable as GlobalVariable

WebUI.openBrowser(’’)

WebUI.navigateToUrl(’’)

WebUI.setText(findTestObject(‘submit booking as coordinator/Page_Primaxis Sign in/input_Sign in_username’),
‘TC0001/IMS Trial’)

WebUI.setEncryptedText(findTestObject(‘submit booking as coordinator/Page_Primaxis Sign in/input_Sign in_password’),
‘oagVfJEzz+A=’)

WebUI.click(findTestObject(‘submit booking as coordinator/Page_Primaxis Sign in/button_Sign in’))
WebUI.click(findTestObject(‘confirm agency booking/Page_Interpreter Management System/datespan dropdown’))
WebUI.click(findTestObject(‘Page_Interpreter Management System/li_This Month’))

WebUI.click(findTestObject(‘submit booking as coordinator/Page_Interpreter Management System/button_View’))

WebUI.click(findTestObject(‘submit booking as coordinator/Page_Interpreter Management System/a_Pending’))

WebUI.setText(findTestObject(‘submit booking as coordinator/Page_Interpreter Management System/input_x_bookAppDateFormatted’),
‘10’)

WebUI.click(findTestObject('submit booking as coordinator/Page_Interpreter Management System/td_TCO1-BCT48J’))

WebUI.click(findTestObject(‘submit booking as coordinator/Page_Interpreter Management System/button_Select Agency’))

WebUI.click(findTestObject(‘submit booking as coordinator/Page_Interpreter Management System/a_NABS’))

WebUI.setText(findTestObject(‘submit booking as coordinator/Page_Interpreter Management System/input_x_bookAppDateFormatted’),
‘10’)

WebUI.click(findTestObject(‘submit booking as coordinator/Page_Interpreter Management System/td_TCO1-BCT48J’))

WebUI.click(findTestObject(‘submit booking as coordinator/Page_Interpreter Management System/button_Send to Agency’))
WebUI.delay(2)
WebUI.click(findTestObject(‘submit booking as coordinator/Page_Interpreter Management System/button_Proceed’))

so this is the booking id which will be generated in testcase 1 td_TCO1-BCT48J’))**

it will be changing everytime

how will i get that id in the testcase 2 automatically

I’m not saying that it will be static… It’s just to give you an idea on how to pass values to another test case.

So, if you want it to be dynamic make your data source the value of your variable.

1 Like

Can you please look into the code and please lemme know how can i do that in here

Hi Jayshree,

In your test case 1 (Create Booking):

  • Is the booking id will be visible on the website (TESTCASE_1) once it is generated? Because it seems like the id will be only visible on your test case 2.
WebUI.click(findTestObject('submit booking as coordinator/Page_Interpreter Management System/td_TCO1-BCT48J’))

I also notice that in test case 2 you will log in again and that’s the case where the booking_id will be visible.

If that’s so, then no need to pass parameters from one TC to another TC. . .

So, just rename your booking id test object as “Booking_Id” instead of literally naming it as a real booking id.

And since you also said this:

Just pass the value or text of your booking id test object to a variable:

String booking_Id = WebUI.getText(findTestObject('submit booking as coordinator/Page_Interpreter Management System/Booking_Id’))

So when it changes, your variable will automatically hold the newly created booking id…

and do what you need to do next…

That is what I am trying to point here:

And here:

Hope that answers your question. . . .:slight_smile:

1 Like

yeah thank you so much Arnel
You helped me a lot:)

You’re welcome!

If that helps you, don’t forget to mark it as a solution to this problem and/or give a like for future users to use this as a reference if they encounter the same scenario. . .

Cheers! :beers:

yes it will be generated in the test case 1

Hi Arnel,
sorry to bother you again.
Actually what i want is the booking id which is generated in testcase 1 should be displayed in testcase 2 so that that i cAN SUBMIT THE BOOKING TO AN AGENCY in testcase 2.

Can you please help me with the code for this one .That would be great.
Apologies for bothering you again and again.

Hi Jayshree,

What do you mean by this?? Quite confusing… can you give more information?
Explain a little further. . .

Or much better if you share a screenshot of your website.

Thanks.

Testcase1: Create a booking
In testcase 1 a booking id will be generated (The one which i have highlighted in the screen shot)

g

Testcase 2 submit that booking to an agency

To do this
the steps are:

Go to the pending booking view
Search the booking id which is generated in the testcase 1
Click on the booking
Click on send to agency

What i did:
I have created a global variable and accessed the global variable in the testcase as
GlobalVariable.IMSID = WebUI.getText(findTestObject(‘Object Repository/Add Booking/Page_Interpreter Management System/test_heading_id’))
WebUI.comment('The booking id is ’ + GlobalVariable.IMSID)

Its printing the dynamic value i.e booking id in the console evrytime when i create a booking

What i need is:

It should pick the new booking id which is generated in the testcase 1 and i should be able to use that booking id in different testcases.

Hi Jayshree,

Since you are dealing with list, the code and the process is not quite simple, I also don’t know the behavior of your list like will the checkbox will be marked as checked once I click anywhere on the row or not… Ill be needing another information from you such as html source for us to inspect the items on the list. But here in my reply I’ll be giving you some idea and a code snippet for you to try.

  1. Inspect the items under the column “Booking IDs”.
    1.1. Look for common locator such as class, name, title, or any attribute that is common to them
    1.2. Or, get the xpath of the item. It will give you an xpath something like this:
//Sample 1
//*[@id="sample_id"]/td/tr/h1/li[1]

//or

//Sample 2
//*[@id="sample_id"]/td/tr/h1/li[1]/li[2]/li/[1]

/**
I'm not saying that it will be the exact one but try to observe know their differences. . . 
**/

NOTE 1: if you chose xpath, don’t forget to remove the index ‘[1]’. So it will look like this:

//*[@id="sample_id"]/td/tr/h1/li

/**
The reason why we need to remove it is because when you chose this as your locator,
your script will collect all the similar items related to the xpath and it will be stored in an array
once it becomes visible to your website.
**/

NOTE 2: If you encounter 2 or more indexes when you get the xpath of the item then I suggest
not to use it, it will be complicated rather use 1.1.

  1. From there, make a new test object and use the locator you prefer whether xpath as I mention in 1.2 or attribute name as I mention in 1.1.

CODE

Assuming that your GlobalVariable.IMSID has already acquired the booking ID.

//import webelement
import org.openqa.selenium.WebElement

//create a java list
//this is what I mention earlier, the items found will be stored here once it is visible in your website.
java.util.List<WebElement> bookingIdContainer = WebUiCommonHelper.findWebElements(findTestObject("Your_Object"), 10)

//create a loop
for(index = 0; index < bookingIdContainer.size(); index++)
{
     //the items will be checked one by one until it finds the ID that matches to the value of your global variable.
     if (bookingIdContainer[index].text == GlobalVariable.IMSID)
     {
            bookingIdContainer[index].click

            //do what you need to do next

            //Click on the booking
            //Click on send to agency
     }
     else (other_condition)
     {
            //other step. . .
     }
}

Sorry for late response. . .

If you have any questions, don’t forget to attach the html source in your reply for further investigation.

Additional points: Include the checkbox to your investigation. . .

Hope that helps. . . :slight_smile:

1 Like

Thank you so much Arnel once it works i will mark it as a solution.

I am posting the html elements of my web table so basically we have two divs.can i pick or click the value from the second div after searching in the first div?

My Html source code is as follows:

           <tr role="row" id="2" tabindex="-1" class="jqgrow ui-row-ltr 19B26BB67125E362CA2584230024E9B3 status_new">
              <td role="gridcell" class="jqgrid-rownum active" style="text-align:center;" title="2" aria-describedby="listxGrid_rn">2</td>
              <td role="gridcell" style="text-align:center;" aria-describedby="listxGrid_cb"><input role="checkbox" type="checkbox" id="jqg_listxGrid_2" class="cbox checkbox" name="jqg_listxGrid_2"></td>
              <td role="gridcell" style="" title="New" aria-describedby="listxGrid_bookStatus">New</td>za
              <td role="gridcell" style="" title="Beaudesert Hospital" aria-describedby="listxGrid_bookSiteCode">Beaudesert Hospital</td>
              <td role="gridcell" style="" title="04/07/2019" aria-describedby="listxGrid_bookAppDateFormatted">04/07/2019</td>
              <td role="gridcell" style="display: none;" title="05:42 PM" aria-describedby="listxGrid_bookAppTimeFormatted">05:42 PM</td>
              <td role="gridcell" style="display: none;" title="15" aria-describedby="listxGrid_bookDuration">15</td>
              <td role="gridcell" style="" title="123456" aria-describedby="listxGrid_bookPUrn">123456</td>
              <td role="gridcell" style="" title="Deegal Test" aria-describedby="listxGrid_bookPFullName">Deegal Test</td>
              <td role="gridcell" style="display: none;" title="General Ward" aria-describedby="listxGrid_bookClinic">General Ward</td>
              <td role="gridcell" style="display: none;" title="Beaudesert Hospital" aria-describedby="listxGrid_bookLocation">Beaudesert Hospital</td>
              <td role="gridcell" style="display: none;" title="Inpatient" aria-describedby="listxGrid_bookPType">Inpatient</td>
              <td role="gridcell" style="display:none;" title="IMS" aria-describedby="listxGrid_bookSource">IMS</td>
              <td role="gridcell" style="display: none;" title="Onsite" aria-describedby="listxGrid_bookDeliveryType">Onsite</td>
              <td role="gridcell" style="display: none;" title="" aria-describedby="listxGrid_bookReqComments">&nbsp;</td>
              <td role="gridcell" style="display:none;" title="Agency" aria-describedby="listxGrid_bookIntType">Agency</td>
              <td role="gridcell" style="display: none;" title="■Language Loop" aria-describedby="listxGrid_bookInterpreter"><span class="iColorsGrid iLanguageLoop">■</span>Language Loop</td>
              <td role="gridcell" style="display: none;" title="" aria-describedby="listxGrid_bookIntComments">&nbsp;</td>
              <td role="gridcell" style="display:none;" title="17:57" aria-describedby="listxGrid_bookAppEndTime">17:57</td>a
              <td role="gridcell" style="display:none;" title="" aria-describedby="listxGrid_bookClinician">&nbsp;</td>
              <td role="gridcell" style="display:none;" title="Test Coordinator1" aria-describedby="listxGrid_bookReqBy">Test Coordinator1</td>
              <td role="gridcell" style="display:none;" title="" aria-describedby="listxGrid_bookReqContactNo">&nbsp;</td>
              <td role="gridcell" style="display:none;" title="19B26BB67125E362CA2584230024E9B3" aria-describedby="listxGrid_@unid">19B26BB67125E362CA2584230024E9B3</td>
              <td role="gridcell" style="" title="TCO1-BDF9VM" aria-describedby="listxGrid_bookCBNLaunch">TCO1-BDF9VM</td>
              <td role="gridcell" style="display:none;" title="Beaudesert Hospital" aria-describedby="listxGrid_bookSiteName">Beaudesert Hospital</td>
              <td role="gridcell" style="display:none;" title="TCO1-BDF9VM" aria-describedby="listxGrid_cbnIMSID">TCO1-BDF9VM</td>
              <td role="gridcell" style="display:none;" title="TCO1-BDF9VM" aria-describedby="listxGrid_bookIMSID">TCO1-BDF9VM</td>
              <td role="gridcell" style="display:none;" title="BOOK" aria-describedby="listxGrid_form">BOOK</td>
              <td role="gridcell" style="display: none;" title="" aria-describedby="listxGrid_bookAgencyID">&nbsp;</td>
           </tr>
           <tr role="row" id="3" tabindex="-1" class="jqgrow ui-row-ltr 81C239938B6BAB61CA2584230025B597 status_new">
              <td role="gridcell" class="jqgrid-rownum active" style="text-align:center;" title="3" aria-describedby="listxGrid_rn">3</td>
              <td role="gridcell" style="text-align:center;" aria-describedby="listxGrid_cb"><input role="checkbox" type="checkbox" id="jqg_listxGrid_3" class="cbox checkbox" name="jqg_listxGrid_3"></td>
              <td role="gridcell" style="" title="New" aria-describedby="listxGrid_bookStatus">New</td>
              <td role="gridcell" style="display: none;" title="Hindi" aria-describedby="listxGrid_bookLanguage">Hindi</td>
              <td role="gridcell" style="" title="PAH" aria-describedby="listxGrid_bookSiteCode">PAH</td>
              <td role="gridcell" style="" title="07/07/2019" aria-describedby="listxGrid_bookAppDateFormatted">07/07/2019</td>
              <td role="gridcell" style="display: none;" title="02:41 AM" aria-describedby="listxGrid_bookAppTimeFormatted">02:41 AM</td>
              <td role="gridcell" style="display: none;" title="15" aria-describedby="listxGrid_bookDuration">15</td>
              <td role="gridcell" style="" title="123456" aria-describedby="listxGrid_bookPUrn">123456</td>
              <td role="gridcell" style="" title="Deegal Test" aria-describedby="listxGrid_bookPFullName">Deegal Test</td>
              <td role="gridcell" style="" title="TCO1-BDFA39" aria-describedby="listxGrid_bookCBNLaunch">TCO1-BDFA39</td>
              <td role="gridcell" style="display:none;" title="PAH" aria-describedby="listxGrid_bookSiteName">PAH</td>
              <td role="gridcell" style="display:none;" title="TCO1-BDFA39" aria-describedby="listxGrid_cbnIMSID">TCO1-BDFA39</td>
              <td role="gridcell" style="display:none;" title="TCO1-BDFA39" aria-describedby="listxGrid_bookIMSID">TCO1-BDFA39</td>
              <td role="gridcell" style="display:none;" title="BOOK" aria-describedby="listxGrid_form">BOOK</td>
              <td role="gridcell" style="display: none;" title="" aria-describedby="listxGrid_bookAgencyID">&nbsp;</td>
           </tr>
        </tbody>
     </table>
  </div>
![snip|690x54](upload://fC1b8caw0VKKuqPiQJMcj4qn1b8.png) ![div1|690x26](upload://oxKBSvXuVMr0jy4bVTSKHyz6NWw.png) ![div2|690x42](upload://cDYJW6rRtjvqqy86yXuzHcKwb4L.png)

Please help me to click the booking id from the table?

Screen shots of the table

Table


DiV 1

Div 2

issue resolved