/** {@link https://issues.jboss.org/browse/RF-12761} */ @Test @Category(Failing.class) public void listener_with_parameter() throws InterruptedException { // given browser.get(contextPath.toExternalForm()); WebElement button1 = browser.findElement(By.id("myForm:jsFunction")); Graphene.guardAjax(button1).click(); WebElement button2 = browser.findElement(By.id("myForm2:ajax2")); Graphene.guardAjax(button2).click(); }
@Test public void testDynamicSelects() { List<String> fruitsExpected = new ArrayList<String>(); fruitsExpected.add(""); fruitsExpected.add("Banana"); fruitsExpected.add("Cranberry"); fruitsExpected.add("Blueberry"); fruitsExpected.add("Orange"); List<String> vegetablesExpected = new ArrayList<String>(); vegetablesExpected.add(""); vegetablesExpected.add("Potatoes"); vegetablesExpected.add("Broccoli"); vegetablesExpected.add("Garlic"); vegetablesExpected.add("Carrot"); assertTrue(firstSelect.isDisplayed(), "First select should be displayed!"); // assertFalse(secondSelect.isDisplayed(), "Second select should be dispayed"); Graphene.guardAjax(new Select(firstSelect)).selectByVisibleText("Fruits"); List<String> fruitsActual = new ArrayList<String>(); List<WebElement> fruitsOptions = new Select(secondSelect).getOptions(); for (WebElement option : fruitsOptions) { fruitsActual.add(option.getText().trim()); } assertTrue(secondSelect.isDisplayed(), "Second select should be dispayed"); assertEquals( fruitsActual, fruitsExpected, "When selected fruits in first select, in the second " + "should be some examples of Fruits"); Graphene.guardAjax(new Select(firstSelect)).selectByVisibleText("Vegetables"); List<String> vegetablesActual = new ArrayList<String>(); List<WebElement> vegetablesOptions = new Select(secondSelect).getOptions(); for (WebElement option : vegetablesOptions) { vegetablesActual.add(option.getText().trim()); } assertEquals( vegetablesActual, vegetablesExpected, "When selected vegetables in first select, in the second " + "should be some examples of vegetables"); }
protected void setCheckboxState(WebElement checkboxElement, boolean checked) { if ((checked == true && !isCheckboxChecked(checkboxElement)) || (checked == false && isCheckboxChecked(checkboxElement))) { WebElement trigger = checkboxElement.findElement(By.cssSelector("div.ui-chkbox-box")); Graphene.guardAjax(trigger).click(); } }
protected void selectOptionByLabel(WebElement menuElement, String text, boolean guardAjax) { String menuId = getEscapedElementId(menuElement); WebElement trigger = menuElement.findElement(By.cssSelector("div.ui-selectonemenu-trigger")); trigger.click(); String menuItemsContainerId = menuId + "_panel"; List<WebElement> options = driver.findElements( By.cssSelector("#" + menuItemsContainerId + " tr.ui-selectonemenu-item")); if (options.isEmpty()) { options = driver.findElements( By.cssSelector("#" + menuItemsContainerId + " li.ui-selectonemenu-item")); } String selectedOptionText = getSelectedOptionText(menuElement); for (WebElement option : options) { if (option.getAttribute("data-label").equals(text)) { if (guardAjax && !selectedOptionText.equals(text)) { Graphene.guardAjax(option).click(); } else { option.click(); } break; } } }
public void selectCurrency(String currencyCode) { WebElement flag = null; for (WebElement element : flags) { if (element.getAttribute("alt").contains(currencyCode)) { flag = element; break; } } Graphene.guardAjax(flag).click(); }
@Test @Templates(value = {"plain"}) public void testPreviousItem() { prevItemButton.click(); assertEquals(valueOutput.getStringValue(), "null"); Graphene.guardAjax(switchTo5Button).click(); prevItemButton.click(); assertEquals(valueOutput.getStringValue(), "item4"); }
/** * !All requests depends on Metamer`s requestTime! Generates a waiting proxy. The proxy will wait * for expected @waitRequestType which will be launched via interactions with @target and then it * waits until Metamer's request time changes(@waitRequestType is HTTP or XHR) or not changes * (@waitRequestType is NONE). * * @param <T> type of the given target * @param target object to be guarded * @param waitRequestType type of expected request which will be launched * @param guardTime time for which will be the target guarded, applicable only * for @waitRequestType = NONE * @return waiting proxy for target object */ public static <T> T waitRequest(T target, WaitRequestType waitRequestType, long guardTime) { switch (waitRequestType) { case HTTP: return requestTimeChangesWaiting(Graphene.guardHttp(target)); case XHR: return requestTimeChangesWaiting(Graphene.guardAjax(target)); case NONE: return requestTimeNotChangesWaiting(Graphene.guardNoRequest(target), guardTime); default: throw new UnsupportedOperationException("Not supported request: " + waitRequestType); } }
@Test @Templates(value = {"plain"}) public void testPreviousItemWithCycledSwitching() { attributes.set(AccordionAttributes.cycledSwitching, Boolean.TRUE); prevItemButton.click(); assertEquals(valueOutput.getStringValue(), "item5"); Graphene.guardAjax(switchTo5Button).click(); prevItemButton.click(); assertEquals(valueOutput.getStringValue(), "item4"); }
@Test public void testNoExceptionsOnPostback() { browser.get(contextPath.toExternalForm()); assertEquals(0, log.getLogEntries().size()); // set watched level log.changeLevel(Log.LogEntryLevel.ERROR); assertEquals(0, log.getLogEntries().size()); for (int i = 0; i < 3; i++) { // send ajax request Graphene.guardAjax(button).click(); // assert that there is no exception on postback assertEquals(0, log.getLogEntries().size()); } }
@Test @Templates(value = {"plain"}) public void testSwitchToItem() { List<WebElement> buttons = Lists.newArrayList(switchTo1Button, switchTo2Button, switchTo3Button, switchTo5Button); List<String> headers = Lists.newArrayList("Item 1", "Item 2", "Item 3", "Item 5"); for (int i = 0; i < buttons.size(); i++) { Graphene.guardAjax(buttons.get(i)).click(); assertEquals(accordion.advanced().getActiveItem().advanced().getHeader(), headers.get(i)); } // switch to disabled item Graphene.guardNoRequest(switchTo4Button).click(); assertEquals( accordion.advanced().getActiveItem().advanced().getHeader(), "Item 5", "Active item should not change."); }
private void selectOrFireChange(Select select, String visibleText) { if (!visibleText.equals(select.getFirstSelectedOption().getText())) { Graphene.guardAjax(select).selectByVisibleText(visibleText); } }
public void fireAction() { Graphene.guardAjax(link).click(); }
protected void verifyExecutedIds(String... expectedExecutedIds) { Graphene.guardAjax(button).click(); Assert.assertEquals(Arrays.toString(expectedExecutedIds), output.getText()); }
@Override public void performAction() { Graphene.guardAjax(page.selectManyCheckbox).click(); }
public void swapCurrencies() { Graphene.guardAjax(swapButton).click(); }