Skip to content

Commit ae364de

Browse files
1756 implement missing commands for uitoolkit (#1761)
* Added getAllVisualElementPropertyParams * Implement AltGetAllVisualElementsProperties * Fixed getAltVisualElementsProperties * Added WaitForVisualElementProperty * Implement AltWaitforVisualElementProperty * Fixed cSharp conflicts * Added command in python, java and robot * Added documentation * Fixed documentation and cSharp command * Fix lint problems * Fixed java syntax problems * fixed python errors
1 parent b7e5e2a commit ae364de

File tree

14 files changed

+577
-7
lines changed

14 files changed

+577
-7
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
Copyright(C) 2025 Altom Consulting
3+
4+
This program is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
This program is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
18+
using System;
19+
using System.Threading;
20+
using AltTester.AltTesterUnitySDK.Driver.Logging;
21+
using Newtonsoft.Json.Linq;
22+
23+
namespace AltTester.AltTesterUnitySDK.Driver.Commands
24+
{
25+
public class AltWaitForVisualElementProperty<T> : AltBaseFindObjects
26+
{
27+
readonly NLog.Logger logger = DriverLogManager.Instance.GetCurrentClassLogger();
28+
AltObject altObject;
29+
string propertyName;
30+
T propertyValue;
31+
bool getPropertyAsString;
32+
double timeout;
33+
double interval;
34+
35+
public AltWaitForVisualElementProperty(IDriverCommunication commHandler, string propertyName, T propertyValue, double timeout, double interval, bool getPropertyAsString, AltObject altObject) : base(commHandler)
36+
{
37+
this.altObject = altObject;
38+
this.propertyName = propertyName;
39+
this.propertyValue = propertyValue;
40+
this.timeout = timeout;
41+
this.interval = interval;
42+
this.getPropertyAsString = getPropertyAsString;
43+
if (timeout <= 0) throw new ArgumentOutOfRangeException("timeout");
44+
if (interval <= 0) throw new ArgumentOutOfRangeException("interval");
45+
}
46+
public T Execute()
47+
{
48+
double time = 0;
49+
string strPropertyValue = "";
50+
string propertyFoundString = "";
51+
while (time < timeout)
52+
{
53+
logger.Debug($"Waiting for property {propertyName} to be {propertyValue}.");
54+
T propertyFound = altObject.GetVisualElementProperty<T>(propertyName);
55+
if (propertyFound == null && propertyValue == null) //avoid null reference exception
56+
return propertyFound;
57+
if (!getPropertyAsString && propertyFound.Equals(propertyValue))
58+
return propertyFound;
59+
strPropertyValue = propertyValue.ToString() == "" ? "null" : propertyValue.ToString();
60+
JToken jTokenPropertyFound = propertyFound == null ? "null" : propertyFound as JToken;
61+
propertyFoundString = propertyFound.ToString();
62+
if (getPropertyAsString && jTokenPropertyFound.ToString().Equals(strPropertyValue))
63+
return propertyFound;
64+
65+
Thread.Sleep(System.Convert.ToInt32(interval * 1000));
66+
time += interval;
67+
}
68+
throw new WaitTimeOutException($"Property {propertyName} was {propertyFoundString} and was not {strPropertyValue} after {timeout} seconds");
69+
}
70+
}
71+
}

Assets/AltTester/Runtime/AltDriver/Commands/FindObjects/AltWaitForVisualElementProperty.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
Copyright(C) 2025 Altom Consulting
3+
4+
This program is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
This program is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
18+
using System.Collections.Generic;
19+
20+
namespace AltTester.AltTesterUnitySDK.Driver.Commands
21+
{
22+
public class AltGetAllVisualElementProperties : AltBaseCommand
23+
{
24+
AltGetAllVisualElementPropertyParams cmdParams;
25+
public AltGetAllVisualElementProperties(IDriverCommunication commHandler, AltObject altObject) : base(commHandler)
26+
{
27+
cmdParams = new AltGetAllVisualElementPropertyParams(altObject);
28+
}
29+
public Dictionary<string, object> Execute()
30+
{
31+
CommHandler.Send(cmdParams);
32+
return CommHandler.Recvall<Dictionary<string, object>>(cmdParams);
33+
}
34+
}
35+
}

Assets/AltTester/Runtime/AltDriver/Commands/ObjectCommands/AltGetAllVisualElementProperties.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/AltTester/Runtime/AltDriver/Commands/Parameters/CommandParams.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,16 @@ public AltGetVisualElementPropertyParams(AltObject altObject, string property) :
838838
this.property = property;
839839
}
840840

