citrusframework / citrusframework/citrus
Convert HTML to XHTML before XPath extractions are applied
- Dominant language
- Java
- Stars
- 485
- Forks
- 155
- Avg merge
- 4d 22h
- Merged PRs (30d)
- 6
Description
**User story**
As a Citrus user, I would like to use XPath extractions from HTML files and use the Citrus HTML to XHTML conversion feature implicitly, to be able to obtain variables from HTML payload.
**Actual behavior**
Currently the conversion from HTML to XHTML is done after the variable extraction. This is because one would like to use extracted variables for validation purposes.
**Additional information**
The idea is to decide whether the Message type is XHTML in the `XpathPayloadVariableExtractor` and convert HTML to XHTML if required. If the conversion is done in the `XpathPayloadVariableExtractor`, a additional conversion should be suppressed in the `XhtmlXpathMessageValidator`.
The class to use for conversion from HTML to XHTML is `XhtmlMessageConverter`.
Here is the test that should be successfull:
```java
@Test
@CitrusTest
public void testGet() {
http()
.client(httpClient)
.send()
.get("/")
.fork(true);
http()
.server(httpServer)
.receive()
.get("/");
http()
.server(httpServer)
.respond()
.messageType(MessageType.XHTML)
.payload(new ClassPathResource("/payload/website.html"));
http()
.client(httpClient)
.receive()
.response(HttpStatus.OK)
.messageType(MessageType.XHTML)
.extractFromPayload("//:html/:body/:div/:input/@value", "VALUE");
action(new AbstractTestAction() {
@Override
public void doExecute(final TestContext context) {
Assert.assertEquals(context.getVariable("VALUE"), "foobar");
}
});
}
```
Here is the HTML website located in `/payload/website.html`:
```html
```
Contributor guide
Assessment
This issue has not been assessed yet.