为什么 JSF UI 组件没有显示在 Graphene WebDriver 测试浏览器实例中?
Why JSF UI components are not displayed in Graphene WebDriver test browser instance?
我想知道为什么我的 JSF 2.2 UI 输入组件没有在我的 Arquillian Drone Graphene WebDriver 的测试浏览器实例中呈现。我的测试页面如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Login</title>
</h:head>
<h:body>
<h:form id="loginForm">
<h3>Login Failure</h3>
<h:panelGrid columns="2">
<h:outputLabel for="username">Username:</h:outputLabel>
<h:inputText id="username"/>
<h:outputLabel for="password">Password:</h:outputLabel>
<h:inputSecret id="password" />
<h:commandButton id="login" value="Log in" />
</h:panelGrid>
</h:form>
</h:body>
</html>
而我的 Arquillian 无人机测试 Class 如下:
import java.io.File;
import java.io.Serializable;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.drone.api.annotation.Drone;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.Filters;
import org.jboss.shrinkwrap.api.GenericArchive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.importer.ExplodedImporter;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.primefaces.model.SortOrder;
------------
@RunWith(Arquillian.class)
public class ArquillianDroneTest {
@Drone
WebDriver browser;
@ArquillianResource
URL deploymentUrl;
private static final String WEBAPP_SRC = "src/main/webapp";
@Deployment(testable=false)
public static WebArchive createDeployment()
{
return ShrinkWrap.create(WebArchive.class,"mytestwar.war")
.addClass(TestEjb.class)
.addClass(ServiceFacade.class).addClass(ServiceQueryFacade.class).addClass(AbstractFacade.class)
.addClass(Service.class).addClass(AbstractLongPKEntity.class).addClass(AbstractEntity.class)
.addClass(PersistentEntity.class).addClass(Serializable.class).addClass(PersistentEntity.class)
.addClass(SortOrder.class)
.merge(ShrinkWrap.create(GenericArchive.class).as(ExplodedImporter.class)
.importDirectory(WEBAPP_SRC).as(GenericArchive.class),
"/", Filters.include(".*\.xhtml$"))
.addAsResource("test-persistence.xml", "META-INF/persistence.xml")
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
.addAsWebInfResource(new StringAsset("<faces-config version=\"2.0\"/>"),"faces-config.xml")
.addAsWebResource(new File(WEBAPP_SRC, "dos.xhtml"));
}
@Test
public void testUserLoginSuccess() {
browser.get(deploymentUrl.toExternalForm() + "/login.xhtml");
browser.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
WebElement textUserName=browser.findElement(By.id("username"));
textUserName.sendKeys("TestUSER");
}
}
所有这些结果(在 运行 maven 测试中)进入以下 WebDriver 测试浏览器
为什么 JSF 未在此测试浏览器中呈现?
从@BalusC 的评论中,我找到了一条线索并解决了我的问题,即将生产 web.xml 或测试 web.xml 文件包含到测试 WAR 中。我只是在我的测试 class 中添加了我的产品 web.xml,它对我有用:
---------------
@Deployment(testable=false)
public static WebArchive createDeployment()
{
return ShrinkWrap.create(WebArchive.class,"mytestwar.war")
.addClass(TestEjb.class)
.addClass(ServiceFacade.class).addClass(ServiceQueryFacade.class).addClass(AbstractFacade.class)
.addClass(Service.class).addClass(AbstractLongPKEntity.class).addClass(AbstractEntity.class)
.addClass(PersistentEntity.class).addClass(Serializable.class).addClass(PersistentEntity.class)
.addClass(SortOrder.class)
.merge(ShrinkWrap.create(GenericArchive.class).as(ExplodedImporter.class)
.importDirectory(WEBAPP_SRC).as(GenericArchive.class),
"/",Filters.include(".*\.(jsf|xhtml|html|css|js|png|jpg|xml)$"))
.addAsResource("test-persistence.xml", "META-INF/persistence.xml")
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
.addAsWebInfResource(new File(WEBAPP_SRC,"WEB-INF/faces-config.xml"))
.setWebXML(new File(WEBAPP_SRC,"WEB-INF/web.xml"))
.addAsWebResource(new File(WEBAPP_SRC, "dos.xhtml"));
}
----------------------------
我想知道为什么我的 JSF 2.2 UI 输入组件没有在我的 Arquillian Drone Graphene WebDriver 的测试浏览器实例中呈现。我的测试页面如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Login</title>
</h:head>
<h:body>
<h:form id="loginForm">
<h3>Login Failure</h3>
<h:panelGrid columns="2">
<h:outputLabel for="username">Username:</h:outputLabel>
<h:inputText id="username"/>
<h:outputLabel for="password">Password:</h:outputLabel>
<h:inputSecret id="password" />
<h:commandButton id="login" value="Log in" />
</h:panelGrid>
</h:form>
</h:body>
</html>
而我的 Arquillian 无人机测试 Class 如下:
import java.io.File;
import java.io.Serializable;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.drone.api.annotation.Drone;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.Filters;
import org.jboss.shrinkwrap.api.GenericArchive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.importer.ExplodedImporter;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.primefaces.model.SortOrder;
------------
@RunWith(Arquillian.class)
public class ArquillianDroneTest {
@Drone
WebDriver browser;
@ArquillianResource
URL deploymentUrl;
private static final String WEBAPP_SRC = "src/main/webapp";
@Deployment(testable=false)
public static WebArchive createDeployment()
{
return ShrinkWrap.create(WebArchive.class,"mytestwar.war")
.addClass(TestEjb.class)
.addClass(ServiceFacade.class).addClass(ServiceQueryFacade.class).addClass(AbstractFacade.class)
.addClass(Service.class).addClass(AbstractLongPKEntity.class).addClass(AbstractEntity.class)
.addClass(PersistentEntity.class).addClass(Serializable.class).addClass(PersistentEntity.class)
.addClass(SortOrder.class)
.merge(ShrinkWrap.create(GenericArchive.class).as(ExplodedImporter.class)
.importDirectory(WEBAPP_SRC).as(GenericArchive.class),
"/", Filters.include(".*\.xhtml$"))
.addAsResource("test-persistence.xml", "META-INF/persistence.xml")
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
.addAsWebInfResource(new StringAsset("<faces-config version=\"2.0\"/>"),"faces-config.xml")
.addAsWebResource(new File(WEBAPP_SRC, "dos.xhtml"));
}
@Test
public void testUserLoginSuccess() {
browser.get(deploymentUrl.toExternalForm() + "/login.xhtml");
browser.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
WebElement textUserName=browser.findElement(By.id("username"));
textUserName.sendKeys("TestUSER");
}
}
所有这些结果(在 运行 maven 测试中)进入以下 WebDriver 测试浏览器
为什么 JSF 未在此测试浏览器中呈现?
从@BalusC 的评论中,我找到了一条线索并解决了我的问题,即将生产 web.xml 或测试 web.xml 文件包含到测试 WAR 中。我只是在我的测试 class 中添加了我的产品 web.xml,它对我有用:
---------------
@Deployment(testable=false)
public static WebArchive createDeployment()
{
return ShrinkWrap.create(WebArchive.class,"mytestwar.war")
.addClass(TestEjb.class)
.addClass(ServiceFacade.class).addClass(ServiceQueryFacade.class).addClass(AbstractFacade.class)
.addClass(Service.class).addClass(AbstractLongPKEntity.class).addClass(AbstractEntity.class)
.addClass(PersistentEntity.class).addClass(Serializable.class).addClass(PersistentEntity.class)
.addClass(SortOrder.class)
.merge(ShrinkWrap.create(GenericArchive.class).as(ExplodedImporter.class)
.importDirectory(WEBAPP_SRC).as(GenericArchive.class),
"/",Filters.include(".*\.(jsf|xhtml|html|css|js|png|jpg|xml)$"))
.addAsResource("test-persistence.xml", "META-INF/persistence.xml")
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
.addAsWebInfResource(new File(WEBAPP_SRC,"WEB-INF/faces-config.xml"))
.setWebXML(new File(WEBAPP_SRC,"WEB-INF/web.xml"))
.addAsWebResource(new File(WEBAPP_SRC, "dos.xhtml"));
}
----------------------------