Can I parameterize a part of test object resource-id

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

Hi!
Are there any changes a few months later? Can I directly set the Global variable into TestObject property’s value (something mentioned above)?

I am not sure.

@devalex88, @ThanhTo ?

1 Like

@kazurayam I faced exactly the same use-case as a topic-starter. I have 3 applications to run Katalon-tests with. All these applications is basically copy-pasted from the main one, so my test-scripts can be run for each of 3 apps. But package name for each of them differs. All my test object were created by “Spy Mobile” option and (I don’t know why(!!!)) “resource-id” parameter always begins with “packageName” of the app. So I have the same objects to deal with (tap for example) but these objects do have different values in “resource-id” parameter, therefore I cannot interact with these object as it is.
Example:

  • first app “resource-id” = myAppName1:/login
  • second app “resource-id” = myAppName2:/login
  • third app “resource-id” = myAppName3:/login

Currently I cannot run my tests for all my apps. So I decided to edit all “resource-id” parameter’s values during test execution as described above. I set variables to all my “resource-id” related objects quickly with search-replace Katalon option, but now I need to adjust all my “resource-id” related test-steps
I need to change
Mobile.tap(findTestObject(‘Welcome_Login button’), 0)
to
Mobile.tap(findTestObject(‘Welcome_Login button’, [(‘packageName’): GlobalVariable.G_packageName]), 0)
And I am afraid I need to change it manually (:sob::sob::sob::sob::sob:)
I have about 300 places to modify and it requires a lot of time, this is a big “monkey job”.
Is there a quick way yo do so? Thanks a lot.

@dmitriynikityuk

Katalon Studio v6.3.0 introduced an improvement

Does it help?

Partially yes, thanks!
Can I use the same approach in my Keywords methods?
I mean can I use
Mobile.tap(findTestObject(‘MyTestObject’, [(‘packageName’): GlobalVariable.G_packageName]), 0)
in my CustomKeywords.‘com.android.MobileKW.swipeTo’() method?

I think it would work. Just try it.

Can I use the same approach in my Keywords methods?

I will rather write the keyword with a String parameter and pass the Global as parameter to the method when calling it from the testcase.

This way your keyword code will be reusable, I tend to avoid hardcodings as much as possible.

I fact, to add more flexibility i will do such design:

  • the keyword takes the needed value as a string parameter
  • i declare a variable in the testcase mapped to the needed global
  • i call the method from the testcase using the testcase variable

With such design you have the possibility to override the value passed to the keyword by 3 means: from the global value, modifying the variable in the testcase or simply calling the keyword with a fixed value

and if the testcase variable is not local (declared in the code) but you create it using the variables tab, it will be visible to other testcases too. so you can override the passed value by calling the testcase from another testcase using parameters mapping.

Hi,

I have the same problem here… to do a work around I did a copy of my project and I tried using powershell to do a find and replace in all *.rs files the resourceid with the other one but now all the object that had a change in them are not available in Katalon??? how come, is there a way to get back the objects after a change done in the files when not using Katalon to do it?

Hi all,

I found why katalon was not recognizing my objects… powershell was changing the encoding from UTF-8 to UTF16 LE BOM… So a quick way to duplicate your project with another package name in Powershell, create a copy of your project and run this script:

$exclude = @(“log”, “bak”)
$files = Get-ChildItem -Path “D:\projectCopy
Path*.rs” -Recurse -exclude $exclude

foreach ($file in $files){

$find = “packageName1”
$replace = “packageName2”
$content = Get-Content $($file.FullName) -Raw
#write replaced content back to the file

$content -replace $find,$replace | Out-File -Encoding utf8 $($file.FullName)

I found a way to change the resource-id everywhere to put the globalvariable for packagename but then you need to add the parameter in your test cases…

$exclude = @(“log”, “bak”)

$files = Get-ChildItem -Path “D:\temp*.rs” -Recurse -exclude $exclude

foreach ($file in $files)
{

$find1 = "@resource-id = packageName:id/"
$replace1 = "@resource-id =  '`${GlobalVariable.packageName}:id/"
$find2 = "<value>packageName:id/"
$replace2 = "<value>`${GlobalVariable.packageName}:id/"

$content = Get-Content $($file.FullName) -Raw

If($content.Contains($find1))
{
    $content | ForEach-Object {

    $_ -replace $find1,$replace1 `
     -replace $find2,$replace2 

     }| Out-File -Encoding utf8 $($file.FullName)

}

}

1 Like

iam new on automation with this tools
how to use this script ?
on testcase or what else ?
can you help me.

thanks.

@rahman.darmawan start from here:

@Ibus thanks for responds.
fundamental about katalon iam done to read, but i want to ask about script @jtheoret how to use
couse i dont want to replace manually all object :sweat_smile:

@kazurayam
Anyone to help about this ?