@Test @RunAsClient public void test() { Warp.execute( new ClientAction() { @Override public void action() { browser.navigate().to(contextPath + "index.jsf"); } }) .verify(new InitialRequestVerification()); NameChangedToX x = Warp.execute( new ClientAction() { public void action() { WebElement nameInput = browser.findElement(By.id("helloWorldJsf:nameInput")); nameInput.sendKeys("X"); } }) .verify(new NameChangedToX()); // verify Object was Deserialized with Server state Assert.assertNotNull(x.getUpdatedName()); }
// @Test @InSequence(10) @RunAsClient public void testJsfAjaxClick() { // Navigate to page browser.navigate().to(context + "/faces/imageIT.xhtml"); Warp.initiate( new Activity() { public void perform() { guardAjax(image_id_3).click(); } }) .inspect( new Inspection() { private static final long serialVersionUID = 1L; @Inject ImageRequestBean imageRequestBean; @BeforePhase(Phase.INVOKE_APPLICATION) public void testBeforeAjax() { assertEquals(Boolean.FALSE, imageRequestBean.getAjaxCalled()); } @AfterPhase(Phase.INVOKE_APPLICATION) public void testAfterAjax() { assertEquals(Boolean.TRUE, imageRequestBean.getAjaxCalled()); } }); }
@Test public void testGlobalMessageIsIgnored() { Warp.initiate( new Activity() { @Override public void perform() { guardHttp(submitButton).click(); } }) .inspect( new AbstractComponentAssertion() { private static final long serialVersionUID = 1L; @BeforePhase(Phase.RENDER_RESPONSE) public void addGlobalMessage() { FacesContext context = FacesContext.getCurrentInstance(); context.addMessage(null, new FacesMessage("global message")); } @AfterPhase(Phase.RENDER_RESPONSE) public void verifyGlobalMessageIsIgnored() { FacesContext context = FacesContext.getCurrentInstance(); AbstractFocus component = bean.getComponent(); FocusRendererBase renderer = bean.getRenderer(); String candidates = renderer.getFocusCandidatesAsString(context, component); assertEquals("form", candidates); } }); assertEquals(input3, getFocusedElement()); }
@Test public void js_function_with_param() throws InterruptedException { // given browser.get(contextPath.toExternalForm() + "param.jsf"); Warp.initiate( new Activity() { public void perform() { Graphene.guardAjax(panel3).click(); } }) .group() .observe(request().uri().contains("param")) .inspect( new Inspection() { private static final long serialVersionUID = 1L; @Inject AjaxBean bean; @BeforePhase(Phase.INVOKE_APPLICATION) public void verify_param_not_yet_assigned() { Assert.assertEquals(0, bean.getLongValue()); } @AfterPhase(Phase.INVOKE_APPLICATION) public void verify_param_assigned() { Assert.assertEquals(3, bean.getLongValue()); } }) .execute(); }
@Test @Category(Failing.class) // RF-13165 public void row_click() throws InterruptedException { // given browser.get(contextPath.toExternalForm()); Warp.initiate( new Activity() { public void perform() { guardAjax(firstRow).click(); } }) .inspect( new Inspection() { private static final long serialVersionUID = 1L; @Inject IterationBean bean; @BeforePhase(Phase.INVOKE_APPLICATION) public void verify_param_not_yet_assigned() { Assert.assertEquals(null, bean.getNodeId()); } @AfterPhase(Phase.INVOKE_APPLICATION) public void verify_param_assigned() { Assert.assertEquals((Integer) 1, bean.getNodeId()); } }); }
@Test public void testValidateMultipleInputsDuringAjax() { Warp.initiate( new Activity() { public void perform() { guardXhr(ajaxButton).click(); } }) .inspect( new VerifyFocusCandidates( "First input should be focused", "form:input1 form:input2", "form:input1 form:input2")); assertEquals(input2, getFocusedElement()); }
@Test public void when_validation_group_is_set_then_bean_validator_should_not_be_used() throws InterruptedException { Warp.initiate( new Activity() { public void perform() { browser.get(contextPath.toExternalForm()); } }) .inspect( new Inspection() { private static final long serialVersionUID = 1L; @BeforeServlet public void setupGroup(GraphValidatorBean bean) { bean.setValidationGroups(new Class[] {MethodValidationGroup.class}); } }); guardAjax(applyChanges).click(); assertThat(inputTextMsg.getText(), equalTo("")); }
@Test public void test() { Warp.initiate( new Activity() { public void perform() { browser.navigate().to(contextPath + "index.html"); } }) .inspect( new Inspection() { private static final long serialVersionUID = 1L; @ArquillianResource HttpServletRequest request; @ArquillianResource HttpServletResponse response; @BeforeServlet public void beforeServlet() { System.out.println("Hi server, here is my initial request!"); assertNotNull( "request must be enriched", request.getHeader(WarpCommons.ENRICHMENT_REQUEST)); assertNotNull("request context must be available", request); assertNotNull( "responses enrichment is set before servlet processing", response.getHeader(WarpCommons.ENRICHMENT_RESPONSE)); } @AfterServlet public void afterServlet() { System.out.println("Servlet just processed my initial request!"); assertNotNull( "responses enrichment is set before servlet processing", response.getHeader(WarpCommons.ENRICHMENT_RESPONSE)); assertFalse( "some headers has been already set", response.getHeaderNames().isEmpty()); } }); Warp.initiate( new Activity() { public void perform() { browser.findElement(By.id("sendAjax")).click(); } }) .inspect( new Inspection() { private static final long serialVersionUID = 1L; @BeforeServlet public void beforeServlet() { System.out.println("Hi server, here is AJAX request!"); } }); }
@Test public void test() { Warp.execute( new ClientAction() { public void action() { browser.navigate().to(contextPath + "index.html"); } }) .filter(FaviconIgnore.class) .verify( new ServerAssertion() { private static final long serialVersionUID = 1L; @ArquillianResource HttpServletRequest request; @ArquillianResource HttpServletResponse response; @BeforeServlet public void beforeServlet() { System.out.println("Hi server, here is my initial request!"); assertNotNull( "request must be enriched", request.getHeader(WarpCommons.ENRICHMENT_REQUEST)); assertNotNull("request context must be available", request); assertNull( "response is not enriched before servlet processing", response.getHeader(WarpCommons.ENRICHMENT_RESPONSE)); } @AfterServlet public void afterServlet() { System.out.println("Servlet just processed my initial request!"); assertNull( "response still isn't senriched, that happens little bit later", response.getHeader(WarpCommons.ENRICHMENT_RESPONSE)); assertFalse( "some headers has been already set", response.getHeaderNames().isEmpty()); } }); Warp.execute( new ClientAction() { public void action() { browser.findElement(By.id("sendAjax")).click(); } }) .filter(FaviconIgnore.class) .verify( new ServerAssertion() { private static final long serialVersionUID = 1L; @BeforeServlet public void beforeServlet() { System.out.println("Hi server, here is AJAX request!"); } }); }