Can I parameterize a part of test object resource-id

Hi All,

I am trying to parameterize a part of resource id. We have different products, each product has a different package name which is added to the resource id, I want to parameterize the package name. Because it is the same test object, just the product changes, hence the package name. Is there any way I can do it?

Thank you.

1 Like

Hi Sravya,

Check out this documentation on Parameterizing a Test Object to see if this helps:

https://docs.katalon.com/display/KD/Manage+Test+Object#ManageTestObject-ParameterizingTestObject

- Chris

.Chris Trevarthen said:

Hi Sravya,

Check out this documentation on Parameterizing a Test Object to see if this helps:

https://docs.katalon.com/display/KD/Manage+Test+Object#ManageTestObject-ParameterizingTestObject

- Chris

Hi Chris,
I have looked at the documentation and it does not provide a solution to my problem, as the document shows parameterizing one particular test object. I need to parameterize resource id for all the test objects in the application. If you can help me with that.

Thanks

as far as i understand, you need to parametrize the name of the test object …

If this is what you want, well, here groovy Gstring may help you with variable substitution, see:

http://grails.asia/groovy-gstring-examples

So you can try something like:

def my_test_obj = "${package_name}_append_something"
findTestObject(my_test_obj)

Pay attention to use double quotes, by using single quotes the variable will be just plain java string

2 Likes

Ibus said:

as far as i understand, you need to parametrize the name of the test object …

If this is what you want, well, here groovy Gstring may help you with variable substitution, see:

http://grails.asia/groovy-gstring-examples

So you can try something like:

def my_test_obj = "${package_name}_append_something"
findTestObject(my_test_obj)

Pay attention to use double quotes, by using single quotes the variable will be just plain java string

Hi Ibus,

Thank you for responding. I actually need to parameterize the value of the test object. We have multiple products with almost the similar interface. Whenever I capture the test object, the resource-id of that test object comes with a package name.example: {packageName}\resource-idName.

As the package name changes, I cannot access the same object in other product with the same interface. I need a way to pass the package name through a global variable, to all the test objects. Can you please help me with that.

Thank you.

How are you getting the package name?

Once you have the ‘packageName’ you can pass it to the global variable (you should create the global variable before running the test) simply by using:

GlobalVariable.PACKAGE_NAME = packageName

(note: this will be valid only during the test suite execution, after that GlobalVariable.PACKAGE_NAME will reset to default value).

Let us say you get the ‘packageName’ in the first test case that is run and it is stored in the global variable, in all the other test cases during this test suite execution, you can now pass the value of the global variable to the parametrized objects as:

${GlobalVariable.PACKAGE_NAME}\resource-idName

Mate Mrse said:

How are you getting the package name?

Once you have the ‘packageName’ you can pass it to the global variable (you should create the global variable before running the test) simply by using:

GlobalVariable.PACKAGE_NAME = packageName

(note: this will be valid only during the test suite execution, after that GlobalVariable.PACKAGE_NAME will reset to default value).

Let us say you get the ‘packageName’ in the first test case that is run and it is stored in the global variable, in all the other test cases during this test suite execution, you can now pass the value of the global variable to the parametrized objects as:

${GlobalVariable.PACKAGE_NAME}\resource-idName

Hello Mate,

Thanks for replying. The solution you have given does not work as the parameterized test object is Not taking the value from global variable directly. It only identifies it, if in Test object Input I am assigning a variable in the test case so that it takes the global variable as mentioned in katalon studio parameterize test object. If I follow that, I have to do that for every test object and assign a variable for every test object used in my test case.

Is there any way to assign global variable directly to the test object instead assigning a variable in the test case and then parameterizing test object with the variable value given in test case.

Sravya,

Can I parameterize a part of test object resource-id

I do not understand what you mean by “test object resource-id”. Could you please give us some examples of it? Also could you show us your test case script as example which deals with “test object resource-id” (which is not yet parameterized, of course)?

Hello Kazurayam,

Resource-id is the unique identifier in android for selecting a test object. In Object’s properties, when I capture a test object it comes with the package name. I am attaching an Image for the reference.

Now I want to give “com.packagename” in the global variable and bind it directly to this test object property resource-id as the package name changes for every product in our company, though the id “doneFilterTv” you see in resource-id, remains same for every product as they have the same screens.

It would be very helpful if there is any way to bind global variable directly in test object property instead following the parametrized test object procedure to access the global variable.

image.png

You can change your Test Objects slightly. Edit the value of Property ‘package’ and ‘resource-id’ to have ${packageName} — this notation expresses a place holder to be interpolated with value specified runtime. See the following example:

You create a GlobalVariable named G_packageName with any value you want:

Finally, your test case will interpolate the ${packageName} with the GlobalVariable value.

TestObject tObjInterpolated = findTestObject(
    'Object Repository/Application/android.widget.TextView - App - parameterized resource-id',
    [('packageName'): GlobalVariable.G_packageName]
)

I printed the test object before interpolation. It was like this:

[
{"name":"class","condition":"equals","value":"android.widget.TextView","isActive":true},
{"name":"instance","condition":"equals","value":"3","isActive":true},
{"name":"text","condition":"equals","value":"App","isActive":true},
{"name":"resource-id","condition":"equals","value":"${packageName}:id/text1","isActive":true}
]

I printed the test object after interpolation. It was like this:

