|
30 | 30 |
|
31 | 31 | package org.testar.monkey.alayer.webdriver; |
32 | 32 |
|
| 33 | +import java.util.ArrayList; |
33 | 34 | import java.util.Arrays; |
| 35 | +import java.util.Collection; |
| 36 | +import java.util.Collections; |
34 | 37 | import java.util.List; |
| 38 | +import java.util.Objects; |
| 39 | +import java.util.stream.Collectors; |
35 | 40 |
|
36 | 41 | 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 | + } |
51 | 103 | } |
0 commit comments