用于组件的 Adobe AEM (Adobe Experience Manager) HTL2HTML
Adobe AEM (Adobe Experience Manager) HTL2HTML for components
Adobe AEM (Adobe Experience Manager) HTL2HTML编译测试
(AEM 6.1 即将迁移到 6.3)
我想从 HTL 组件自动生成 HTML
作为构建过程的一部分(使用默认/和自定义值)
所以我可以提供额外的自动化测试和质量保证。
即 HTML 验证和可访问性 QA。
是否有 java 调用或其他命令行工具可以为每个组件生成 html 片段或页面。
在调用时可以将其合并到构建过程中
mvn clean install -PautoInstallPackage
我考虑过使用 selenium 生成页面,但我怀疑这种方法速度慢且容易出错。
感谢您的帮助
麦克
您可以使用 SlingRequestProcessor 在服务器端获得呈现的 HTML。
来自@nateyolles blog post:
获取 Apache Sling 中资源的 HTML 标记。
@SlingServlet(paths={"/bin/foo"})
public class SlingResourceResolutionServlet extends SlingSafeMethodsServlet {
/** Service to process requests through Sling */
@Reference
private SlingRequestProcessor requestProcessor;
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
/* The resource path to resolve. Use any selectors or extension. */
String requestPath = "/content/myapp/us/en/index/jcr:content/myparsys/mycomponent_f93d.html";
/*
* Create a fake request and fake response. The response adds a method to make the HTML accessible.
* You need the following three files from Apache Sling:
*
* https://github.com/apache/sling/blob/trunk/testing/junit/scriptable/src/main/java/org/apache/sling/junit/scriptable/HttpRequest.java
* https://github.com/apache/sling/blob/trunk/testing/junit/scriptable/src/main/java/org/apache/sling/junit/scriptable/HttpResponse.java
* https://github.com/apache/sling/blob/trunk/testing/junit/scriptable/src/main/java/org/apache/sling/junit/scriptable/TestServletOutputStream.java
*/
final HttpRequest req = new HttpRequest(requestPath);
final HttpResponse resp = new HttpResponse();
/* Process request through Sling */
requestProcessor.processRequest(req, resp, request.getResourceResolver());
String html = resp.getContent();
}
获取 AEM 中资源的 HTML 标记。
@SlingServlet(paths={"/bin/foo"})
public class AemResourceResolutionServlet extends SlingSafeMethodsServlet {
/** Service to create HTTP Servlet requests and responses */
@Reference
private RequestResponseFactory requestResponseFactory;
/** Service to process requests through Sling */
@Reference
private SlingRequestProcessor requestProcessor;
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
/* The resource path to resolve. Use any selectors or extension. */
String requestPath = "/content/myapp/us/en/index/jcr:content/myparsys/mycomponent_f93d.html";
/* Setup request */
HttpServletRequest req = requestResponseFactory.createRequest("GET", requestPath);
WCMMode.DISABLED.toRequest(req);
/* Setup response */
ByteArrayOutputStream out = new ByteArrayOutputStream();
HttpServletResponse resp = requestResponseFactory.createResponse(out);
/* Process request through Sling */
requestProcessor.processRequest(req, resp, request.getResourceResolver());
String html = out.toString();
}
}
Adobe AEM (Adobe Experience Manager) HTL2HTML编译测试 (AEM 6.1 即将迁移到 6.3)
我想从 HTL 组件自动生成 HTML 作为构建过程的一部分(使用默认/和自定义值) 所以我可以提供额外的自动化测试和质量保证。 即 HTML 验证和可访问性 QA。
是否有 java 调用或其他命令行工具可以为每个组件生成 html 片段或页面。 在调用时可以将其合并到构建过程中 mvn clean install -PautoInstallPackage
我考虑过使用 selenium 生成页面,但我怀疑这种方法速度慢且容易出错。
感谢您的帮助
麦克
您可以使用 SlingRequestProcessor 在服务器端获得呈现的 HTML。
来自@nateyolles blog post:
获取 Apache Sling 中资源的 HTML 标记。
@SlingServlet(paths={"/bin/foo"})
public class SlingResourceResolutionServlet extends SlingSafeMethodsServlet {
/** Service to process requests through Sling */
@Reference
private SlingRequestProcessor requestProcessor;
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
/* The resource path to resolve. Use any selectors or extension. */
String requestPath = "/content/myapp/us/en/index/jcr:content/myparsys/mycomponent_f93d.html";
/*
* Create a fake request and fake response. The response adds a method to make the HTML accessible.
* You need the following three files from Apache Sling:
*
* https://github.com/apache/sling/blob/trunk/testing/junit/scriptable/src/main/java/org/apache/sling/junit/scriptable/HttpRequest.java
* https://github.com/apache/sling/blob/trunk/testing/junit/scriptable/src/main/java/org/apache/sling/junit/scriptable/HttpResponse.java
* https://github.com/apache/sling/blob/trunk/testing/junit/scriptable/src/main/java/org/apache/sling/junit/scriptable/TestServletOutputStream.java
*/
final HttpRequest req = new HttpRequest(requestPath);
final HttpResponse resp = new HttpResponse();
/* Process request through Sling */
requestProcessor.processRequest(req, resp, request.getResourceResolver());
String html = resp.getContent();
}
获取 AEM 中资源的 HTML 标记。
@SlingServlet(paths={"/bin/foo"})
public class AemResourceResolutionServlet extends SlingSafeMethodsServlet {
/** Service to create HTTP Servlet requests and responses */
@Reference
private RequestResponseFactory requestResponseFactory;
/** Service to process requests through Sling */
@Reference
private SlingRequestProcessor requestProcessor;
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
/* The resource path to resolve. Use any selectors or extension. */
String requestPath = "/content/myapp/us/en/index/jcr:content/myparsys/mycomponent_f93d.html";
/* Setup request */
HttpServletRequest req = requestResponseFactory.createRequest("GET", requestPath);
WCMMode.DISABLED.toRequest(req);
/* Setup response */
ByteArrayOutputStream out = new ByteArrayOutputStream();
HttpServletResponse resp = requestResponseFactory.createResponse(out);
/* Process request through Sling */
requestProcessor.processRequest(req, resp, request.getResourceResolver());
String html = out.toString();
}
}