Is it possible to pass the variable value from the test case to the data file?

Hi,

I have a query Is that even possible to pass the variable value from the test case to the data file? If yes, then how?

//Get The count of the projects Pagination first:
	List<WebElement> Lists_Count = WebUiCommonHelper.findWebElements(Project_Pagination_Row , 30)

	//Get the size of the lists
	int columns_count = Lists_Count.size()
	println("Total number of saved lists are: " + columns_count)
	
	
	WebUI.delay(5)


	if (columns_count > 0)
		{
			for (int i = 0; i< columns_count; i++ )
				{
					ExpectedText = Lists_Count.get(i).getText()
println("Pagination no is: " + ExpectedText)

				}
		}

The above is the code written in TestCase1. I want to get the value of the ExpectedText and utilize this value in the data file.

What do you mean by saying “the data file”? You haven’t describe it at all.

@kazurayam
I am using the DATA-DRIVEN approach so instead of getting the hard-coded data I am getting the data/value using (Excel or CSV or internal file) files
By Data file, I mean this
image

Your test case is a Groovy script. It can overwrite any file during its run.

However, “Data-driven” approach does NOT support reloading the file during a run.

Therefore, your test case can not see the updated content of the file through “Data-driven”.

Is it really necessary to write the value of variable ExpectedTest into a file?

I would guess you can utilize the variable just on memory in various ways without serialization into file.

Or, you can store the value into a GlobalVariable, which can be accessed by other test cases easily.

What I am trying to do is:

I have this pagination box

First I get the count of the pagination numbers. The last value I get (Highlighted in the image below) I want to pass it to the File that ExpectedText value will decide which pagination number to click.

WebUI.delay(5)
	//Get The count of the projects Pagination first:
	List<WebElement> Lists_Count = WebUiCommonHelper.findWebElements(Project_Pagination_Row , 30)

	//Get the size of the lists
	int columns_count = Lists_Count.size()
	println("Total number of saved lists are: " + columns_count)
	if (columns_count > 0)
		{
			for (int i = 0; i< columns_count; i++ )
				{
					ExpectedText = Lists_Count.get(i).getText()
println("Pagination no is: " + ExpectedText)

				}
		}
	```

As you can see in the below code I am trying to replace the PagCount with Pagination_Row_No (given from Data file)

So, I want to pass the ExpectedText Value in this column named Pagination_Row_No in Data file. 

![image|690x231](upload://fvMPGsxNor3XBVuOpgW3b4Zgya.png)



The Xpath for the pagination row is: 


//ul[@class = "pagination b-pagination"]/li/button[@class ="page-link" and contains(text(),PagCount)]

TestObject myTest = findTestObject("Object Repository/Project_Page_Xpaths/Bulk_Operations/Project_Pagination_Count")
String test = myTest.findPropertyValue("xpath")
test = test.toString().replace("PagCount", Pagination_Row_No)
println(test)
myTest.findProperty("xpath").setValue(test)
WebUI.waitForElementPresent(myTest, 30)

//clicking the required pagination count
WebUI.click(myTest)
WebUI.delay(5)


I just hope this makes sense

I believe you do not need to save the value of ExpectedText into data file.

How? … Well, you would be able to find the way yourself.