I am trying to use REST Assured to check some properties of an HTML document returned by my server. The SSCCE demonstrating the problem will be as follows:
import static com.jayway.restassured.path.xml.config.XmlPathConfig.xmlPathConfig; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; import org.junit.Test; import com.jayway.restassured.path.xml.XmlPath; public class HtmlDocumentTest { @Test public void titleShouldBeHelloWorld() { final XmlPath xml = new XmlPath("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">" + "<html xmlns=\"http://www.w3.org/1999/xhtml\">" + "<head><title>Hello world</title></head><body></body></html>") .using(xmlPathConfig().with().feature("http://apache.org/xml/features/disallow-doctype-decl", false)); assertThat(xml.get("//title[text()]"), is("Hello world")); } }
Now this attempt ends with com.jayway.restassured.path.xml.exception.XmlPathException: Failed to parse the XML document caused by disconnecting all possible errors, java.net.ConnectException: Connection timed out after about 30 seconds!
If I delete the line using xmlPathConfig().with().feature(...) , the test will immediately end due to DOCTYPE is disallowed when the feature "http://apache.org/xml/features/disallow-doctype-decl" set to true. .
If I delete the doctype line from the document, the parsing succeeds, but if the error says β Expected: is "Hello world" but: was <Hello worldnull> β however, another problem occurs (but feel free to give instructions for this, too...). And removing doctype is not an option for me anyway.
So the question is: how do you check the properties of an HTML document using doctype using REST Assured? The documentation states that "REST Assured providers are predefined by parsers such as HTML, XML, and JSON." , But I canβt find examples on how to activate and work with this HTML parser! There is no " HtmlPath " class, such as XmlPath , and this timeout exception is very puzzling ...
source share