Skip to content

Commit ffcb2a1

Browse files
committed
Add settings to configure webdriver constants
1 parent 9fc8037 commit ffcb2a1

11 files changed

Lines changed: 247 additions & 20 deletions

File tree

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- Fix bug extracting the protocol name the .sse file
1111
- Ignore weak password chrome popup
1212
- Refactor usage of Tag ScreenshotImage
13+
- Add settings to configure webdriver constants
1314

1415

1516
#TESTAR 2.7.7 (26-Aug-2025)

testar/resources/workflow/settings/test_gradle_workflow_webdriver_parabank/Protocol_test_gradle_workflow_webdriver_parabank.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.testar.monkey.alayer.actions.AnnotatingActionCompiler;
3636
import org.testar.monkey.alayer.actions.StdActionCompiler;
3737
import org.testar.monkey.alayer.exceptions.ActionBuildException;
38+
import org.testar.monkey.alayer.webdriver.Constants;
3839
import org.testar.monkey.alayer.webdriver.enums.WdTags;
3940
import org.testar.monkey.ConfigTags;
4041
import org.testar.monkey.Main;
@@ -76,6 +77,12 @@ protected void initialize(Settings settings) {
7677
Assert.collectionSize(deniedExtensions, 5);
7778
Assert.isTrue(settings.get(ConfigTags.ClickableClasses).isEmpty());
7879
Assert.isTrue(settings.get(ConfigTags.TypeableClasses).isEmpty());
80+
81+
// WebDriver advanced state fetcher configuration verification
82+
Assert.isTrue(Constants.getHiddenTags().contains("canvas"));
83+
Assert.isTrue(Constants.getIgnoredTags().size() == 9);
84+
Assert.isTrue(Constants.getIgnoredTags().contains("iframe"));
85+
Assert.isTrue(Constants.getIgnoredAttributes().contains("xpath"));
7986
}
8087

