• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hazendaz / httpunit / 755

14 Feb 2026 07:14PM UTC coverage: 80.526%. Remained the same
755

push

github

hazendaz
[ci] Fix badge

3213 of 4105 branches covered (78.27%)

Branch coverage included in aggregate %.

8245 of 10124 relevant lines covered (81.44%)

0.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

59.57
/src/main/java/com/meterware/httpunit/HTMLElementBase.java
1
/*
2
 * SPDX-License-Identifier: MIT
3
 * See LICENSE file for details.
4
 *
5
 * Copyright 2000-2026 Russell Gold
6
 * Copyright 2021-2000 hazendaz
7
 */
8
package com.meterware.httpunit;
9

10
import com.meterware.httpunit.scripting.ScriptableDelegate;
11
import com.meterware.httpunit.scripting.ScriptingHandler;
12

13
import java.util.HashSet;
14
import java.util.Set;
15

16
import org.w3c.dom.Node;
17

18
/**
19
 * The Class HTMLElementBase.
20
 */
21
abstract class HTMLElementBase implements HTMLElement {
22

23
    /** The node. */
24
    private Node _node;
25

26
    /** The scriptable. */
27
    private ScriptingHandler _scriptable;
28

29
    /** The supported attributes. */
30
    private Set _supportedAttributes = new HashSet<>();
1✔
31

32
    @Override
33
    public String getID() {
34
        return getAttribute("id");
1✔
35
    }
36

37
    @Override
38
    public String getClassName() {
39
        return getAttribute("class");
1✔
40
    }
41

42
    @Override
43
    public String getTitle() {
44
        return getAttribute("title");
1✔
45
    }
46

47
    @Override
48
    public String getName() {
49
        return getAttribute("name");
1✔
50
    }
51

52
    /**
53
     * Returns a scriptable object which can act as a proxy for this control.
54
     */
55
    @Override
56
    public ScriptingHandler getScriptingHandler() {
57
        if (_scriptable == null) {
1✔
58
            _scriptable = HttpUnitOptions.getScriptingEngine().createHandler(this);
1✔
59
        }
60
        return _scriptable;
1✔
61
    }
62

63
    /**
64
     * handle the event that has the given script attached by compiling the eventScript as a function and executing it
65
     *
66
     * @param eventScript
67
     *            - the script to use
68
     *
69
     * @deprecated since 1.7 - use doEventScript instead
70
     */
71
    @Deprecated
72
    @Override
73
    public boolean doEvent(String eventScript) {
74
        return doEventScript(eventScript);
×
75
    }
76

77
    /**
78
     * optional do the event if it's defined
79
     */
80
    @Override
81
    public boolean doEventScript(String eventScript) {
82
        return this.getScriptingHandler().doEventScript(eventScript);
×
83
    }
84

85
    @Override
86
    public boolean handleEvent(String eventName) {
87
        return this.getScriptingHandler().handleEvent(eventName);
1✔
88
    }
89

90
    /**
91
     * Returns the text value of this block.
92
     */
93
    @Override
94
    public String getText() {
95
        if (_node == null) {
×
96
            return "";
×
97
        }
98
        if (_node.getNodeType() == Node.TEXT_NODE) {
×
99
            return _node.getNodeValue().trim();
×
100
        }
101
        if (!_node.hasChildNodes()) {
×
102
            return "";
×
103
        }
104
        return NodeUtils.asText(_node.getChildNodes()).trim();
×
105
    }
106

107
    @Override
108
    public String getTagName() {
109
        return _node.getNodeName();
1✔
110
    }
111

112
    /**
113
     * construct me from a node.
114
     *
115
     * @param node
116
     *            - the node to get me from
117
     */
118
    protected HTMLElementBase(Node node) {
1✔
119
        _node = node;
1✔
120
        // default attributes every html element can have
121
        supportAttribute("id");
1✔
122
        supportAttribute("class");
1✔
123
        supportAttribute("title");
1✔
124
        supportAttribute("name");
1✔
125
    }
1✔
126

127
    /**
128
     * get the Attribute with the given name - by delegating to NodeUtils
129
     *
130
     * @param name
131
     *            - the name of the attribute to get
132
     *
133
     * @return the attribute
134
     */
135
    @Override
136
    public String getAttribute(final String name) {
137
        return NodeUtils.getNodeAttribute(getNode(), name);
1✔
138
    }
139

140
    /**
141
     * set the Attribute with the given name - by delegating to NodeUtils
142
     *
143
     * @param name
144
     *            - the name of the attribute to set
145
     * @param value
146
     *            - the value to set
147
     */
148
    @Override
149
    public void setAttribute(final String name, final Object value) {
150
        NodeUtils.setNodeAttribute(getNode(), name, value == null ? null : value.toString());
1!
151
    }
1✔
152

153
    /**
154
     * remove the Attribute with the given name - by delegating to NodeUtils
155
     *
156
     * @param name
157
     *            - the name of the attribute to remove
158
     */
159
    @Override
160
    public void removeAttribute(final String name) {
161
        NodeUtils.removeNodeAttribute(getNode(), name);
×
162
    }
×
163

164
    @Override
165
    public boolean isSupportedAttribute(String name) {
166
        return _supportedAttributes.contains(name);
1✔
167
    }
168

169
    /**
170
     * Gets the attribute.
171
     *
172
     * @param name
173
     *            the name
174
     * @param defaultValue
175
     *            the default value
176
     *
177
     * @return the attribute
178
     */
179
    protected String getAttribute(final String name, String defaultValue) {
180
        return NodeUtils.getNodeAttribute(getNode(), name, defaultValue);
×
181
    }
182

183
    @Override
184
    public Node getNode() {
185
        return _node;
1✔
186
    }
187

188
    /**
189
     * Support attribute.
190
     *
191
     * @param name
192
     *            the name
193
     */
194
    protected void supportAttribute(String name) {
195
        _supportedAttributes.add(name);
1✔
196
    }
1✔
197

198
    /**
199
     * Creates and returns a scriptable object for this control. Subclasses should override this if they use a different
200
     * implementation of Scriptable.
201
     */
202
    @Override
203
    public ScriptableDelegate newScriptable() {
204
        return new HTMLElementScriptable(this);
1✔
205
    }
206

207
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc