TESTARtool / TESTAR_dev

TESTAR, automated testing through the Graphical User Interface
http://www.testar.org
BSD 3-Clause "New" or "Revised" License
37 stars 24 forks source link

[Refactor] Widget toString prints all children values instead of the current widget #384

Closed ferpasri closed 8 months ago

ferpasri commented 9 months ago

The Widget.toString(Tag<?>... tags) implementation for Windows, WebDriver, and Android is not just printing the current widget Tags description but also the tree descendents Tags description.

https://github.com/TESTARtool/TESTAR_dev/blob/f9c7019ec2af8a41afdd21300ad1bba0c3d76877/webdriver/src/org/testar/monkey/alayer/webdriver/WdWidget.java#L248-L250

https://github.com/TESTARtool/TESTAR_dev/blob/f9c7019ec2af8a41afdd21300ad1bba0c3d76877/core/src/org/testar/monkey/Util.java#L397-L412

Solution Create a new function in the Util class

public static String widgetDesc(Widget widget, Tag<?>... tags) {
    Assert.notNull(widget, tags);
    StringBuilder sb = new StringBuilder();
    for (Tag<?> t : tags) {
        sb.append(widget.get(t, null)).append(", ");
    }
    return sb.toString();
}

And use it by default in the Widget.toString(Tag<?>... tags) function.

@Override
public String toString(Tag<?>... tags){
    return Util.widgetDesc(this, tags);
}