diff --git a/src/main/java/org/htmlunit/html/HtmlDomTreeWalker.java b/src/main/java/org/htmlunit/html/HtmlDomTreeWalker.java index 594a3dc760..e2db02a441 100644 --- a/src/main/java/org/htmlunit/html/HtmlDomTreeWalker.java +++ b/src/main/java/org/htmlunit/html/HtmlDomTreeWalker.java @@ -14,6 +14,8 @@ */ package org.htmlunit.html; +import java.io.Serializable; + import org.w3c.dom.DOMException; import org.w3c.dom.Node; import org.w3c.dom.traversal.NodeFilter; @@ -30,7 +32,7 @@ * @author Ahmed Ashour * @author Ronald Brill */ -public class HtmlDomTreeWalker { +public class HtmlDomTreeWalker implements Serializable { private final DomNode root_; private DomNode currentNode_; diff --git a/src/test/java/org/htmlunit/html/HtmlDomTreeWalkerTest.java b/src/test/java/org/htmlunit/html/HtmlDomTreeWalkerTest.java new file mode 100644 index 0000000000..42223a6313 --- /dev/null +++ b/src/test/java/org/htmlunit/html/HtmlDomTreeWalkerTest.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2002-2025 Gargoyle Software Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.htmlunit.html; + +import org.apache.commons.lang3.SerializationUtils; +import org.htmlunit.SimpleWebTestCase; +import org.htmlunit.junit.BrowserRunner; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * Tests for {@link HtmlDomTreeWalker}. + * + * @author Ronald Brill + */ +@RunWith(BrowserRunner.class) +public class HtmlDomTreeWalkerTest extends SimpleWebTestCase { + + /** + * @throws Exception if an error occurs + */ + @Test + public void serialization() throws Exception { + final String html = "\n" + + "
1
2
\n" + + ""; + + final HtmlPage page = loadPage(html); + + final byte[] bytes = SerializationUtils.serialize(new HtmlDomTreeWalker(page.getBody(), 0, null, false)); + + final HtmlDomTreeWalker deserialized = (HtmlDomTreeWalker) SerializationUtils.deserialize(bytes); + Assert.assertEquals(page.getBody().getNodeName(), deserialized.getRoot().getNodeName()); + } +}