2017-08-09 189 views
0

我的目標是使用的Arquillian經測試驗證輔助Bean值使用的Arquillian經

1.已導航到JSF頁面上以前的測試

2.在另一個測試設置文本字段的值,使用經我需要注入ViewScope豆,並在支持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("[email protected]"); 
         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 ", "[email protected]", hmb.getMerchantEmail()); 
        } 

        @AfterPhase(UPDATE_MODEL_VALUES) 
        public void changed_input_value_has_been_applied() { 
         Assert.assertEquals(" email value ", "[email protected]", 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豆的另一種方式

+0

嘗試使用'@ RunAsClient'只'browserTest'。 –

+0

您是否嘗試使用郵遞員或Chrome開發工具運行以檢查是否存在此標頭集? – lordofthejars

+0

@lordofthejars你能澄清哪些頭文件 – Francis

回答