Changing the object properties during runtime

Hello ,

I’m trying to control slider using SetSliderValue but i failed, In my case the Object property X varies from 619 to 1433. Can i set a variable as object property so that i can change X value to (x+200) using loops.

Or is there any other alternative.

image.png

As far as I know, you can not change (= overwrite) the value of properties of a TestObject during a TestCase running.

You can org.openqa.selenium.WebElement and org.openqa.selenium.By in Katalon Studio, over which you would have minute control. Why not you use them instead?

I have got an alternative idea.

Your test case script can create a new instance of TestObect, which has no property defined, on the fly.

TestObject newObj = new TestObject()

You can read properties of an existing TestObject instance and copy them into your new one by addProperty(name, condition, value, active) while modifying the X property as you want.

TestObject original = findTestObject("Object Repository/foo/bar")
List<TestObjectProperty> lst = original.getActiveProperties()
for (TestObjectProperty top : lst) {
    if (top.getName().equals("x")) {
        // set x newObj with x property as you like
    } else {
       newObj.addProperty(top.getName(), top.getCondition(), top.getValue(), top.isActive())
    }
}
// use newObj with new X value

It would be better to create a Custom Keyword which encloses the above “cloning TestObject” functionality.

Hi kazurayam,

Can you explain me in detail.

I’m not able to run the code because its giving error at List

Capture.PNG

I’m not able to run the code because its giving error at List

Any error message?

Do you have import statement for TestObjectProperty class?

import com.kms.katalon.core.testobject.TestObjectProperty

Hi Kazurayam,

Yes, I imported the class.

Groovy will not like a variable name “1st” because it starts with numeric character. Change it to “first”.

Hi,

This is the script code i have written, But it does nothing.

TestObject newObj = new TestObject()TestObject dimmer = findTestObject("Object Repository/Dimming/Dim level 2")List<TestObjectProperty> first = dimmer.getActiveProperties()for (TestObjectProperty top : first) {	if (top.getName().equals("x")) {			                 x = 1003	} else {	   newObj.addProperty(top.getName(), top.getCondition(), top.getValue(), top.isActive())	}}

for (TestObjectProperty top : first) {    if (top.getName().equals("x")) {        newObj.addProperty("x", top.getCondition(), 1003, top.isActive())    } else {        newObj.addProperty(top.getName(), top.getCondition(), top.getValue(), top.isActive())    }}

The TestCase is throwing error

11-02-2018 10:38:18 AM - [ERROR]  - Test Cases/mytest/Dimming FAILED because (of) (Stack trace: groovy.lang.MissingMethodException: No signature of method: com.kms.katalon.core.testobject.TestObject.addProperty() is applicable for argument types: (java.lang.String, com.kms.katalon.core.testobject.ConditionType, java.lang.Integer, java.lang.Boolean) values: [x, equals, 1003, true]Possible solutions: addProperty(java.lang.String, com.kms.katalon.core.testobject.ConditionType, java.lang.String, boolean), addProperty(java.lang.String, com.kms.katalon.core.testobject.ConditionType, java.lang.String), addProperty(com.kms.katalon.core.testobject.TestObjectProperty)	

enclose the value in quotation marks:

        newObj.addProperty("x", top.getCondition(), "1003", top.isActive())

I tried the same it got executed, but when i checked for x value of newObj using println its giving me the current value of the slider.

TestObject newObj = new TestObject()TestObject dimmer = findTestObject("Object Repository/Dimming/Dim level 2")List<TestObjectProperty> first = dimmer.getActiveProperties()for (TestObjectProperty top : first) {		if (top.getName().equals("x")) {					        newObj.addProperty("x", top.getCondition(), "1003", top.isActive())	} else {	   newObj.addProperty(top.getName(), top.getCondition(), top.getValue(), top.isActive())	}}def value = Mobile.getAttribute(newObj, "x", 0)	println(value)

11-02-2018 10:59:41 AM - [PASSED] - Element '' has attribute 'x' is '1034'11-02-2018 10:59:41 AM - [END]    - End action : Statement - value = com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords.getAttribute(newObj, "x", 0)11-02-2018 10:59:41 AM - [START]  - Start action : Statement - println(value)103411-02-2018 10:59:41 AM - [END]    - End action : Statement - println(value)

Wait.

The title of the post

changing the object properties during runtime

was misleading.

In the initial post you said

In my case the Object property X varies from 619 to 1433.

What do you think the property ‘x’ stands for? Do you think ‘x’ represents the current position of moving slider meter?

I don’t think ‘x’ presents the position of the meter which moves horizontally. I think ‘x’ represents the (x,y) position of the upper left point of the Slider object, which is fixed, never changes.

Creating a new TestObject (which I happened to mention) is totally useless. You need to use Mobile.SetSliderValue() keyword appropriately.

I’m trying to control slider using SetSliderValue but i failed,

What error did you got?

Hi,

My issue is like the slider i got is not seekbar, and i not sure how they defined this in app.
The Minimum value (Slider at 0% ) of ‘x’ is '617" and Maximum value (Slider at 100%) is “1433” and the Max and Minimum values varies with respect to screen resolution.

Currently i’m using android emulator and i have got the above values for “X”.

I do not do Mobile testing myself. I am not able to reproduce your case on my side. I am not capable of helping you, sorry.

Ok,Thanks :slight_smile: