1

My goal is to test using Arquillian Warp

1. Already navigated to a JSF page on a previous test

2. On a another test set a text field to a value, using warp i need to inject the ViewScope Bean , and verify the value in the backing bean

Sample Code

@RunWith(Arquillian.class)
@WarpTest
@RunAsClient
public class TestIT {

    private static final String WEBAPP_SRC = "src/main/webapp";
    private static final String WEB_INF_SRC = "src/main/webapp/WEB-INF";
    private static final String WEB_RESOURCES = "src/main/webapp/resources";

    @Deployment(testable = true)
    public static WebArchive createDeployment() {
        File[] files = Maven.resolver().loadPomFromFile("pom.xml")
                .importRuntimeDependencies().resolve().withTransitivity().asFile();

        WebArchive war = ShrinkWrap.create(WebArchive.class, "test.war")
                .addPackages(true, "com.mobitill")
                .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
                .addAsWebInfResource(new File(WEB_INF_SRC, "template.xhtml"))
                .addAsWebInfResource(new File(WEB_INF_SRC, "jboss-web.xml"))
                .addAsWebInfResource(new File(WEB_INF_SRC, "web.xml"))
                .addAsWebResource(new File(WEBAPP_SRC, "index.xhtml"))
                .addAsWebResource(new File("src/main/webapp/demo", "home.xhtml"), "demo/home.xhtml")
                .addAsResource("test-persistence.xml", "META-INF/persistence.xml")
                .merge(ShrinkWrap.create(GenericArchive.class).as(ExplodedImporter.class)
                        .importDirectory(WEB_RESOURCES).as(GenericArchive.class), "resources")
                .addAsLibraries(files);
        System.out.println(war.toString(true));
        return war;
    }
    @Drone
    private WebDriver browser;
    @ArquillianResource
    private URL deploymentUrl;

    @Test
    @InSequence(1)
    public final void browserTest() throws Exception {
        browser.get(deploymentUrl.toExternalForm() + "index");
        guardHttp(loginImage).click();
        Assert.assertEquals("navigate to home page ", "https://127.0.0.1:8080/citi/demo/home", browser.getCurrentUrl());
    }
    @Test
    @InSequence(2)
    public final void homeManagedBean() throws Exception {
        Warp
                .initiate(new Activity() {
                    @Override
                    public void perform() {
                        WebElement txtMerchantEmailAddress = browser.findElement(By.id("txtMerchantEmailAddress"));
                        txtMerchantEmailAddress.sendKeys("demouser@yahoo.com");
                        guardAjax(btnMerchantSave).click();
                    }
                })
                .observe(request().header().containsHeader("faces-request"))
                .inspect(new Inspection() {
                    private static final long serialVersionUID = 1L;

                    @Inject
                    HomeManagedBean hmb;

                    @ArquillianResource
                    FacesContext facesContext;

                    @BeforePhase(UPDATE_MODEL_VALUES)
                    public void initial_state_havent_changed_yet() {
                        Assert.assertEquals("email value ", "demouser@yahoo.com", hmb.getMerchantEmail());
                    }

                    @AfterPhase(UPDATE_MODEL_VALUES)
                    public void changed_input_value_has_been_applied() {
                        Assert.assertEquals(" email value ", "demouser@yahoo.com", hmb.getMerchantEmail());
                    }
                });
    }
}

the error i keep gettting is

org.jboss.arquillian.warp.impl.client.execution.WarpSynchronizationException: The Warp failed to observe requests or match them with response.

There were no requests matched by observer [containsHeader('faces-request')]

If Warp enriched a wrong request, use observe(...) method to select appropriate request which should be enriched instead.
Otherwise check the server-side log and enable Arquillian debugging mode on both, test and server VM by passing -Darquillian.debug=true.

    at org.jboss.arquillian.warp.impl.client.execution.SynchronizationPoint.awaitResponses(SynchronizationPoint.java:155)
    at org.jboss.arquillian.warp.impl.client.execution.DefaultExecutionSynchronizer.waitForResponse(DefaultExecutionSynchronizer.java:60)
    at org.jboss.arquillian.warp.impl.client.execution.WarpExecutionObserver.awaitResponse(WarpExecutionObserver.java:64)

any help will be welcomed or an alternative way of validating a jsf viewscope bean during integration testing

Francis
  • 603
  • 1
  • 6
  • 17
  • Try using `@RunAsClient` only on `browserTest`. – bartosz.majsak Aug 09 '17 at 21:24
  • Have you tried to run with Postman or with Chrome Dev Tools to check if there is this header set? – lordofthejars Aug 09 '17 at 21:31
  • @lordofthejars can you clarify which headers – Francis Aug 10 '17 at 15:03
  • There were no requests matched by observer [containsHeader('faces-request')] so I was wondering if faces-request header is really created – lordofthejars Aug 11 '17 at 07:32
  • have checked on normal use these are the headers generated on ajax request :authority:localhost:8080 :method:POST :path:/citi/demo/home :scheme:https accept:application/xml, text/xml, */*; q=0.01 accept-encoding:gzip, deflate, br accept-language:en-GB,en-US;q=0.8,en;q=0.6 content-length:474 content-type:application/x-www-form-urlencoded; charset=UTF-8 dnt:1 faces-request:partial/ajax origin:https://localhost:8080 referer:https://localhost:8080/citi/demo/home x-requested-with:XMLHttpRequest – Francis Aug 11 '17 at 08:37

1 Answers1

0

I was able to sort out it was not working and able to create a sample project for future reference if anyone comes by the same problem

Testing using arquillian warp example

Francis
  • 603
  • 1
  • 6
  • 17