841+
}
842+
843+
[Command("getAllVisualElementProperty")]
844+
public class AltGetAllVisualElementPropertyParams : BaseAltObjectParams
845+
{
846+
847+
public AltGetAllVisualElementPropertyParams(AltObject altObject) : base(altObject)
848+
{
849+
}
850+
841851
}
842852
[Command("setVisualElementProperty")]
843853
public class AltSetVisualElementPropertyParams : BaseAltObjectParams

Assets/AltTester/Runtime/AltDriver/Common/AltObject.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ You should have received a copy of the GNU General Public License
1616
*/
1717

1818
using System;
19+
using System.Collections.Generic;
1920
using System.Threading;
2021
using AltTester.AltTesterUnitySDK.Driver.Commands;
2122

@@ -275,5 +276,26 @@ public T GetVisualElementProperty<T>(string propertyName)
275276
CommHandler.SleepFor(CommHandler.GetDelayAfterCommand());
276277
return propertyValue;
277278
}
279+
public T WaitForVisualElementProperty<T>(string propertyName, T propertyValue, double timeout = 20, double interval = 0.5, bool getPropertyAsString = false)
280+
{
281+
if (type != "UIToolkit")
282+
{
283+
throw new WrongAltObjectTypeException("This method is only available for VisualElement objects");
284+
}
285+
var value = new AltWaitForVisualElementProperty<T>(CommHandler, propertyName, propertyValue, timeout, interval, getPropertyAsString, this).Execute();
286+
CommHandler.SleepFor(CommHandler.GetDelayAfterCommand());
287+
return value;
288+
}
289+
public Dictionary<string, object> GetAllVisualElementProperties()
290+
{
291+
if (type != "UIToolkit")
292+
{
293+
throw new WrongAltObjectTypeException("This method is only available for VisualElement objects");
294+
}
295+
var propertyValue = new AltGetAllVisualElementProperties(CommHandler, this).Execute();
296+
CommHandler.SleepFor(CommHandler.GetDelayAfterCommand());
297+
return propertyValue;
298+
}
299+
278300
}
279301
}

Bindings~/java/src/main/java/com/alttester/AltObject.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import com.alttester.Commands.FindObject.AltFindObjectsParams;
3030
import com.alttester.Commands.FindObject.AltWaitForComponentProperty;
3131
import com.alttester.Commands.FindObject.AltWaitForComponentPropertyParams;
32+
import com.alttester.Commands.FindObject.AltWaitForVisualElementProperty;
33+
import com.alttester.Commands.FindObject.AltWaitForVisualElementPropertyParams;
3234
import com.alttester.Commands.FindObject.AltFindObject;
3335

