inputjsf-2.2arquillian-dronegraphene2

Why JSF UI components are not displayed in Graphene WebDriver test browser instance?


I wonder why my JSF 2.2 UI input components are not rendered in my Arquillian Drone Graphene WebDriver's test browser instance. My test page is as follows:

<?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>

And my Arquillian Drone Test Class is as follows:

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");


    }
}

And all this results (on running maven test) into following WebDriver test browser

enter image description here

Why JSF is not rendered in this test browser?


Solution

  • From comment by @BalusC, I found a clue and solved my problem i.e. inclusion of either production web.xml or testing web.xml file into test WAR. I simply added my production web.xml as follows in my test class and it worked for me:

    ---------------
     @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"));
        }
    ----------------------------