8188
/**

testar/resources/workflow/settings/test_gradle_workflow_webdriver_parabank/test.settings

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ ProtocolClass = test_gradle_workflow_webdriver_parabank/Protocol_test_gradle_wor
107107
#################################################################
108108
AbstractStateAttributes = WebWidgetId
109109

110+
#################################################################
111+
# WebDriver advanced state fetcher configuration
112+
#################################################################
113+
WebIgnoredTags = script;noscript;head;meta;style;link;svg;canvas;iframe
114+
WebIgnoredAttributes = xpath
115+
110116
#################################################################
111117
# WebDriver features
112118
#################################################################

testar/src/org/testar/monkey/ConfigTags.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,14 @@ private ConfigTags() {}
176176
public static final Tag<Boolean> SwitchNewTabs = Tag.from("SwitchNewTabs", Boolean.class,
177177
"Indicate if switch to a new web tab if opened");
178178

179+
@SuppressWarnings("unchecked")
180+
public static final Tag<List<String>> WebIgnoredTags = Tag.from("WebIgnoredTags", (Class<List<String>>) (Class<?>) List.class,
181+
"List of HTML tags that TESTAR should ignore when obtaining the web state");
182+
183+
@SuppressWarnings("unchecked")
184+
public static final Tag<List<String>> WebIgnoredAttributes = Tag.from("WebIgnoredAttributes", (Class<List<String>>) (Class<?>) List.class,
185+
"List of web attributes that TESTAR should ignore when obtaining the web state (e.g., to reduce state high-performance workloads)");
186+
179187
public static final Tag<Boolean> WebConsoleErrorOracle = Tag.from("WebConsoleErrorOracle", Boolean.class,
180188
"Enable or Disable applying ORACLES to the browser error console");
181189

testar/src/org/testar/protocols/WebdriverProtocol.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/***************************************************************************************************
22
*
3-
* Copyright (c) 2019 - 2023 Universitat Politecnica de Valencia - www.upv.es
4-
* Copyright (c) 2019 - 2023 Open Universiteit - www.ou.nl
3+
* Copyright (c) 2019 - 2025 Universitat Politecnica de Valencia - www.upv.es
4+
* Copyright (c) 2019 - 2025 Open Universiteit - www.ou.nl
55
*
66
* Redistribution and use in source and binary forms, with or without
77
* modification, are permitted provided that the following conditions are met:
@@ -45,6 +45,7 @@
4545
import org.testar.monkey.alayer.webdriver.WdDriver;
4646
import org.testar.monkey.alayer.webdriver.WdElement;
4747
import org.testar.monkey.alayer.webdriver.WdWidget;
48+
import org.testar.monkey.alayer.webdriver.Constants;
4849
import org.testar.monkey.alayer.webdriver.enums.WdRoles;
4950
import org.testar.monkey.alayer.webdriver.enums.WdTags;
5051
import org.testar.monkey.alayer.windows.WinProcess;
@@ -132,6 +133,12 @@ protected void initialize(Settings settings){
132133
//Force webdriver to switch to a new tab if opened
133134
//This feature can block the correct display of select dropdown elements
134135
WdDriver.forceActivateTab = settings.get(ConfigTags.SwitchNewTabs);
136+
137+
// List of HTML tags that TESTAR should ignore when obtaining the web state
138+
Constants.setIgnoredTags(settings.get(ConfigTags.WebIgnoredTags));
139+
140+
// List of web attributes that TESTAR should ignore when obtaining the web state
141+
Constants.setIgnoredAttributes(settings.get(ConfigTags.WebIgnoredAttributes));
135142
}
136143

137144
/**

testar/src/org/testar/settings/SettingsDefaults.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,25 @@ private SettingsDefaults() {}
160160
defaults.add(Pair.from(BrowserFullScreen, true));
161161
defaults.add(Pair.from(SwitchNewTabs, true));
162162

163+
defaults.add(Pair.from(WebIgnoredTags, new ArrayList<String>() {
164+
{
165+
add("script");
166+
add("noscript");
167+
add("head");
168+
add("meta");
169+
add("style");
170+
add("link");
171+
add("svg");
172+
add("canvas");
173+
}
174+
}));
175+
176+
defaults.add(Pair.from(WebIgnoredAttributes, new ArrayList<String>() {
177+
{
178+
add("xpath");
179+
}
180+
}));
181+
163182
/*
164183
//TODO web driver settings for login feature
165184
defaults.add(Pair.from(Login, null)); // null = feature not enabled

testar/src/org/testar/settings/SettingsFileStructure.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,16 @@ public static String getTestSettingsStructure() {
280280
, ConfigTags.SwitchNewTabs.name() + " = "
281281
, ""
282282
, "#################################################################"
283+
, "# WebDriver advanced state fetcher configuration"
284+
, "#"
285+
, "# WebIgnoredTags: " + ConfigTags.WebIgnoredTags.getDescription()
286+
, "# WebIgnoredAttributes: " + ConfigTags.WebIgnoredAttributes.getDescription()
287+
, "#################################################################"
288+
, ""
289+
, ConfigTags.WebIgnoredTags.name() + " = "
290+
, ConfigTags.WebIgnoredAttributes.name() + " = "
291+
, ""
292+
, "#################################################################"
283293
, "# WebDriver Browser Console Oracles"
284294
, "#"
285295
, "# WebConsoleErrorOracle: " + ConfigTags.WebConsoleErrorOracle.getDescription()

webdriver/src/org/testar/monkey/alayer/webdriver/Constants.java

Lines changed: 66 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,74 @@
3030

3131
package org.testar.monkey.alayer.webdriver;
3232

33+
import java.util.ArrayList;
3334
import java.util.Arrays;
35+
import java.util.Collection;
36+
import java.util.Collections;
3437
import java.util.List;
38+
import java.util.Objects;
39+
import java.util.stream.Collectors;
3540

3641
public class Constants {
37-
// List of HTML tags that getStateTreeTestar should ignore
38-
// no widgets can be found here
39-
public static List<String> ignoredTags = Arrays.asList(
40-
"script", "noscript", "head", "meta", "style", "link", "svg", "canvas");
41-
// Disable the state-canvas
42-
public static List<String> hiddenTags = Arrays.asList("canvas");
43-
44-
// List of web attributes to ignore when obtaining the getStateTreeTestar
45-
// These can be ignored to reduce state high-performance workloads
46-
public static List<String> ignoredAttributes = Arrays.asList("xpath");
47-
48-
// element.offsetWidth - element.clientWidth
49-
public static double scrollArrowSize = 36;
50-
public static double scrollThick = 15;
42+
43+
private Constants() {}
44+
45+
// List of default HTML tags that getStateTreeTestar should ignore
46+
// no widgets can be found here
47+
// this list can be updated by users using the "WebIgnoredTags" setting
48+
private static List<String> ignoredTags = Collections.emptyList();
49+
50+
public static List<String> getIgnoredTags() {
51+
return Collections.unmodifiableList(ignoredTags);
52+
}
53+
54+
public static void setIgnoredTags(Collection<String> values) {
55+
ignoredTags = sanitize(values);
56+
}
57+
58+
// List of default web attributes to ignore when obtaining the getStateTreeTestar
59+
// These can be ignored to reduce state high-performance workloads
60+
// based on "webdriver/resources/web-extension/js/testar.state.js"
61+
// this list can be updated by users using the "WebIgnoredAttributes" setting
62+
private static List<String> ignoredAttributes = Collections.emptyList();
63+
64+
public static List<String> getIgnoredAttributes() {
65+
return Collections.unmodifiableList(ignoredAttributes);
66+
}
67+
68+
public static void setIgnoredAttributes(Collection<String> values) {
69+
ignoredAttributes = sanitize(values);
70+
}
71+
72+
// Disable the state-canvas
73+
private static List<String> hiddenTags = new ArrayList<>(Arrays.asList("canvas"));
74+
75+
public static List<String> getHiddenTags() {
76+
return Collections.unmodifiableList(hiddenTags);
77+
}
78+
79+
// element.offsetWidth - element.clientWidth
80+
public static double scrollArrowSize = 36;
81+
public static double scrollThick = 15;
82+
83+
/**
84+
* Sanitize a collection of strings:
85+
* - null returns empty list
86+
* - trims, removes nulls/blanks
87+
* - deduplicates preserving order
88+
*/
89+
private static List<String> sanitize(Collection<String> input) {
90+
if (input == null) {
91+
return Collections.emptyList();
92+
}
93+
94+
List<String> cleaned = input.stream()
95+
.filter(Objects::nonNull)
96+
.map(String::trim)
97+
.filter(s -> !s.isEmpty())
98+
.distinct()
99+
.collect(Collectors.toList());
100+
101+
return cleaned.isEmpty() ? Collections.emptyList() : cleaned;
102+
}
51103
}