3436
@Getter
@@ -378,7 +380,7 @@ private AltObject sendActionAndEvaluateResult(String command) {
378380
* @return The value of the specified property.
379381
* @throws WrongAltObjectTypeException if the object type is not "UIToolkit".
380382
*/
381-
public <T> T GetVisualElementProperty(String propertyName, Class<T> returnType) {
383+
public <T> T getVisualElementProperty(String propertyName, Class<T> returnType) {
382384
if (!type.equals("UIToolkit")) {
383385
throw new WrongAltObjectTypeException("This method is only available for VisualElement objects");
384386
}
@@ -391,4 +393,29 @@ public <T> T GetVisualElementProperty(String propertyName, Class<T> returnType)
391393
Utils.sleepFor(messageHandler.getDelayAfterCommand());
392394
return propertyValue;
393395
}
396+
397+
@Deprecated
398+
public <T> T GetVisualElementProperty(String propertyName, Class<T> returnType) {
399+
return getVisualElementProperty(propertyName, returnType);
400+
}
401+
402+
public <T> T waitForVisualElementProperty(
403+
AltWaitForVisualElementPropertyParams altWaitForVisualElementPropertyParams,
404+
T propertyValue,
405+
boolean getPropertyAsString,
406+
Class<T> returnType) {
407+
408+
if (!type.equals("UIToolkit")) {
409+
throw new WrongAltObjectTypeException("This method is only available for VisualElement objects");
410+
}
411+
412+
altWaitForVisualElementPropertyParams.setAltObject(this);
413+
T response = new AltWaitForVisualElementProperty<T>(messageHandler,
414+
altWaitForVisualElementPropertyParams,
415+
propertyValue, getPropertyAsString, this)
416+
.Execute(returnType);
417+
Utils.sleepFor(messageHandler.getDelayAfterCommand());
418+
return response;
419+
}
420+
394421
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
Copyright(C) 2025 Altom Consulting
3+
4+
This program is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
This program is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.alttester.Commands.FindObject;
19+
20+
import com.alttester.Utils;
21+
import com.alttester.Commands.ObjectCommand.AltGetComponentPropertyParams;
22+
import com.alttester.IMessageHandler;
23+
import com.alttester.AltObject;
24+
import com.alttester.altTesterExceptions.WaitTimeOutException;
25+
import com.google.gson.Gson;
26+
import com.google.gson.JsonArray;
27+
28+
/**
29+
* Wait until there are no longer any objects that respect the given criteria or
30+
* times run out and will throw an error.
31+
*/
32+
public class AltWaitForVisualElementProperty<T> extends AltBaseFindObject {
33+
/**
34+
* @param waitParams the properties parameter for waiting
35+
* the
36+
* object
37+
* @param altObject the AltObject element
38+
* @param property the wanted value of the property
39+
* @param getPropertyAsString if true compares the property's value and the
40+
* actual value as strings
41+
*/
42+
private AltObject altObject;
43+
private AltWaitForVisualElementPropertyParams waitParams;
44+
private T property;
45+
private Boolean getPropertyAsString = false;
46+
47+
/**
48+
* @param messageHandler
49+
* @param AltWaitForVisualElementPropertyParams
50+
*/
51+
public AltWaitForVisualElementProperty(IMessageHandler messageHandler,
52+
AltWaitForVisualElementPropertyParams AltWaitForVisualElementPropertyParams, T property,
53+
AltObject altObject) {
54+
super(messageHandler);
55+
this.waitParams = AltWaitForVisualElementPropertyParams;
56+
this.property = property;
57+
this.altObject = altObject;
58+
}
59+
60+
public AltWaitForVisualElementProperty(IMessageHandler messageHandler,
61+
AltWaitForVisualElementPropertyParams AltWaitForVisualElementPropertyParams, T property,
62+
Boolean getPropertyAsString, AltObject altObject) {
63+
super(messageHandler);
64+
this.waitParams = AltWaitForVisualElementPropertyParams;
65+
this.property = property;
66+
this.getPropertyAsString = getPropertyAsString;
67+
this.altObject = altObject;
68+
}
69+
70+
public T Execute(Class<T> returnType) {
71+
double time = 0;
72+
String jsonElementToString = "";
73+
String propertyName = waitParams.getPropertyName();
74+
while (time < waitParams.getTimeout()) {
75+
logger.debug("Waiting for element where name contains "
76+
+ propertyName + "....");
77+
T propertyFound = altObject.getVisualElementProperty(
78+
propertyName,
79+
returnType);
80+
if (!getPropertyAsString && propertyFound.equals(property))
81+
return propertyFound;
82+
if (!(propertyFound instanceof JsonArray)) {
83+
String str = new Gson().toJsonTree(propertyFound).toString();
84+
jsonElementToString = str.contains("\"") ? str : "\"" + str + "\"";
85+
} else {
86+
jsonElementToString = propertyFound.toString();
87+
}
88+
if (getPropertyAsString && jsonElementToString.equals(property.toString()))
89+
return propertyFound;
90+
91+
Utils.sleepFor(waitParams.getInterval());
92+
time += waitParams.getInterval();
93+
}
94+
throw new WaitTimeOutException(
95+
"Property " + propertyName
96+
+ " was " + jsonElementToString + " and was not " + property + " after "
97+
+ waitParams.getTimeout()
98+
+ " seconds");
99+
}
100+
}

0 commit comments

Comments
 (0)