How to store url obtained through "current url = WebUI.getUrl() " in test data(in Data files)

In the above post, I mentioned “Excel Keyword” plugin to you. Sorry. To be honest, I have never used it.

Now I looked at it, and found its sole purpose is provide “Keywords” that enables you to indirectly call POI API from the Manual mode of Test Case editor. If you can code scripts in the Script mode, you do not really need the plugin.

The plugin assumes that users do understand the conceptual data model behind the Excel API. The plugin requires users to have similar level of programming skill as the Apache POI.

I wonder who can really make use of this plugin.

  1. The plugin is meant to help the Manual mode users.
  2. The Manual mode users are, usually, not skilled enough for programming.
  3. The plugin assumes users to have good enough programming skill, so that they understand the conceptual data model of the POI API + Excel API.

To me, these 3 statements do not hold true together.

Just for your interest

csv files are also available…

https://www.baeldung.com/groovy-io

@kazurayam
You misunderstand my point.
I told you that I preserve it as an Excel file, but it doesn’t really matter to me whether the file name is csv or xlsx.

If you know the process of storing URL data in GlobalVariable and delivering it from TestCase to another TestCase, please let us know easily. I’m already used to the csv file because I’m already using tools such as Python, sql, and R…

1, in the “default” Execution profile, create a GlobalVariable named “url”
2. create a Test Case “TC1” that opens browser and navigate to a url http://demoaut.katalon.com. It gets the URL string and set it into the GlobalVariable.url
3. create a Test Case “TC2” that reads the GlobalVariable.url, and print it into the log
4. create a Test Suite “TS1” that binds TC1 and TC2
5. execute TS1
6. in the log, you will find a message “url is https://katalon-demo-cura.herokuapp.com

I tried to make TC1. But it doesnn’t RUN(errors)…
And What’s the code for TC2?. Let me share

You typed

htpp://demoaut.katalon.com

It should rather be:

http://demoaut.katalon.com

TC2 is:

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

import internal.GlobalVariable as GlobalVariable

WebUI.comment("url is " + GlobalVariable.url)

@kazurayam
Thank you for your kind explanation. If such a result comes out like this, does it properly worked?

How can I save this URL as the next step? Can you extract it as a csv? I’d appreciate it if you could explain it easily.

And how I input my url default profile variable into Test data?

the green bar indicated that the script ran without any error.

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI 
import internal.GlobalVariable as GlobalVariable 
File f = new File("./data.csv")
f.text = GlobalVariable.url + ",something\n"

Then you would find a file named “data.csv” in the project directory.

1 Like

I don’t understand this question. What do you want to do? Please restate it.


Do you want to update the “Test Data”?

As I wrote previously, the “Test Data” is read-only. Your test case script can not update the “Test Data”.

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import internal.GlobalVariable as GlobalVariable
File f = new File(“./data.csv”)
f.text = GlobalVariable.url + “,something\n”

I added the code you mentioned to TS1 after designating it as TC3.
But I don’t know where the csv was saved… where is my Globalvariable.url?
“data.csv” can not be found…

The file should be found at <projectdir>/data.csv.

I am sure you would find it by Windows Explorer, or Mac Finder.

Do you want to see it in Katalon Studio?

While KS GUI opened, try F5 (Refresh). But, I know quite often the “Refresh” operation does not work in Katalon Studio GUI. See another post

In that case, you should close the project once, and reopen the project.

Yeh Finally I found it. thx for your reply

@kazurayam

I use the for function below to continuously issue new URLs and
I want to put the URL in a row in csv.
Which part should I fix?

for (def row = 1; row <= findTestData('New').getRowNumbers(); row++) {
    WebUI.click(findTestObject('Page_SSCSVNumatcheck/input_SS_SSnum'))

    WebUI.setText(findTestObject('Object Repository/Page_SSCSVNumatcheck/input_SS_SSnum'), findTestData('NEW').getValue(
            'a', row))

    WebUI.uploadFile(findTestObject('Object Repository/Page_SSCSVNumatcheck/input_SSCSV_csvFileSS'), findTestData('NEW').getValue(
            'c', row))

    WebUI.waitForAlert(5)

    WebUI.uploadFile(findTestObject('uploadObject/Page_SSCSVNumatcheck/input_CSV_csvFileNP'), findTestData('NEW').getValue(
            'd', row))

    WebUI.waitForAlert(5)

    WebUI.click(findTestObject('Object Repository/Page_SSCSVNumatcheck/input_SS_button'))

    WebUI.waitForPageLoad(60)

    WebUI.switchToWindowIndex(1 //switches to 2nd window
        )

    secondUrl = WebUI.getUrl()

    println('secondUrl: ' + secondUrl)

    GlobalVariable.url = WebUI.getUrl()

	WebUI.closeWindowIndex(1)
	
    WebUI.switchToWindowIndex(0)

    firstUrl = WebUI.getUrl()

    println('firstUrl: ' + firstUrl)
}

'Save the URL to csv.'
File f = new File('./data1.csv')

f.text = GlobalVariable.url

No way.
As I told you 2 times previously, you can not update the row variable as it is READ-ONLY.

I mean GlobalVariable to csv…


@kazurayam
I just want to get URL then return to csv.