webdriver/src/org/testar/monkey/alayer/webdriver/WdElement.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public WdElement(Map<String, Object> packedElement, WdRootElement root, WdElemen
186186
isKeyboardFocusable = getIsFocusable();
187187
hasKeyboardFocus = (Boolean) packedElement.get("hasKeyboardFocus");
188188

189-
enabled = !Constants.hiddenTags.contains(tagName) && !disabled;
189+
enabled = !Constants.getHiddenTags().contains(tagName) && !disabled;
190190
if (display != null && display.toLowerCase().equals("none")) {
191191
enabled = false;
192192
}
@@ -195,8 +195,8 @@ public WdElement(Map<String, Object> packedElement, WdRootElement root, WdElemen
195195
(List<Map<String, Object>>) packedElement.get("wrappedChildren");
196196
for (Map<String, Object> wrappedChild : wrappedChildren) {
197197
WdElement child = new WdElement(wrappedChild, root, this);
198-
if (!Constants.hiddenTags.contains(child.tagName) &&
199-
!Constants.ignoredTags.contains(child.tagName)) {
198+
if (!Constants.getHiddenTags().contains(child.tagName) &&
199+
!Constants.getIgnoredTags().contains(child.tagName)) {
200200
children.add(child);
201201
}
202202
}

webdriver/src/org/testar/monkey/alayer/webdriver/WdStateFetcher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public WdStateFetcher(SUT system) {
5454
public static WdRootElement buildRoot(SUT system) throws StateBuildException {
5555
Object result = WdDriver.executeScript(
5656
"return getStateTreeTestar(arguments[0], arguments[1])",
57-
Constants.ignoredTags, Constants.ignoredAttributes);
57+
Constants.getIgnoredTags(), Constants.getIgnoredAttributes());
5858

5959
// TODO As Edge limits its recursion to 20, we need to flatten the tree in JS
6060
// And unflatten the list here into a nested Map (as produced by Chrome / FF)

0 commit comments

Comments
 (0)