有没有一种方法可以;解析";使用Play for Java查看html的各个部分?
我目前正在使用play测试页面渲染:有没有一种方法可以;解析";使用Play for Java查看html的各个部分?,java,testing,playframework-2.0,Java,Testing,Playframework 2.0,我目前正在使用play测试页面渲染: @Test public void renderUpdateUserPage() { Content html = update_user.render("Update User"); assertThat(contentType(html)).isEqualTo("text/html"); String htmlAsString = contentAsString(html); ass
@Test
public void renderUpdateUserPage() {
Content html = update_user.render("Update User");
assertThat(contentType(html)).isEqualTo("text/html");
String htmlAsString = contentAsString(html);
assertThat(htmlAsString).contains("Update User");
assertThat(contentAsString(html)).contains("<input type=\"text\" placeholder=\"First Name\" class=\"input-large\" id=\"firstName\" name=\"firstName\">");
assertThat(contentAsString(html)).contains("<input type=\"text\" placeholder=\"Last Name\" class=\"input-large\" id=\"lastName\" name=\"lastName\">");
assertThat(contentAsString(html)).contains("<input type=\"text\" placeholder=\"Email Address\" class=\"input-large\" id=\"email\" name=\"email\">");
}
@测试
公共无效renderUpdateUserPage(){
Content html=update_user.render(“更新用户”);
assertThat(contentType(html)).isEqualTo(“text/html”);
字符串htmlAsString=contentAsString(html);
包含(“更新用户”);
(contentAsString(html))包含(“”)的资产;
(contentAsString(html))包含(“”)的资产;
(contentAsString(html))包含(“”)的资产;
}
正如您在代码中看到的,我只是将html复制到
contains()
中。测试页面内容的更好方法是什么?我认为这种方法可能有点脆弱,因为即使是很小的布局更改也会导致测试失败。与其测试特定的DOM结构,不如尝试测试页面的行为,比如提交表单,看看会发生什么。有一个,你可以以此为起点,用Cucumber和Fluentlenium测试表单提交