[
{"name":"class","condition":"equals","value":"android.widget.TextView","isActive":true},
{"name":"instance","condition":"equals","value":"3","isActive":true},
{"name":"text","condition":"equals","value":"App","isActive":true},
{"name":"resource-id","condition":"equals","value":"com.packagename:id/text1","isActive":true}
]

Sravya,

I think the test object after interpolation would work for you.

But you wrote:

It would be very helpful if there is any way to bind global variable directly in test object property instead following the parametrized test object procedure to access the global variable.

I am not sure what you mean here. Don’t you find the above mentioned approach satisfactory for you?

parameterized_resource-id.png

G_packageName.PNG

Hello Kazurayam,

Thanks for replying. The problem I am facing with the above approach is I have to interpolate, for each and every test object I use in my test case. which is a lot of work just to detect the object. Because I may have 100 test cases and test objects, and each and every time I have to follow the above procedure for using a test object in my test case.

each and every time I have to follow the above procedure for using a test object in my test case

I do not see what you mean.

You can switch Execution Profile, a set of GlobalVariables, to apply to a Test Suite execution.

Create a Test suite “TS0” which binds your 100 test cases. And create 2 Profiles “prof1”, and “prof2” each of which contains GlobalVarialbe.packageName with different values: ‘my.package.a’ and 'my.package.b". Then you can easily choose executing TS0 with “prof1” or TS0 with “prof2”. I suppose this approach is easy enough. Isn’t it for you, Sravya?

In fact there is no need to do a ‘Controller’ TC0.

If the test object is called as per kazurayam example, with:

GlobalVariable.G_packageName

switching the profile is enough, the variable will be evaluated correctly … so having 100 test cases … I don’t see any problem there

And you can create as many profiles as you want, one for each client.

As for the ‘I may have 100 test objects’ … well, that is not a serious problem, if you correctly parametrize the test object (only not common part).

Even if you have to put 100 variables, once a profile is created, you can easily create a new one: go to the project ‘Profiles’ folder, duplicate an existing .glbl file, open it with a text editor of your choice (e.g. Notepad++) > Search > replace. Refresh your project and the new profile will magically be available

Other option is to build the test object dynamically, see for example:

https://docs.katalon.com/katalon-studio/docs/creation-of-test-object-in-object-repository-in-runtime.html

kazurayam said:

each and every time I have to follow the above procedure for using a test object in my test case

I do not see what you mean.

You can switch Execution Profile, a set of GlobalVariables, to apply to a Test Suite execution.

Create a Test suite “TS0” which binds your 100 test cases. And create 2 Profiles “prof1”, and “prof2” each of which contains GlobalVarialbe.packageName with different values: ‘my.package.a’ and 'my.package.b". Then you can easily choose executing TS0 with “prof1” or TS0 with “prof2”. I suppose this approach is easy enough. Isn’t it for you, Sravya?

Hello Kazurayam,

TestObject tObjInterpolated = findTestObject(
‘Object Repository/Application/android.widget.TextView - App - parameterized resource-id’,
[(‘packageName’): GlobalVariable.G_packageName]
)

Can I know where you have created the above test object so that all the test objects take the global variable value while running a test suite? I am new to katalon and I am trying to figure out ways.

Also, inside a test case are you assigning any variable to the test object that takes the global variable as value. for example

Mobile.tap(findTestObject(‘Login/btn_WhatsNewDone’, [(‘packageName’) : GlobalVariable.G_PackageName]), 0)

Thanks for trying to help out.

Sravya,

Can I know where you have created the above test object so that all the test objects take the global variable value while running a test suite?

I suppose you used Web Recorder or Spy Web to generate your 100 test objects, but you have never edited test objects manually, have you?

Web Recorder will never automatically generate this:

You need to manually edit the value of property of a Test Object. See the following screenshot.

I am saying you should edit 100 test objects manually. You would need to edit your test cases accordingly. :wink:

KatalonDiscussion9786_editingTestObjectProperty.png

4b6ish6wd1nm.png

Sravya,

Also, inside a test case are you assigning any variable to the test object that takes the global variable as value.

Are you asking me any question by this sentence? I do not see what.

kazurayam said:

Sravya,

Can I know where you have created the above test object so that all the test objects take the global variable value while running a test suite?

I suppose you used Web Recorder or Spy Web to generate your 100 test objects, but you have never edited test objects manually, have you?

Web Recorder will never automatically generate this:

You need to manually edit the value of property of a Test Object. See the following screenshot.

I am saying you should edit 100 test objects manually. You would need to edit your test cases accordingly. :wink:

Yes, of course, I have edited everything manually and assigned a global variable in the profiles. The only way I know to bind the value of the global variable to the test object is to assign it in the test case I am running. For example, If I am having a login test case, Where I need to enter email id, to the email id test object inside the test case I need to assign a variable that is taking the value from the global variable and binds it to the test object. I need to assign a variable for every test object I am using in the test case.

I am not sure if it is the same solution that you are providing too. I was thinking if there is any way where the test object that is edited manually takes the value from the global variable directly. :slight_smile:

Sravya Batchu

You can use GlobalVariable.YourVar anywhere into the script, without the need to have an intermediate variable declared in the testcase.

The Globals are scoped, therefore visible to the test suite/test-collection, so to any test-case.

Sravya,

I was thinking if there is any way where the test object that is edited manually takes the value from the global variable directly.

Do you want something like this? — a Test Object which refers to a GlobalVariable directly from the property value:

No, this is not available.

KatalonDiscussion9786_TestObjectReferingToGlobalVariableDirectly.png

TestObjectWhichRefersGlobalVariable_clipped.png