Can we pass the TEST OBJECTS to Internal file and use it in the test case?

Hi, My query is I have 3 different search options on the same Page

  1. Search By name (Option 1 )
  2. Global search (Option 2)
  3. Advanced Search (Option 3)

I want to make it dynamic. Like, instead of creating 3 different test cases for the search purpose. I want to create only 1 test case which can handle all the 3 searches through the if/else condition. But for that, I have to pass the Search Test Object either through a Data file or a Global variable. Is that even possible?

I hope the question makes sense.

Could you write a test case which makes a query to your Application Under Test with all 3 options given with a sample concrete values. For example,

  1. Search By name <= “foo”
  2. Global search <= “bar”
  3. Advanced Search <= “baz”

You should make the sample code runnable; it should PASS without compile errors.

Once written, please share the entire code of your test case script here.

Provided with a concrete code, then we would be able to understand what you want to do. Provided with your base code, possibly somebody would be able to advise you how to revise it so that it accepts external data to make it “dynamic”.

I apologize if I wasn’t clear enough!
Let’s say we have 3 search options on the same page. I want to search “ABC” on the given list of Projects. And it can be searched through all the given search options.

And I want to use a search button through a data file like CSV. it should depend on the user through which search he wants to filter out the results.

So, I was asking is that possible to pass the WebElement[ i.e Search button] through the data file, and if yes how?

Like if the user wants to filter through Global search, he just needs to pass the Global Search Xpath in the file.

We can speak only by code. Don’t we?

Literal description helps. But I do need to see your code first. I would read explanations later.


In brief - WRITE SOME CODE! :sunglasses:

What @kazurayam is struggling with is your English. Kaz is not a native English speaker, but I am. I can’t understand what it is you want to achieve since most of your questions make no sense to me. Sorry.

What Kaz is asking you to do is write some code. Get the idea started in code. Code (backed up with good comments) has a way of removing ambiguities and providing clear statements of your intentions. Your (and our) English, on the other hand, can be full of subtle twists in meaning which seriously impedes true understanding.

First step: Write a Test Case that searches using just option 1.

Second step: Add the ability to repeat the search using option 2.

  Reload the page, then choose option 2.

Third step: Add a search for option 3.

  Again, reload the page, then choose option 3.

If you get stuck, post a specific question about a specific problem. And make sure we can see your code.

1 Like

It is not possible to pass the WebElement or TestObject through the data file (at least I don’t know how). You can only pass Strings and Numbers. However, you can pass the String that makes up the xpath, or css, or the pathway or your Object Repository that composes the WebElement or TestObject. You will have to recreate your “Search” WebElement, or TestObject, from your String, like:

def yourStrHere = excelData.getValue(x,y)
WebElement mySearchButton = driver.findElement(By.xpath('yourStrHere'));

or even

def yourTestObjectPathway = excelData.getValue(x,y)
TestObject mySearchButton = findTestObject("${yourTestObjectPathway}")

??Maybe even include the “findTestObject” onto the String within the data file.??

def yourTestObject = excelData.getValue(x,y)
TestObject mySearchButton = "${yourTestObject}"
1 Like

I suppose that @hijabf529 would not know of org.openqa.selenium.WebElement class at all.

@Russ_Thomas @kazurayam Sorry for causing the misunderstanding! :smiling_face_with_tear:
Appreciate your response.

Here is the little code which I wrote using SEARCH OPTION 1 and it works.

@Russ_Thomas Now, just like you said I should reload and then use OPTION 2 and so on… That’s 1 solution. But what I want to do is

If this doesn’t make sense I don’t know how to explain :sweat:

yes, you are right as I am totally an amateur on Katalon right now. Just getting started on it. I apologize for such a lame query

Please copy & paste the entire source code ( line#1 … to the end) of your test case here in a new post.

A screenshot is not enough to reproduce your case on our side. We need your source code copiable into our PC.

When you copy your source, please enclose it inside a pair of triple backticks.

This makes your post better readable for others.

//Calling the LOGIN Test Case
WebUI.callTestCase(findTestCase("Test Cases/Login_Logout_Scenario/Login_Logout_Scenario"),
		[("User_Email"): user_input , ("User_Password"): user_password  ], FailureHandling.STOP_ON_FAILURE)
//Click on project main page
if(WebUI.waitForElementPresent(Project_Link, 60))
	println('Project detail mode is displayed')
	println("Couldn't find the Project Button")
//Get the total count of projects before searching
GIVENCount = WebUI.getText(TotalCountOfProject)
TotalProjectCount = GIVENCount.substring(8,12)
System.out.println("There are " + TotalProjectCount + " Project records.")
//Click on the Search button. Search project through project name.
WebUI.waitForElementClickable(ProjectSearchByName, 30)
//Set Project Name fetching from the file data
WebUI.setText(ProjectSearchByName, ProjectName)
System.out.println("The entered Project name is : " + ProjectName)
// Declaring the variables
String   GetProjectName,   ProjectNotFoundMessag,  Headingtext,  CellText
//Calling the verification method here!!!!
CustomKeywords.'project_Page.Project_Search.ProjectSearchCase'(ProjectName, EditProjectName,  
	 ProjectNotFoundMessage, ProjectNotFoundMessag,  Headingtext, CellText)

It seems you trimmed lines before

//Calling the LOGIN Test Case

You can’t share the leading part?

Why not you expose the URL of your target web page?

Is it a private one or you can’t share it to us for some security reasons?

If so, I am discouraged. If you can not tell us the target URL, I would quit. Because it is very difficult to think about the HTML that I can not actually see.

you have some security reason.

OK, I understand it.

now you can delete the preceding post.

Thanks for your understanding! :slightly_smiling_face:
I just hope this helps now

Your question is highly dependent on the structure of the HTML source. Therefore we need to be able to open it in browser in hand to see the HTML source code and study in detail.

HTML source code matters! Please understand this.

But you can not share the live URL and username/password for security reason. OK, I understand it.

Then, please save the target page (after login) into a MIME HTML file, and share the file here.

The following post tells you how to save a web page into a MIME HTML file.

The credentials (username/password) will not be included in the MHT file. So you need not be worrried about the security.

Provided with the saved HTML shared, others will be able to open the HTML in their own browser and look at the HTML structure precisely. Then somebody would be able to give you some productive advices.

@kazurayam here you go!
FollowupCRM.mht (4.6 MB)

Thank you for sharing your mht file. I could open the web page on my PC.

After I looking at the page, I went back to your original post (to your original question). Also I had a look at your code. — Still I do not understand what you want to do.

You wrote: “I want to make this Search as Test Data Value which can be passed through data file”.

Possiblly what is called “Data-driven testing approach in Katalon Studio” is the answer to this particular question. Have a look at the following article, go through its instruction:

Katalon provides some more pages concerning “Data driven testing”. Google search will tell you the URLs.

Thanks for all your replies. I think I have almost got it @grylion54 approach is something that I was looking for.
Many thanks! @kazurayam @grylion54 :slightly_smiling_face:

1 Like