List of usage examples for org.openqa.selenium.support.ui Wait until
<T> T until(Function<? super F, T> isTrue);
From source file:cuenen.raymond.svgplot.DocumentScalerTest.java
License:CDDL license
/** * Test the scaling of the SVGDocument.//from w w w. j av a2s. c om * * @param driver The WebDriver executing the test. */ @Test(dataProvider = "driver", groups = "all") public void documentScalerTest(WebDriver driver) { Wait wait = load(driver, MODULE_LOADER_SCALER, 1); wait.until(RESULT_SET); WebElement circle = getElementById(driver, PLACEHOLDER_ID); String before = circle.getAttribute("before"); String after = circle.getAttribute("after"); String msg = getMessage(driver); assertNotEquals(before, after, msg); Capabilities caps = ((HasCapabilities) driver).getCapabilities(); Rectangle2D beforeRect = getBeforeRect(caps); assertEquals(toRect(before), beforeRect, msg); String[] size = getResult(driver).split(","); Rectangle2D afterRect = createRect(Double.parseDouble(size[0]), Double.parseDouble(size[1])); if ("opera".equals(caps.getBrowserName())) { afterRect.setRect(Math.floor(afterRect.getX()), Math.floor(afterRect.getY()), Math.floor(afterRect.getWidth()), Math.floor(afterRect.getHeight())); } Rectangle2D expected = toRect(after); if ("firefox".equals(caps.getBrowserName())) { /* Don't know how firefox comes op with its position coordinates. */ Dimension dim = driver.manage().window().getSize(); assertTrue(Double.compare(0.25 * dim.getHeight() - 17.75, afterRect.getY()) == 0); assertTrue(Double.compare(0.5 * dim.getHeight() - 35.5, afterRect.getWidth()) == 0); assertTrue(Double.compare(0.5 * dim.getHeight() - 35.5, afterRect.getHeight()) == 0); } else { assertEquals(expected, afterRect, msg); } }
From source file:cuenen.raymond.svgplot.ExpressionParserTest.java
License:CDDL license
/** * Convenience method to evaluate an expression. * * @param driver The WebDriver executing the test. * @param expression The expression to be parsed. * @param value The value to use with variable substitution. * @param alert {@code true} when an alert is expected, {@code false} * otherwise./*from ww w .ja v a 2s. c o m*/ * @return The parsed result. */ private String evaluateExpression(WebDriver driver, String expression, String value, boolean alert) { Wait wait = load(driver, MODULE_LOADER, 1); String callback = String.format(FUNCTION_FORMAT, expression, value); require(driver, callback, MODULE_NAME); if (alert) { wait.until(ExpectedConditions.alertIsPresent()); return getAlert(driver); } else { wait.until(RESULT_SET); return getResult(driver); } }
From source file:cuenen.raymond.svgplot.MathematicalEngineTest.java
License:CDDL license
/** * Convenience function for performing the range tests. * * @param driver The WebDriver executing the test. * @param function The pseudo-random function to test. * @param range The expected range of the result. *//*from w w w . j a va 2 s.c om*/ private void performRangeTest(WebDriver driver, String function, double... range) { Wait wait = load(driver, MODULE_LOADER, 1); String functionCall = createRangeFunctionCall(function); String callback = String.format(FUNCTION_FORMAT, functionCall); require(driver, callback, MODULE_NAME); wait.until(RESULT_SET); String result = getResult(driver); String msg = getMessage(driver); assertNotNull(result, msg); checkRange(result, range, msg + ": " + function); }
From source file:cuenen.raymond.svgplot.MathematicalEngineTest.java
License:CDDL license
/** * Convenience function for executing the tests. * * @param driver The WebDriver executing the test. * @param results The array of expected result values. * @param functions The array of functions to test. *//*from ww w. java 2 s .c o m*/ private void executeTest(WebDriver driver, Object[] results, String... functions) { Wait wait = load(driver, MODULE_LOADER, 1); String functionCall = createFunctionCall(functions); String callback = String.format(FUNCTION_FORMAT, functionCall); require(driver, callback, MODULE_NAME); wait.until(RESULT_SET); String result = getResult(driver); String msg = getMessage(driver); assertNotNull(result, msg); checkResult(result, results, functions, msg); }
From source file:cuenen.raymond.svgplot.RandomNumberGeneratorTest.java
License:CDDL license
/** * Convenience function for executing the tests. * * @param driver The WebDriver executing the test. * @param testDescription The array of objects to be used with the * {@link #FUNCTION_FORMAT}.// w w w . j a v a 2 s . c o m * @return The result from the placeholder WebElement. */ private String executeTest(WebDriver driver, Object... testDescription) { Wait wait = load(driver, MODULE_LOADER, 1); String callback = String.format(FUNCTION_FORMAT, testDescription); require(driver, callback, MODULE_NAME); wait.until(RESULT_SET); return getResult(driver); }
From source file:cuenen.raymond.svgplot.SVGPlotAttributesTest.java
License:CDDL license
/** * Verify the error when parsing the attribute twice. * * @param driver The WebDriver executing the test. *//*from w w w . jav a 2 s. c om*/ @Test(dataProvider = "driver", groups = { "all", "alert" }) public void multipleAttributesTest(WebDriver driver) { String msg = getMessage(driver); for (String[] attribute : VALID_ATTRIBUTES) { Wait wait = parseAttribute(driver, attribute[0], attribute[1], 2); wait.until(ExpectedConditions.alertIsPresent()); String alert = getAlert(driver); assertTrue(alert.startsWith(String.format(ALREADY_SET, attribute[0])), msg + ": " + attribute[0] + " --> " + alert); } }
From source file:cuenen.raymond.svgplot.SVGPlotAttributesTest.java
License:CDDL license
/** * Verify the exceptions when an invalid attribute value is supplied. * * @param driver The WebDriver executing the test. *///from ww w . ja v a2 s. c o m @Test(dataProvider = "driver", groups = { "all", "alert" }) public void invalidAttributesTest(WebDriver driver) { String msg = getMessage(driver); for (String[] attribute : INVALID_ATTRIBUTES) { Wait wait = parseAttribute(driver, attribute[0], attribute[1], 1); wait.until(ExpectedConditions.alertIsPresent()); String alert = getAlert(driver); assertTrue(alert.startsWith(attribute[2]), msg + ": " + attribute[0] + " --> " + alert); } }
From source file:cuenen.raymond.svgplot.SVGPlotAttributesTest.java
License:CDDL license
/** * Verify the exception of creating an unknown attribute. * * @param driver The WebDriver executing the test. */// w w w . j a va 2 s. co m @Test(dataProvider = "driver", groups = { "all", "alert" }) public void unknownAttributeTest(WebDriver driver) { Wait wait = parseAttribute(driver, UNKNOWN_ATTRIBUTE[0], UNKNOWN_ATTRIBUTE[1], 0); wait.until(ExpectedConditions.alertIsPresent()); String alert = getAlert(driver); String msg = getMessage(driver); assertTrue(alert.startsWith(UNKNOWN_ATTRIBUTE[2]), msg + ": " + UNKNOWN_ATTRIBUTE[0] + " --> " + alert); }
From source file:cuenen.raymond.svgplot.SVGPlotAttributesTest.java
License:CDDL license
/** * Create and test a newly defined attribute. * * @param driver The WebDriver executing the test. *//* w ww . j a va 2 s .co m*/ @Test(dataProvider = "driver", groups = "all") public void newAttributeTest(WebDriver driver) { int v = 0; for (int i = 0; i < UNKNOWN_ATTRIBUTE[1].length(); i++) { v += UNKNOWN_ATTRIBUTE[1].codePointAt(i); } Wait wait = load(driver, MODULE_LOADER, 1); String callback = String.format(SET_FUNCTION_FORMAT, NEW_ATTRIUTE[0], NEW_ATTRIUTE[1], NEW_ATTRIUTE[2], UNKNOWN_ATTRIBUTE[1]); require(driver, callback, MODULE_NAME); wait.until(RESULT_SET); String result = getResult(driver); String msg = getMessage(driver); assertEquals(result, String.valueOf(v), msg); }
From source file:cuenen.raymond.svgplot.SVGPlotAttributesTest.java
License:CDDL license
/** * Test for failure of a newly defined attribute. * * @param driver The WebDriver executing the test. */// w w w . j a va2 s .com @Test(dataProvider = "driver", groups = { "all", "alert" }) public void invalidNewAttributeTest(WebDriver driver) { Wait wait = load(driver, MODULE_LOADER, 1); String callback = String.format(SET_FUNCTION_FORMAT, NEW_ATTRIUTE[0], NEW_ATTRIUTE[1], "{parse: function(a){return a;}}", UNKNOWN_ATTRIBUTE[1]); require(driver, callback, MODULE_NAME); wait.until(ExpectedConditions.alertIsPresent()); String msg = getMessage(driver); String alert = getAlert(driver); assertTrue(alert.startsWith("TypeError: Invalid parse function"), msg + " --> " + alert); }