# Turn geturl into a variable

**URL:** <https://forum.katalon.com/t/turn-geturl-into-a-variable/39846>\
**Category:** Web Testing\
**Tags:** katalon-studio\
**Created:** [February 13, 2020, 3:43pm UTC](https://forum.katalon.com/t/turn-geturl-into-a-variable/39846 "2020-02-13T15:43:36Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paul\_Smith1](https://avatars.discourse-cdn.com/v4/letter/p/5daacb/32.png) [@Paul\_Smith1](https://forum.katalon.com/u/Paul_Smith1)\
**Post date:** [February 13, 2020, 3:43pm UTC](https://forum.katalon.com/t/turn-geturl-into-a-variable/39846/1 "2020-02-13T15:43:36Z")

</div>

Is there anyone that could clearly with examples, let me know how to turn a geturl into a global variable for use within my project?

thanks

---

<div class="post-metadata">

**Author:** ![helpdesk](https://avatars.discourse-cdn.com/v4/letter/h/7c8e57/32.png) [@helpdesk](https://forum.katalon.com/u/helpdesk)\
**Post date:** [February 13, 2020, 8:00pm UTC](https://forum.katalon.com/t/turn-geturl-into-a-variable/39846/2 "2020-02-13T20:00:39Z")

</div>

Here are some links to assist you with getUrl and creating a GlobalVariable. The getUrl returns a string so the GlobalVariable should be a String type. Then, use the getUrl into the GlobalVariable.

> **[Global Variables and Execution Profile](https://docs.katalon.com/katalon-studio/docs/execution-profile-v54.html)**
>
> Execution Profile Execution Profile is available starting in Katalon Studio version 5.4 and enhanced with a Scripting Editor in version 5.9. Katalon Studio v5.4 introduces another flexible way to extend...

> **[\[WebUI\] Get Url](https://docs.katalon.com/katalon-studio/docs/webui-get-url.html#example)**
>
> Description   Get URL of the current window. Parameters   Param Param Type Mandatory Description flowControl FailureHandling Optional Specify failure handling schema to determine whether the execution should be allowed...

and some samples:  
GlobalVariable.gSiteUrl = WebUI.getUrl();

GlobalVariable.gImportFileName = ‘G:\Katalon Test Cases\Data Files\Big Fight.txt’;

finally, make sure you have both of these in your import list at the top of the Test Case:

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

---

<div class="post-metadata">

**Author:** ![Paul\_Smith1](https://avatars.discourse-cdn.com/v4/letter/p/5daacb/32.png) [@Paul\_Smith1](https://forum.katalon.com/u/Paul_Smith1)\
**Post date:** [February 14, 2020, 2:40am UTC](https://forum.katalon.com/t/turn-geturl-into-a-variable/39846/3 "2020-02-14T02:40:19Z")

</div>

Thanks for your reply:

Question: is this GlobalVariable.gSiteUrl = WebUI.getUrl(); actually defined in the profile? or the script?

thanks

---

<div class="post-metadata">

**Author:** ![Paul\_Smith1](https://avatars.discourse-cdn.com/v4/letter/p/5daacb/32.png) [@Paul\_Smith1](https://forum.katalon.com/u/Paul_Smith1)\
**Post date:** [February 14, 2020, 3:48pm UTC](https://forum.katalon.com/t/turn-geturl-into-a-variable/39846/4 "2020-02-14T15:48:22Z")

</div>

Larger Context:

Objective: I have a setup script where I am trying to getUrl - and Define it as a global variable for use in other scripts.

Process: This is defined inside my setup script  
GlobalVariable.simURL = WebUI.getUrl()

Next, in my default profile I define simURL:

 ![image](https://europe1.discourse-cdn.com/katalon/original/2X/4/49ba12211ae1ae0616031bb13b4742d643b5c4de.png)

This is NOT working: in a test suite when I try and navigate to Url GlobalVariable.simURL it fails with: Step failed exception Unable to navigate to "  
I also have the necessary import installed:  
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI  
import internal.GlobalVariable as GlobalVariable

Next

I

Can I define the getUrl as a global variable in a script?  
Is this possible?

---

<div class="post-metadata">

**Author:** ![Paul\_Smith1](https://avatars.discourse-cdn.com/v4/letter/p/5daacb/32.png) [@Paul\_Smith1](https://forum.katalon.com/u/Paul_Smith1)\
**Post date:** [February 14, 2020, 4:07pm UTC](https://forum.katalon.com/t/turn-geturl-into-a-variable/39846/5 "2020-02-14T16:07:02Z")

</div>

Would gSiteUrl need to be defined in the profile?

---

<div class="post-metadata">

**Author:** ![helpdesk](https://avatars.discourse-cdn.com/v4/letter/h/7c8e57/32.png) [@helpdesk](https://forum.katalon.com/u/helpdesk)\
**Post date:** [February 18, 2020, 8:20pm UTC](https://forum.katalon.com/t/turn-geturl-into-a-variable/39846/6 "2020-02-18T20:20:31Z")

</div>

@Paul_Smith1, you define GlobalVariables in the Profile. After defining the GV, you can use it in all TestCase pages of a TestSuite after you collect/fill. However, to use the GV in more than the “original” TestSuite where you collect/fill the variable, then you have to SAVE the variable quantity (it’s contents) to an outside Data source, such as MS Excel. Then, when you run the other TestSuites, you “read” the contents of the “original” from the Data source.  
As an example, save an MS Excel file within the Data folder of Katalon Studio. (you need the path and the MS Excel file name in your query; see below) Now, after you have the GV filled, save it to MS Excel (you can find similar examples in other KS questions) :

import java.io.FileInputStream;  
import java.io.FileNotFoundException;  
import java.io.FileOutputStream;  
import java.io.IOException;  
import org.apache.poi.ss.usermodel.Cell;  
import org.apache.poi.ss.usermodel.Row  
import org.apache.poi.xssf.usermodel.XSSFWorkbook;  
import org.apache.poi.xssf.usermodel.XSSFSheet;

FileInputStream fis = new FileInputStream (“G:\Katalon Studio\Data Files\TestId 23.xlsx”);

XSSFWorkbook workbook = new XSSFWorkbook (fis);

XSSFSheet sheet = workbook.getSheet(“Sheet1”);  
// set data in cell A2  
Row row = sheet.createRow(1);  
Cell cell = row.createCell(0);

cell.setCellType(cell.CELL\_TYPE\_STRING);  
cell.setCellValue(GlobalVariable.gLastName);  
FileOutputStream fos = new FileOutputStream(“G:\Katalon Studio\Data Files\TestId 23.xlsx”);  
workbook.write(fos);  
fos.close();

Now, in a second TestSuite, read the GV back from the MS Excel sheet into the TestCase (you need the same import statements as above) :  
FileInputStream fis = new FileInputStream (“G:\Katalon Studio\Data Files\TestId 23.xlsx”);

XSSFWorkbook workbook = new XSSFWorkbook (fis);

XSSFSheet sheet = workbook.getSheet(“Sheet1”);

// read data from cell A2  
Row row = sheet.getRow(1);  
Cell cell = row.getCell(0);  
// read in the user’s last name  
GlobalVariable.gLastName = cell.getStringCellValue();

Hope I have addressed all your concerns.

---

<div class="post-metadata">

**Author:** ![Paul\_Smith1](https://avatars.discourse-cdn.com/v4/letter/p/5daacb/32.png) [@Paul\_Smith1](https://forum.katalon.com/u/Paul_Smith1)\
**Post date:** [February 19, 2020, 4:48pm UTC](https://forum.katalon.com/t/turn-geturl-into-a-variable/39846/7 "2020-02-19T16:48:52Z")

</div>

> [@helpdesk](#):
>
> FileInputStream fis = new FileInputStream (“G:\Katalon Studio\Data Files\TestId 23.xlsx”);
> 
> XSSFWorkbook workbook = new XSSFWorkbook (fis);
> 
> XSSFSheet sheet = workbook.getSheet(“Sheet1”);
> 
> // read data from cell A2  
> Row row = sheet.getRow(1);  
> Cell cell = row.getCell(0);  
> // read in the user’s last name  
> GlobalVariable.gLastName = cell.getStringCellValue();

This worked magnificently well, thanks very much for your very clear response and instructions. I hope this thread can remain somewhere where Katalon users may easily find it for reference purposes.

thanks again!

---

<div class="post-metadata">

**Author:** ![Timo\_Kuisma1](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/timo_kuisma1/32/16103_2.png) [@Timo\_Kuisma1](https://forum.katalon.com/u/Timo_Kuisma1)\
**Post date:** [February 19, 2020, 7:21pm UTC](https://forum.katalon.com/t/turn-geturl-into-a-variable/39846/8 "2020-02-19T19:21:41Z")

</div>

hello,

excel, ugh, ok if it works, but as in testengineer should use better way e.g postgress db 🙂

---

<div class="post-metadata">

**Author:** ![Russ\_Thomas](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/russ_thomas/32/11884_2.png) [@Russ\_Thomas](https://forum.katalon.com/u/Russ_Thomas)\
**Post date:** [February 19, 2020, 7:27pm UTC](https://forum.katalon.com/t/turn-geturl-into-a-variable/39846/9 "2020-02-19T19:27:40Z")

</div>

Timo, instead of merely passing comment, please write a Tips&Tricks article that explains how to install setup Postgres to use for testing and how to integrate with Katalon.

[![](http://forum.katalon.com/images/emoji/twitter/slightly_smiling_face.png?v=9) ](http://forum.katalon.com/images/emoji/twitter/slightly_smiling_face.png?v=9)

---

<div class="post-metadata">

**Author:** ![Timo\_Kuisma1](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/timo_kuisma1/32/16103_2.png) [@Timo\_Kuisma1](https://forum.katalon.com/u/Timo_Kuisma1)\
**Post date:** [February 19, 2020, 7:30pm UTC](https://forum.katalon.com/t/turn-geturl-into-a-variable/39846/10 "2020-02-19T19:30:05Z")

</div>

hi, Russ,

Google is our friend 🙂

---

<div class="post-metadata">

**Author:** ![Russ\_Thomas](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/russ_thomas/32/11884_2.png) [@Russ\_Thomas](https://forum.katalon.com/u/Russ_Thomas)\
**Post date:** [February 19, 2020, 7:35pm UTC](https://forum.katalon.com/t/turn-geturl-into-a-variable/39846/11 "2020-02-19T19:35:15Z")

</div>

There’s very little that google does that I would consider friendly. 😕

Please. Write it up. Be our hero.

---

<div class="post-metadata">

**Author:** ![Timo\_Kuisma1](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/timo_kuisma1/32/16103_2.png) [@Timo\_Kuisma1](https://forum.katalon.com/u/Timo_Kuisma1)\
**Post date:** [February 19, 2020, 7:47pm UTC](https://forum.katalon.com/t/turn-geturl-into-a-variable/39846/12 "2020-02-19T19:47:32Z")

</div>

hello,

If I’ll create a document, then I will do it to way that document reader not need to be engineer to get it everything work as it should be. That takes time and my current company will pay me for that, Katalon community is not the payer 🙂 sorry
