【问题标题】:Verify Backing Bean values using Arquillian Warp使用 Arquillian Warp 验证 Backing Bean 值
【发布时间】:2017-08-09 07:33:51
【问题描述】:

我的目标是使用 Arquillian Warp 进行测试

1。已经导航到上一个测试中的 JSF 页面

2。在另一个测试中,将文本字段设置为一个值,使用 warp 我需要注入 ViewScope Bean,并验证支持 bean 中的值

示例代码

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

我一直遇到的错误是

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)

欢迎任何帮助或在集成测试期间验证 jsf viewscope bean 的替代方法

【问题讨论】:

  • 尝试仅在 browserTest 上使用 @RunAsClient
  • 您是否尝试过使用 Postman 或 Chrome Dev Tools 运行以检查是否设置了此标头?
  • @lordofthejars 你能澄清哪些标题
  • 观察者没有匹配的请求 [containsHeader('faces-request')] 所以我想知道是否真的创建了 faces-request 标头
  • 已检查正常使用这些是 ajax 请求生成的标头 :authority:localhost:8080 :method:POST :path:/citi/demo/home :scheme:https accept:application/xml,文本/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:localhost:8080referer:localhost:8080/citi/demo/home x-requested-with:XMLHttpRequest

标签: jsf-2 integration-testing jboss-arquillian wildfly-10


【解决方案1】:

如果有人遇到同样的问题,我能够解决它不起作用并且能够创建一个示例项目以供将来参考

Testing using arquillian warp example

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多