# \[Keywords\] Map variable

**URL:** <https://forum.katalon.com/t/keywords-map-variable/10429>\
**Category:** Web Testing\
**Tags:** katalon-studio\
**Created:** [April 20, 2018, 9:48am UTC](https://forum.katalon.com/t/keywords-map-variable/10429 "2018-04-20T09:48:02Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![xio](https://avatars.discourse-cdn.com/v4/letter/x/ed655f/32.png) [@xio](https://forum.katalon.com/u/xio)\
**Post date:** [April 20, 2018, 9:48am UTC](https://forum.katalon.com/t/keywords-map-variable/10429/1 "2018-04-20T09:48:02Z")

</div>

```auto
In the beginning, I created a new custom keyword:@Keyworddef testMapVariable (Map <String, String> myMap) {}Then I created a new test case and using the manual mode.I add the custom keyword that I created.When I try to specify a value in the input field by double click,Param type is Map and Value type is test object.And each time have to replace Test object by selecting Map from the drop-down list.Maybe I'm wrongly passing the Map variable as a parameterand would be very grateful if you could give me a solution.

```

---

<div class="post-metadata">

**Author:** ![xio](https://avatars.discourse-cdn.com/v4/letter/x/ed655f/32.png) [@xio](https://forum.katalon.com/u/xio)\
**Post date:** [April 20, 2018, 9:56am UTC](https://forum.katalon.com/t/keywords-map-variable/10429/2 "2018-04-20T09:56:51Z")

</div>

My CustomKeyword

![](https://s3.amazonaws.com/katalon-forum/editor/9r/ki4xdcoc48l8.png "Image: https://s3.amazonaws.com/katalon-forum/editor/9r/ki4xdcoc48l8.png")

Add it in Test Case and

![](https://s3.amazonaws.com/katalon-forum/editor/6h/hd0haq26ltbu.png "Image: https://s3.amazonaws.com/katalon-forum/editor/6h/hd0haq26ltbu.png")

after double click on Input field

![](https://s3.amazonaws.com/katalon-forum/editor/e8/f07ecpzfuaah.png "Image: https://s3.amazonaws.com/katalon-forum/editor/e8/f07ecpzfuaah.png")

and change value type to Map  
 ![](https://s3.amazonaws.com/katalon-forum/editor/dj/mm0hgepgatq2.png "Image: https://s3.amazonaws.com/katalon-forum/editor/dj/mm0hgepgatq2.png")

[image.png](https://s3.amazonaws.com/katalon-forum/editor/6h/hd0haq26ltbu.png)

[map\_no\_to.png](https://s3.amazonaws.com/katalon-forum/editor/e8/f07ecpzfuaah.png)

[myMap.png](https://s3.amazonaws.com/katalon-forum/editor/9r/ki4xdcoc48l8.png)

[manual\_replaca\_value\_type.png](https://s3.amazonaws.com/katalon-forum/editor/dj/mm0hgepgatq2.png)

---

<div class="post-metadata">

**Author:** ![abhishek\_kumar](https://avatars.discourse-cdn.com/v4/letter/a/eb9ed0/32.png) [@abhishek\_kumar](https://forum.katalon.com/u/abhishek_kumar)\
**Post date:** [April 20, 2018, 11:09am UTC](https://forum.katalon.com/t/keywords-map-variable/10429/3 "2018-04-20T11:09:25Z")

</div>

Hi,  
You may create keyword in this way also,

public class testOfTest {

@Keyword

public void map(Map\<String, String\> myMap){

}

}

---

<div class="post-metadata">

**Author:** ![xio](https://avatars.discourse-cdn.com/v4/letter/x/ed655f/32.png) [@xio](https://forum.katalon.com/u/xio)\
**Post date:** [April 20, 2018, 12:36pm UTC](https://forum.katalon.com/t/keywords-map-variable/10429/4 "2018-04-20T12:36:00Z")

</div>

Hi [abhishek kumar](http://forum.katalon.com/profile/4738/abhishek%20kumar "Link: http://forum.katalon.com/profile/4738/abhishek%20kumar"),

thanks of course, but the access modifiers do not change anything. The value type is still test object.

---

<div class="post-metadata">

**Author:** ![Brian\_Ducson](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/brian_ducson/32/603_2.png) [@Brian\_Ducson](https://forum.katalon.com/u/Brian_Ducson)\
**Post date:** [October 30, 2018, 9:53am UTC](https://forum.katalon.com/t/keywords-map-variable/10429/5 "2018-10-30T09:53:09Z")

</div>

![](https://s3.amazonaws.com/katalon-forum/editor/9z/uu6yhnt5lkgq.png) ![](https://s3.amazonaws.com/katalon-forum/editor/i5/lqq93r8lr7u2.png)xio,

Please correct me if I am wrong. Did you try to set “findTestObject()” into the Map variable? findTestObject return an Object, not a Map.

[Screen Shot 2018-10-30 at 16.53.57.png](https://s3.amazonaws.com/katalon-forum/editor/9z/uu6yhnt5lkgq.png)

[Screen Shot 2018-10-30 at 16.54.09.png](https://s3.amazonaws.com/katalon-forum/editor/i5/lqq93r8lr7u2.png)

---

<div class="post-metadata">

**Author:** ![xio](https://avatars.discourse-cdn.com/v4/letter/x/ed655f/32.png) [@xio](https://forum.katalon.com/u/xio)\
**Post date:** [November 8, 2018, 9:56pm UTC](https://forum.katalon.com/t/keywords-map-variable/10429/6 "2018-11-08T21:56:29Z")

</div>

> Brian Ducson said:
> 
> ![](https://dub1.discourse-cdn.com/katalon/uploads/default/original/1X/9eb2e7bd6f5c57df8bf233d2887a26da4148fd62.png) ![](https://dub1.discourse-cdn.com/katalon/uploads/default/original/1X/5fce674e2959a9475f59f2d3da755dd0464a8519.png)xio,
> 
> Please correct me if I am wrong. Did you try to set “findTestObject()” into the Map variable? findTestObject return an Object, not a Map.

Of course not. I never tried to pass the findTestObject () method to the Map variable.

My goal is to transfer Map to a custom method as a parameter and later use it in a test case by setting parameters in manual mode.

And when I open the test case in manual mode, the value type turns out to be a String (used to be TestObject) in the place of Map. Therefore, you have to specify the correct value type Map each time, choosing from the drop-down list.

In the task, I ask that the Map variable when editing the parameters of the custom method have the correct Value Type

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [January 25, 2019, 8:51pm UTC](https://forum.katalon.com/t/keywords-map-variable/10429/7 "2019-01-25T20:51:20Z")

</div>

> [@xio](#):
>
> And when I open the test case in manual mode, the value type turns out to be a String (used to be TestObject) in the place of Map. Therefore, you have to specify the correct value type Map each time, choosing from the drop-down list.

I guess that **the dialog titled `Input` is designed simple** (stupid, buggy … whatever you may say).

- The `Input` dialog does not recognize your `my_map` param is defined to be of Map type.
- It just assumes every param should be of String type as default.
- It expects users to manually change the Value Type if he/she requires some other types.

as you see.

The `Input` dialog seems not to be capable of implementing what you want.

* * *

Possible workaround:

1. Stick to the idea of using the `Input` dialog to set/change values of params.
2. Abandon single param of Map type.
3. Use multiple params of String named `lastName` and `firstName`.

* * *

Changing your approach:

1. Abandon the idea of using the `Input` dialog to set/change values of params.
2. Stick to the param type to be Map
3. Employ some other way of expressing your data. But how? … there are many options for you, for example …

- Have you tried `Execution Profile` (GlobalVariables)? it might be the same, though.
- How about creating a JSON file `<project dir>/Data Files/myParams.json`. You edit it with any text editor, your test case reads the file, parse the text to find the value, pass the values as arguments to your custom keywords.

---

<div class="post-metadata">

**Author:** ![xio](https://avatars.discourse-cdn.com/v4/letter/x/ed655f/32.png) [@xio](https://forum.katalon.com/u/xio)\
**Post date:** [January 26, 2019, 2:09pm UTC](https://forum.katalon.com/t/keywords-map-variable/10429/8 "2019-01-26T14:09:15Z")

</div>

Thank you for your reply **kazurayam**.

I tried everything that you described above.  
And it works well if there are not too many parameters that I need to pass to the method.

A json file is also a good idea.  
I did this by adding a json file in “Data Files” directory.  
File with structure in this format:

```
{ 
  "TestName" : "test name", 
  "TestNumber" : 1,
  "TestDate" : "test date",
  "TestChecked" : false,   
  "TestDataArray" : {
                       "data1" : "<data1>",
                       "data2" : "<data2>",
                       "data3" : null,
                       "data4" : false
                      },  
  "TestResultArray" : {
                       "result1" : "<result1>",
                       "result2" : "<result2>"
                      }
 }

```

Then in the “Test case” I created new variable “requestBody” in which passed the contents of the file.

```
String requestBody = new File ('Data Files / Test.json').text

```

And then I changed the values ​​of the fields I needed, for what I need using:

```
requestBody .replace ("<data1>", "some test value") 

```

But unfortunately this approach does not suit others.

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [January 26, 2019, 2:49pm UTC](https://forum.katalon.com/t/keywords-map-variable/10429/9 "2019-01-26T14:49:26Z")

</div>

Your text is not a valid JSON. Syntactically wrong.

I changed it as follows. This is a valid JSON. :

```auto
{
    "TestName" : "test name",
    "TestNumber" : 1,
    "TestDate" : "test date",
    "TestChecked" : false,
    "TestData" : {
        "data1" : "<data1>",
        "data2" : "<data2>",
        "data3" : null,
        "data4" : false
    },
    "TestResult" : {
        "result1" : "<result1>",
        "result2" : "<result2>"
    }
 }

```

Please check it and find differences for yourself.

I made a test case as follows:

```auto
import groovy.json.JsonSlurper

String text = new File('Data Files/Test.json').text
def jsonSlurper = new JsonSlurper()
def object = jsonSlurper.parseText(text)
println "object.TestData.data1 is '${object.TestData.data1}'"
object.TestData.data1 = "some test value"
println "object.TestData.data1 is '${object.TestData.data1}'"

```

When I ran it, I got the following messages in the console:

```auto
...
object.TestData.data1 is '<data1>'
...
object.TestData.data1 is 'some test value'

```

Hope this helps.

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [January 26, 2019, 2:55pm UTC](https://forum.katalon.com/t/keywords-map-variable/10429/10 "2019-01-26T14:55:17Z")

</div>

You can pass the JSON object instance (the `object` variable in the above sample code) as a parameter to your keyword instead of Map, you know.

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [January 26, 2019, 2:59pm UTC](https://forum.katalon.com/t/keywords-map-variable/10429/11 "2019-01-26T14:59:04Z")

</div>

> [@kazurayam](#):
>
> object.TestData.data1 = “some test value”

“some test value” above is a simple String.

You can give the value (in place of “some test value”) through the **Input** dialog, you know.

---

<div class="post-metadata">

**Author:** ![xio](https://avatars.discourse-cdn.com/v4/letter/x/ed655f/32.png) [@xio](https://forum.katalon.com/u/xio)\
**Post date:** [January 26, 2019, 3:15pm UTC](https://forum.katalon.com/t/keywords-map-variable/10429/12 "2019-01-26T15:15:35Z")

</div>

At the moment things are as follows:

- there is a test class “test.groovy” in which Map model defined
- there is a CustomKeyword that accepts TestObject and a previously defined Map as a parameter

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

And when we add the created CustomKeyword to TestCase, we get the following:

 ![image](https://europe1.discourse-cdn.com/katalon/original/2X/7/73d4ebff61f195014c52da90aad8310ce3d553ac.png)

The only way to solve this problem is to write the values ​​manually in the test case itself using Script mode looks like this:

 ![image](https://europe1.discourse-cdn.com/katalon/original/2X/7/79671d40246b456cb5c5d40f43cac8f7bca963f8.png)

And if after this switch to Manual mode, everything will be as it should

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

And the question is, can there be any way to transfer the Map in this form as a parameter at once?

---

<div class="post-metadata">

**Author:** ![xio](https://avatars.discourse-cdn.com/v4/letter/x/ed655f/32.png) [@xio](https://forum.katalon.com/u/xio)\
**Post date:** [January 26, 2019, 3:19pm UTC](https://forum.katalon.com/t/keywords-map-variable/10429/13 "2019-01-26T15:19:46Z")

</div>

Thank you kazurayam!  
You right wrong brackets “[” and “]” in my example.  
I fixed it.

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [January 26, 2019, 7:50pm UTC](https://forum.katalon.com/t/keywords-map-variable/10429/14 "2019-01-26T19:50:03Z")

</div>

I suppose  
a) You have a property named `testMap` of Map type in the class `test.test` located at `Keywords/test.groovy` file. The `testMap` is initialized with a Map literal.  
b) You have similar Map literal in the test case located at `Test Cases/test.groovy` as well  
c) You want to keep the Map literal in a) and you want to _transfer_ it (or silently copy it somehow) into b)

Am I right?

I do not think c) is possible.

What should you do?

Possibly, you should remove a) and forget about it. You should be satisfied with b). What do you want more?

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [January 26, 2019, 10:16pm UTC](https://forum.katalon.com/t/keywords-map-variable/10429/15 "2019-01-26T22:16:36Z")

</div>

> [@xio](#):
>
> You right wrong brackets “[” and “]” in my example.

I believe you understand it but let me note to make things clear for those who happened to read this thread …

In JSON syntax a JSON object should be in the format of `{name:value}`.  
In Groovy syntax a Map literal should be in the format of `[name:value]`.  
What xio has in his/her code is NOT a JSON string.  
What xio has in his/her code is a Map literal in Groovy syntax.
