How to use equals method of org.openqa.selenium.ScriptKey class

Best Selenium code snippet using org.openqa.selenium.ScriptKey.equals

Source:MobileGeneric.java Github

copy

Full Screen

...1051 }105210531054 /**1055 * Asserts page title equals target value1056 *1057 * @param propertyKey (String) properties file key defining string1058 */1059 @Step("Confirm page title.")1060 public void confirmTitle(String propertyKey) {10611062 ss.assertTrue(driver.getTitle().toLowerCase().equals(getPropertyValue(propertyKey)));10631064 }106510661067 /**1068 * Scrolls down1069 *1070 */1071 @Step("Scroll down on the window.")1072 public void scrollDown() {10731074 JavascriptExecutor js = (JavascriptExecutor) driver;1075 js.executeScript("window.scrollBy(0,250)");10761077 }107810791080 /**1081 * Scroll to an element, direction independent1082 *1083 * @param propertyKey (String) properties file key defining string1084 */1085 public MobileElement smartScroll(String propertyKey) {10861087 this.me = confirmElementExistence(propertyKey);1088 int currentY = 0;1089 int currentX = 0;1090 int afterY = 100000;1091 int afterX = 100000;10921093 System.out.format("[LOG]: <[%s:%s] scrolling to element: %s; ", this.id, this.testName, propertyKey);1094 // move to element until moving no longer changes position. in general, the move is instantaneous1095 do {1096 currentY = (int) (long) this.jse.executeScript("return window.pageYOffset;");1097 currentX = (int) (long) this.jse.executeScript("return window.pageXOffset;");1098 System.out.format("(%d,%d) -> ", currentX, currentY);10991100 this.jse.executeScript("return arguments[0].scrollIntoView(true);", this.me);11011102 afterY = (int) (long) this.jse.executeScript("return window.pageYOffset;");1103 afterX = (int) (long) this.jse.executeScript("return window.pageXOffset;");1104 System.out.format("(%d,%d)", afterX, afterY);1105 } while ((Math.abs(currentY - afterY) != 0) && (Math.abs(currentX - afterX) != 0));11061107 System.out.format(";>%n" );1108 return this.me;11091110 }111111121113 /**1114 * Scroll to an element, direction independent1115 *1116 * @param w (WebElement)1117 */1118 public MobileElement smartScroll(MobileElement m) {11191120 int currentY = 0;1121 int currentX = 0;1122 int afterY = 100000;1123 int afterX = 100000;11241125 System.out.format("[LOG]: <[%s:%s] scrolling to element: ", this.id, this.testName);1126 // move to element until moving no longer changes position. in general, the move is instantaneous1127 do {1128 currentY = (int) (long) this.jse.executeScript("return window.pageYOffset;");1129 currentX = (int) (long) this.jse.executeScript("return window.pageXOffset;");1130 System.out.format("(%d,%d) -> ", currentX, currentY);11311132 this.jse.executeScript("return arguments[0].scrollIntoView(true);", m);11331134 afterY = (int) (long) this.jse.executeScript("return window.pageYOffset;");1135 afterX = (int) (long) this.jse.executeScript("return window.pageXOffset;");1136 System.out.format("(%d,%d)", afterX, afterY);1137 } while ((Math.abs(currentY - afterY) != 0) && (Math.abs(currentX - afterX) != 0));11381139 System.out.format(";>%n" );1140 return m;11411142 }114311441145 /**1146 * Scrolls up1147 * @Param pixelX (int)1148 * @Param pixelY (int)1149 */1150 @Step("Scroll up on the window.")1151 public void scrollUp(int pixelX, int pixelY) {11521153 jse.executeScript("window.scrollBy(argumets[0], -1*arguments[1])", pixelX, pixelY); // aug[0], arg[1]11541155 }115611571158 /**1159 * Scrolls down1160 * @Param pixelX (int)1161 * @Param pixelY (int)1162 */1163 @Step("Scroll down on the window.")1164 public void scrollDown(int pixelX, int pixelY) {11651166 jse.executeScript("window.scrollBy(argumets[0], arguments[1])", pixelX, pixelY);11671168 }116911701171 /**1172 * Scrolls up1173 *1174 */1175 @Step("Scroll up on the window.")1176 public void scrollUp() {11771178 jse.executeScript("window.scrollBy(0,-250)");11791180 }118111821183 /**1184 * Navigates browser to target URL1185 *1186 * @param propertyKey (String) properties file key defining string1187 */1188 @Step("Navigate to URL.")1189 public void getUrl(String propertyKey) {11901191 driver.get(getPropertyValue(propertyKey));1192 waitForPageLoaded();1193 ss.takeScreenShot("After navigation to URL.");11941195 }119611971198 /**1199 * Navigates to target URL (runtimeData)1200 *1201 * @param runtimeValue (String) value from runtimeData/GlobalConstants1202 */1203 @Step("Navigate to URL.")1204 public void getUrl(String[] runtimeValue) {12051206 driver.get(runtimeValue[0]);1207 waitForPageLoaded();1208 ss.takeScreenShot("After navigation to URL.");12091210 }121112121213 /**1214 * Retrieves locator definition and type from WebElement property definition1215 *1216 * @param propertyKey (String) properties file key defining element locator1217 * @return (String[]) containing locator definition and locator type1218 */1219 private String[] locatorElementAndMethod(String propertyKey) {12201221 //System.out.format("[DEBUG]: <[%s:%s] key: %s>%n", this.id, this.testName, propertyKey);1222 command = null;1223 String propertyValue = null;12241225 //System.out.format("[DEBUG]: <[%s:%s] key found?: %b>%n", this.id, this.testName, this.props.containsKey(propertyKey));1226 ss.assertTrue(props.containsKey(propertyKey), "Property key \""+propertyKey+"\" not found");1227 propertyValue = this.props.getProperty(propertyKey);1228 //System.out.format("[DEBUG]: <[%s:%s] key value: %s>%n", this.id, this.testName, propertyValue);1229 command = propertyValue.split(gc.locatorSeparator);1230 // System.out.format("[DEBUG]: <[%s:%s] command length: %d>%n", this.id, this.testName, command.length);123112321233 return command;12341235 }123612371238 /**1239 * Return String value of non-WebElement property definition1240 *1241 * @param propertyKey (String) properties file key defining string1242 * @return (String) value of property1243 */1244 public String getPropertyValue(String propertyKey) {12451246 // System.out.format("[DEBUG]: <[%s:%s] key: %s>%n", this.id, this.testName, propertyKey);1247 command = null;1248 String propertyValue = null;12491250 ss.assertTrue(props.containsKey(propertyKey), "Property key \""+propertyKey+"\" not found");1251 // System.out.format("[DEBUG]: <[%s:%s] key found?: %b>%n", this.id, this.testName, props.containsKey(propertyKey));12521253 propertyValue = props.getProperty(propertyKey);1254 // System.out.format("[DEBUG]: <[%s:%s] key value: %s>%n", this.id, this.testName, propertyValue);125512561257 return propertyValue;12581259 }126012611262 /**1263 * Inserts string into target element1264 *1265 * @param propertyKey (String) properties file key defining element locator1266 * @param input (String) text to enter into target element1267 */1268 @Step("Input text.")1269 public void sendText(String propertyKey, String input) {12701271 me = confirmElementExistence(propertyKey);1272 //me.click();1273 me.clear();1274 me.sendKeys(input);1275 ss.takeScreenShot("After input");12761277 }127812791280 /**1281 * Inserts string into target element1282 *1283 * @param me (WebElement) selenium text field1284 * @param input (String) text to enter into target element1285 */1286 @Step("Input text.")1287 public void sendText(MobileElement me, String input) {12881289 //me.click();1290 me.clear();1291 me.sendKeys(input);1292 ss.takeScreenShot("After input");12931294 }129512961297 /**1298 * Inserts string into target element1299 *1300 * @param propertyKey (String) properties file key defining element locator1301 * @param input (String) text to enter into target element1302 * @param takeSS (boolean) trigger to take a screenshot1303 */1304 @Step("Input text.")1305 public void sendText(String propertyKey, String input, boolean takeSS) {13061307 me = confirmElementExistence(propertyKey);1308 //me.click();1309 me.clear();1310 me.sendKeys(input);13111312 if (takeSS) {1313 ss.takeScreenShot("After input");1314 }13151316 }131713181319 /**1320 * Inserts string into target element1321 *1322 * @param we (WebElement) selenium text field1323 * @param input (String) text to enter into target element1324 * @param takeSS (boolean) trigger to take a screenshot1325 */1326 @Step("Input text.")1327 public void sendText(MobileElement me, String input, boolean takeSS) {13281329 me.clear();1330 me.sendKeys(input);13311332 if (takeSS) {1333 ss.takeScreenShot("After input");1334 }13351336 }133713381339 /**1340 * Manually trigger a screenshot1341 *1342 * @param description (String) describing screenshot to be taken1343 */1344 @Step("Take Screenshot: {0}.")1345 public void takeScreenShot(String description) {13461347 ss.takeScreenShot(description);13481349 }135013511352 /**1353 * After confirming element existence, clicks element.1354 *1355 * @param propertyKey (String) properties file key defining element locator1356 */1357 @Step("Click element.")1358 public void clickElement(String propertyKey) {13591360 me = confirmElementExistence(propertyKey);1361 System.out.format("[LOG]: <[%s:%s] clicking element with property key: \"%s\">%n", this.id, this.testName, propertyKey);1362 me.click();13631364 }136513661367 /**1368 * After confirming element existence, clicks element.1369 *1370 * @param wel (WebElement) selenium web element1371 */1372 @Step("Click element.")1373 public void clickElement(MobileElement me) {13741375 System.out.format("[LOG]: <[%s:%s] clicking element>%n", this.id, this.testName);1376 me.click();1377 waitForPageLoaded();13781379 }138013811382 /**1383 * After confirming element existence, clicks element.1384 *1385 * @param propertyKey (String) properties file key defining element locator1386 */1387 @Step("Click element.")1388 public void clickElement(String propertyKey, int timeOut) {13891390 me = confirmElementExistence(propertyKey);1391 System.out.format("[LOG]: <[%s:%s] clicking element with property key: \"%s\">%n", this.id, this.testName, propertyKey);1392 me.click();1393 waitForPageCompletelyLoaded(timeOut);13941395 }139613971398 /**1399 * After confirming dynamic element existence, clicks element.1400 *1401 * @param propertyKey (String) properties file key defining element locator1402 * @param replacement (String) compound locator replacement1403 */1404 @Step("Click dynamic element.")1405 public void clickElement(String propertyKey, String replacement) {14061407 me = confirmElementExistence(propertyKey, replacement);1408 System.out.format("[LOG]: <[%s:%s] clicking element with property key: \"%s\">%n", this.id, this.testName, propertyKey);1409 me.click();1410 waitForPageLoaded();14111412 }141314141415 /**1416 * Asserts element exists, includes custom error message1417 *1418 * @param propertyKeyCustomError (String[]) properties file key defining element locator, custom error message1419 * @return (WebElement)1420 */1421 @Step("Confirm element exists.")1422 public MobileElement confirmElementExistence(String[] propertyKeyCustomError) {14231424 ss.assertTrue((me = waitForElement(propertyKeyCustomError[0])) instanceof WebElement, propertyKeyCustomError[1]);1425 return me;14261427 }142814291430 /**1431 * Asserts element can be found within default time constraint1432 *1433 * @param propertyKey (String) properties file key defining element locator1434 * @return (WebElement)1435 */1436 @Step("Confirm element exists.")1437 public MobileElement confirmElementExistence(String propertyKey) {14381439 ss.assertTrue((me = waitForElement(propertyKey)) instanceof WebElement, "Element could not be located.");1440 return me;14411442 }144314441445 /**1446 * Asserts element can be found within default time constraint1447 *1448 * @param propertyKey (String) properties file key defining element locator1449 * @return (WebElement)1450 */1451 @Step("Confirm element exists.")1452 public MobileElement confirmElementExistenceOrNone(String propertyKey, int maxWait) {14531454 return me = waitForElement(propertyKey, maxWait);14551456 }14571458 /**1459 * Asserts element can be found within default time constraint1460 *1461 * @param propertyKey (String) properties file key defining element locator1462 * @return (WebElement)1463 */1464 @Step("Confirm element exists.")1465 public MobileElement confirmElementExistenceOrNone(String propertyKey, String replacement, int maxWait) {14661467 return me = waitForElement(propertyKey, replacement, maxWait);14681469 }1470147114721473 /**1474 * Asserts element can be found within time constraint1475 *1476 * @param propertyKey (String) properties file key defining element locator1477 * @param maxWait (int) maximum time in seconds to wait for element1478 * @return (WebElement)1479 */1480 @Step("Confirm element exists within {maxWait} seconds.")1481 public MobileElement confirmElementExistence(String propertyKey, int maxWait) {14821483 ss.assertTrue((me = waitForElement(propertyKey, maxWait)) instanceof WebElement, "Element could not be located.");1484 return me;14851486 }148714881489 /**1490 * Asserts element can be found within time constraint1491 *1492 * @param propertyKey (String) properties file key defining element locator1493 * @param maxWait (int) maximum time in seconds to wait for element1494 * @return (WebElement)1495 */1496 @Step("Confirm element exists within {maxWait} seconds.")1497 public MobileElement confirmElementExistence(String propertyKey, int maxWait, int polling) {14981499 ss.assertTrue((me = waitForElement(propertyKey, maxWait, polling)) instanceof WebElement, "Element could not be located.");1500 return me;15011502 }150315041505 /**1506 * Asserts compound element can be found within default time constraint1507 *1508 * @param propertyKey (String) properties file key defining element locator1509 * @param replacement (String) value to replace placeholder1510 * @return (WebElement)1511 */1512 @Step("Confirm dynamic element exists.")1513 public MobileElement confirmElementExistence(String propertyKey, String replacement) {15141515 ss.assertTrue((me = waitForElement(propertyKey, replacement)) instanceof WebElement, "Element could not be located.");1516 return me;15171518 }151915201521 /**1522 * Asserts compound element can be found within time constraint1523 *1524 * @param propertyKey (String) properties file key defining element locator1525 * @param replacement (String) value to replace placeholder1526 * @param maxWait (int) maximum time in seconds to wait for element1527 * @return (WebElement)1528 */1529 @Step("Confirm dynamic element exists within {maxWait} seconds.")1530 public MobileElement confirmElementExistence(String propertyKey, String replacement, int maxWait) {15311532 ss.assertTrue((me = waitForElement(propertyKey, replacement, maxWait)) instanceof WebElement, "Element could not be located.");1533 return me;15341535 }153615371538 /**1539 * Asserts element can be found relative to parent element1540 *1541 * @param parentElement (WebElement)1542 * @param propertyKey (String)1543 * @return (WebElement)1544 */1545 @Step("Confirm dynamic element exists within 30 seconds.")1546 public MobileElement confirmElementExistence(MobileElement parentElement, String propertyKey) {15471548 ss.assertTrue((me = waitForElement(parentElement, propertyKey)) instanceof WebElement, "Element could not be located.");1549 return me;15501551 }155215531554 /**1555 * Asserts one or more elements can be found within default time constraint, includes custom error message1556 *1557 * @param propertyKeyCustomError (String[]) properties file key defining element locator, custom error messsage1558 * @return (List<MobileElement>)1559 */1560 @Step("Confirm element(s) exist.")1561 public List<MobileElement> confirmElementsExistence(String[] propertyKeyCustomError) {15621563 ss.assertTrue(null != (meArray = waitForElements(propertyKeyCustomError[0])), propertyKeyCustomError[1]);1564 int size = meArray.size();1565 ss.assertTrue(size > 0, propertyKeyCustomError[1]);1566 return meArray;15671568 }156915701571 /**1572 * Asserts one or more element(s) can be found within default time constraint1573 *1574 * @param propertyKey (String) properties file key defining element locator1575 * @return (List<MobileElement>)1576 */1577 @Step("Confirm element(s) exist.")1578 public List<MobileElement> confirmElementsExistence(String propertyKey) {15791580 ss.assertTrue(null != (meArray = waitForElements(propertyKey)), "One or more Elements could not be located.");1581 int size = meArray.size();1582 ss.assertTrue(size > 0, "One or more Elements could not be located.");1583 return meArray;15841585 }158615871588 /**1589 * Asserts zero or more element(s) can be found within default time constraint1590 *1591 * @param propertyKey (String) properties file key defining element locator1592 * @return (List<MobileElement>)1593 */1594 @Step("Confirm element(s) exist.")1595 public List<MobileElement> confirmElementsExistenceOrNone(String propertyKey) {15961597 ss.assertTrue(null != (meArray = waitForElements(propertyKey)), "One or more Elements could not be located.");1598 int size = meArray.size();1599 ss.assertTrue(size >= 0, "One or more Elements could not be located.");1600 return meArray;16011602 }160316041605 /**1606 * Asserts one or more element(s) can be found within time constraint1607 *1608 * @param propertyKey (String) properties file key defining element locator1609 * @param maxWait (int) maximum time in seconds to wait for element1610 * @return (List<MobileElement>)1611 */1612 @Step("Confirm element(s) exist within {maxWait} seconds.")1613 public List<MobileElement> confirmElementsExistence(String propertyKey, int maxWait) {16141615 ss.assertTrue(null != (meArray = waitForElements(propertyKey, maxWait)), "One or more Elements could not be located.");1616 int size = meArray.size();1617 ss.assertTrue(size > 0, "One or more Elements could not be located.");1618 return meArray;16191620 }162116221623 /**1624 * Asserts one or more element(s) can be found within time constraint1625 *1626 * @param propertyKey (String) properties file key defining element locator1627 * @param w (WebElement)1628 * @return (List<MobileElement>)1629 */1630 @Step("Confirm element(s) exist within {maxWait} seconds.")1631 public List<MobileElement> confirmElementsExistence(MobileElement m, String propertyKey) {16321633 ss.assertTrue(null != (meArray = waitForElements(m, propertyKey)), "One or more Elements could not be located.");1634 int size = meArray.size();1635 ss.assertTrue(size > 0, "One or more Elements could not be located.");1636 return meArray;16371638 }163916401641 /**1642 * Asserts compound element(s) can be found within default time constraint1643 *1644 * @param propertyKey (String) properties file key defining element locator1645 * @param replacement (String) value to replace placeholder1646 * @return (List<MobileElement>)1647 */1648 @Step("Confirm dynamic element(s) exist.")1649 public List<MobileElement> confirmElementsExistence(String propertyKey, String replacement) {16501651 ss.assertTrue(null != (meArray = waitForElements(propertyKey, replacement)), "One or more Elements could not be located.");1652 int size = meArray.size();1653 ss.assertTrue(size > 0, "One or more Elements could not be located.");1654 return meArray;16551656 }165716581659 /**1660 * Asserts one or more compound element(s) can be found within time constraint1661 *1662 * @param propertyKey (String) properties file key defining element locator1663 * @param replacement (String) value to replace placeholder1664 * @param maxWait (int) maximum time in seconds to wait for element1665 * @return (List<MobileElement>)1666 */1667 @Step("Confirm dynamic element(s) exist within {maxWait} seconds.")1668 public List<MobileElement> confirmElementsExistence(String propertyKey, String replacement, int maxWait) {16691670 ss.assertTrue(null != (meArray = waitForElements(propertyKey, replacement, maxWait)), "One or more Elements could not be located.");1671 int size = meArray.size();1672 ss.assertTrue(size > 0, "One or more Elements could not be located.");1673 return meArray;16741675 }167616771678 /**1679 * Asserts zero or more element(s) can be found within default time constraint1680 *1681 * @param propertyKey (String) properties file key defining element locator1682 * @return (List<MobileElement>)1683 */1684 @Step("Confirm element(s) exist.")1685 public List<MobileElement> confirmElementsExistenceOrNone(MobileElement m, String propertyKey) {16861687 ss.assertTrue(null != (meArray = waitForElements(m, propertyKey)), "One or more Elements could not be located.");1688 int size = meArray.size();1689 ss.assertTrue(size >= 0, "One or more Elements could not be located.");1690 return meArray;16911692 }169316941695 /**1696 * Asserts element cannot be found within default time constraint1697 *1698 * @param propertyKeyCustomError (String[]) properties file key defining element locator, custom error message1699 */1700 @Step("Confirm element does not exist.")1701 public void confirmElementNonExistence(String[] propertyKeyCustomError) {17021703 ss.assertFalse(waitForElementNotFound(propertyKeyCustomError[0]) instanceof WebElement, propertyKeyCustomError[1]);17041705 }170617071708 /**1709 * Asserts element cannot be found within default time constraint1710 *1711 * @param propertyKey (String) properties file key defining element locator171217131714 */1715 @Step("Confirm element does not exist.")1716 public void confirmElementNonExistence(String propertyKey) {17171718 ss.assertFalse(waitForElementNotFound(propertyKey) instanceof WebElement, "Persistent element located unexpectedly.");17191720 }172117221723 /**1724 * Asserts element cannot be found within time constraint1725 *1726 * @param propertyKey (String) properties file key defining element locator1727 * @param maxWait (int) maximum time in seconds to wait for element1728 */1729 @Step("Confirm element does not exist within {maxWait} seconds.")1730 public void confirmElementNonExistence(String propertyKey, int maxWait) {17311732 ss.assertFalse(waitForElementNotFound(propertyKey, maxWait) instanceof WebElement, "Persistent element located unexpectedly.");17331734 }173517361737 /**1738 * Asserts compound element cannot be found within default time constraint1739 *1740 * @param propertyKey (String) properties file key defining element locator1741 * @param replacement (String) value to replace placeholder1742 */1743 @Step("Confirm dynamic element does not exist.")1744 public void confirmElementNonExistence(String propertyKey, String replacement) {17451746 ss.assertFalse(waitForElementNotFound(propertyKey, replacement) instanceof WebElement, "Persistent element located unexpectedly.");17471748 }174917501751 /**1752 * Asserts compound element cannot be found within time constraint1753 *1754 * @param propertyKey (String) properties file key defining element locator1755 * @param replacement (String) value to replace placeholder1756 * @param maxWait (int) maximum time in seconds to wait for element1757 */1758 @Step("Confirm dynamic element does not exist within {maxWait} seconds.")1759 public void confirmElementNonExistence(String propertyKey, String replacement, int maxWait) {17601761 ss.assertFalse(waitForElementNotFound(propertyKey, replacement, maxWait) instanceof WebElement, "Persistent element located unexpectedly.");17621763 }176417651766 /**1767 * Asserts element cannot be found within default time constraint, including custom error message1768 *1769 * @param propertyKeyCustomError (String[]) properties file key defining element locator, custom error message1770 */1771 @Step("Confirm element(s) do not exist.")1772 public void confirmElementsNonExistence(String[] propertyKeyCustomError) {17731774 ss.assertFalse(waitForElementsNotFound(propertyKeyCustomError[0]) instanceof List<?>, propertyKeyCustomError[1]);17751776 }177717781779 /**1780 * Asserts one or more element(s) cannot be found within default time constraint1781 *1782 * @param propertyKey (String) properties file key defining element locator1783 */1784 @Step("Confirm element(s) do not exist.")1785 public void confirmElementsNonExistence(String propertyKey) {17861787 ss.assertFalse(waitForElementsNotFound(propertyKey) instanceof List<?>, "Persistent element(s) located unexpectedly.");17881789 }179017911792 /**1793 * Asserts one or more element(s) cannot be found within time constraint1794 *1795 * @param propertyKey (String) properties file key defining element locator1796 * @param maxWait (int) maximum time in seconds to wait for element1797 */1798 @Step("Confirm element(s) do not exist within {maxWait} seconds.")1799 public void confirmElementsNonExistence(String propertyKey, int maxWait) {18001801 ss.assertFalse(waitForElementsNotFound(propertyKey, maxWait) instanceof List<?>, "Persistent element(s) located unexpectedly.");18021803 }180418051806 /**1807 * Asserts one or more compound element(s) cannot be found within default time constraint1808 *1809 * @param propertyKey (String) properties file key defining element locator1810 * @param replacement (String) value to replace placeholder1811 */1812 @Step("Confirm dynamic element(S) do not exist.")1813 public void confirmElementsNonExistence(String propertyKey, String replacement) {18141815 ss.assertFalse(waitForElementsNotFound(propertyKey, replacement) instanceof List<?>, "Persistent element(s) located unexpectedly.");18161817 }181818191820 /**1821 * Asserts one or more compound element(s) cannot be found within time constraint1822 *1823 * @param propertyKey (String) properties file key defining element locator1824 * @param replacement (String) value to replace placeholder1825 * @param maxWait (int) maximum time in seconds to wait for element1826 */1827 @Step("Confirm dynamic element(s) do not exist within {maxWait} seconds.")1828 public void confirmElementsNonExistence(String propertyKey, String replacement, int maxWait) {18291830 ss.assertFalse(waitForElementsNotFound(propertyKey, replacement, maxWait) instanceof List<?>, "Persistent element(s) located unexpectedly.");18311832 }183318341835 /**1836 * Given a generic locator (includes placeholder string), replace placeholder1837 * string with desired string1838 *1839 * @param locator (String) properties file key defining element locator1840 * @param replacement (String) to replace placeholder1841 * @return (String) locator as rebuilt1842 */1843 // @Step("Build dynamic locator.")1844 private String buildDynamicLocator(String locator, String replacement) {18451846 return locator.replaceAll(gc.compoundLocatorPlaceholder, replacement);18471848 }184918501851 /**1852 * Waits up to 30s for the browser JavaScript engine to report standby.1853 *1854 */1855 @Step("Wait for page to load.")1856 public void waitForPageLoaded() {18571858 double start = System.currentTimeMillis();1859 System.out.format("[LOG]: <[%s:%s] waiting up to %d seconds for page to load.>", this.id, this.testName, gc.defaultTimeOut);18601861 try {18621863 this.wait1864 .withTimeout(Duration.ofSeconds((long) gc.defaultTimeOut))1865 .until(new Function<AppiumDriver<?>, Boolean>() {1866 public Boolean apply(AppiumDriver<?> drv) {1867 return ( ((JavascriptExecutor) drv).executeScript("return document.readyState").equals("complete") ||1868 ((JavascriptExecutor) drv).executeScript("return document.readyState").equals("interactive") );1869 }1870 });18711872 } catch (TimeoutException to) {1873 System.out.format(" <timed out: unexpected>");18741875 } finally {1876 System.out.format(" <waited %.2f seconds>%n", (System.currentTimeMillis() - start)/1000.0);1877 }18781879 }188018811882 /**1883 * Waits up to timeOut seconds for the browser JavaScript engine to report standby.18841885 *1886 * @param timeOut (int) maximum seconds to wait1887 */1888 @Step("Wait for page to load.")1889 public void waitForPageLoaded(int timeOut) {189018911892189318941895 double start = System.currentTimeMillis();1896 System.out.format("[LOG]: <[%s:%s] waiting up to %d seconds for page to load.>", this.id, this.testName, timeOut);18971898 try {18991900 this.wait1901 .withTimeout(Duration.ofSeconds((long) timeOut))1902 .until(new Function<AppiumDriver<?>, Boolean>() {1903 public Boolean apply(AppiumDriver<?> drv) {1904 return ( ((JavascriptExecutor) drv).executeScript("return document.readyState").equals("complete") ||1905 ((JavascriptExecutor) drv).executeScript("return document.readyState").equals("interactive") );1906 }1907 });19081909 } catch (TimeoutException to) {1910 System.out.format(" <timed out: unexpected>");19111912 } finally {1913 System.out.format(" <waited %.2f seconds>%n", (System.currentTimeMillis() - start)/1000.0);1914 }19151916 }191719181919 /**1920 * Waits up to timeOut seconds for the browser JavaScript engine to report completed.1921 */1922 @Step("Wait for page to completely load.")1923 public void waitForPageCompletelyLoaded() {19241925 double start = System.currentTimeMillis();1926 System.out.format("[LOG]: <[%s:%s] waiting up to %d seconds for page to completely load.>", this.id, this.testName, gc.defaultTimeOut);19271928 try {1929 this.wait1930 .withTimeout(Duration.ofSeconds((long) gc.defaultTimeOut))1931 .until(new Function<AppiumDriver<?>, Boolean>() {1932 public Boolean apply(AppiumDriver<?> drv) {1933 return ( ((JavascriptExecutor) drv).executeScript("return document.readyState").equals("complete") );1934 }1935 });19361937 } catch (TimeoutException to) {1938 System.out.format(" <timed out: unexpected>");19391940 } finally {1941 System.out.format(" <waited %.2f seconds>%n", (System.currentTimeMillis() - start)/1000.0);1942 }19431944 }194519461947 /**1948 * Waits up to timeOut seconds for the browser JavaScript engine to report completed.1949 *1950 * @param timeOut (int) maximum seconds to wait1951 */1952 @Step("Wait for page to completely load.")1953 public void waitForPageCompletelyLoaded(int timeOut) {195419551956195719581959 double start = System.currentTimeMillis();1960 System.out.format("[LOG]: <[%s:%s] waiting up to %d seconds for page to completely load.>", this.id, this.testName, timeOut);19611962 try {19631964 this.wait1965 .withTimeout(Duration.ofSeconds((long) timeOut))1966 .until(new Function<AppiumDriver<?>, Boolean>() {1967 public Boolean apply(AppiumDriver<?> drv) {1968 return ( ((JavascriptExecutor) drv).executeScript("return document.readyState").equals("complete") );1969 }1970 });19711972 } catch (TimeoutException to) {1973 System.out.format(" <timed out: unexpected>");19741975 } finally {1976 System.out.format(" <waited %.2f seconds>%n", (System.currentTimeMillis() - start)/1000.0);1977 }19781979 }198019811982 /**1983 * Waits up to timeOut seconds for the browser JavaScript engine to report completed.1984 *1985 * @param customMessage (String) custom logging message1986 */1987 @Step("Wait for page to completely load.")1988 public void waitForPageCompletelyLoaded(String customMessage) {19891990 double start = System.currentTimeMillis();1991 System.out.format("[LOG]: <[%s:%s] %s>", this.id, this.testName, customMessage);19921993 try {1994 this.wait1995 .withTimeout(Duration.ofSeconds((long) gc.defaultTimeOut))1996 .until(new Function<AppiumDriver<?>, Boolean>() {1997 public Boolean apply(AppiumDriver<?> drv) {1998 return ( ((JavascriptExecutor) drv).executeScript("return document.readyState").equals("complete") );1999 }2000 });20012002 } catch (TimeoutException to) {2003 System.out.format(" <timed out: unexpected>");20042005 } finally {2006 System.out.format(" <waited %.2f seconds>%n", (System.currentTimeMillis() - start)/1000.0);2007 }20082009 }201020112012 /**2013 * Waits for dropdown to be found. Once found, sets dropdown to target value (property key).2014 * Once set, confirms selection.2015 *2016 * @param propertyKey (String) locator properties key2017 * @param valueKey (String) option to set properties key2018 */2019 @Step("Set dropdown value.")2020 public void setDropdownByStaticValue(String propertyKey, String valueKey) {20212022 waitForPageLoaded();2023 Select sel = new Select(confirmElementExistence(propertyKey));2024 String value = getPropertyValue(valueKey);2025 List<WebElement> options = sel.getOptions();2026 boolean valueExists = false;20272028 for (WebElement w: options) {2029 if (w.getAttribute("value").toLowerCase().equals(value.toLowerCase())) {2030 valueExists = true;2031 break;2032 }2033 }20342035 if (valueExists) {2036 System.out.format("[LOG]: <[%s:%s] setting dropdown value to: \"%s\">%n", this.id, this.testName, value);2037 sel.selectByValue(value);2038 ss.assertTrue(new Select(confirmElementExistence(propertyKey)).getAllSelectedOptions().size() == 1, "Multiple selections unexpected.");2039 ss.assertTrue(new Select(confirmElementExistence(propertyKey)).getFirstSelectedOption().getAttribute("value").toLowerCase().equals(value.toLowerCase()), "Unable to confirm selection.");2040 ss.takeScreenShot("Dropdown set by value.");2041 } else {2042 // force a descriptive fail if value not found2043 ss.assertTrue(false, "Could not find value among options.");2044 }20452046 }204720482049 /**2050 * Waits for dropdown to be found. Once found, sets dropdown to target value (runtimeData).2051 * Once set, confirms selection.2052 *2053 * @param propertyKey (String) locator properties key2054 * @param runtimeValue (String) runtimeData value2055 */2056 @Step("Set dropdown by dynamic value.")2057 public void setDropdownByDynamicValue(String propertyKey, String runtimeValue) {20582059 waitForPageLoaded();2060 Select sel = new Select(confirmElementExistence(propertyKey));2061 List<WebElement> options = sel.getOptions();2062 boolean valueExists = false;20632064 for (WebElement w: options) {2065 if (w.getAttribute("value").toLowerCase().equals(runtimeValue.toLowerCase())) {2066 valueExists = true;2067 break;2068 }2069 }20702071 if (valueExists) {2072 System.out.format("[LOG]: <[%s:%s] setting dropdown value to: \"%s\">%n", this.id, this.testName, runtimeValue);2073 sel.selectByValue(runtimeValue);2074 ss.assertTrue(new Select(confirmElementExistence(propertyKey)).getAllSelectedOptions().size() == 1, "Multiple selections unexpected.");2075 ss.assertTrue(new Select(confirmElementExistence(propertyKey)).getFirstSelectedOption().getAttribute("value").toLowerCase().equals(runtimeValue.toLowerCase()), "Unable to confirm selection.");2076 ss.takeScreenShot("Dropdown set by value.");2077 } else {2078 // force a descriptive fail if value not found2079 ss.assertTrue(false, "Could not find value among options.");2080 }20812082 }208320842085 /**2086 * Waits for dropdown to be found. Once found, sets dropdown to target index (properties).2087 * Once set, confirms selection.2088 *2089 * @param propertyKey (String) locator properties key2090 * @param valueKey (String) value properties key2091 */2092 @Step("Set dropdown by static index.")2093 public void setDropdownByStaticIndex(String propertyKey, String valueKey) {20942095 waitForPageLoaded();2096 Select sel = new Select(confirmElementExistence(propertyKey));2097 int index = Integer.parseInt(getPropertyValue(valueKey));20982099 if (index < sel.getOptions().size()) {2100 System.out.format("[LOG]: <[%s:%s] setting dropdown value to index: %d>%n", this.id, this.testName, index);2101 String value = sel.getOptions().get(index).getAttribute("value");2102 sel.selectByIndex(index);2103 ss.assertTrue(new Select(confirmElementExistence(propertyKey)).getAllSelectedOptions().size() == 1, "Multiple selections unexpected.");2104 ss.assertTrue(new Select(confirmElementExistence(propertyKey)).getFirstSelectedOption().getAttribute("value").equals(value), "Unable to confirm selection.");2105 ss.takeScreenShot("Dropdown set by index.");2106 } else {2107 // force a descriptive fail if index is not appropriate2108 ss.assertTrue(false, "Index beyond allowable bounds.");2109 }21102111 }211221132114 /**2115 * Waits for dropdown to be found. Once found, sets dropdown to target index (properties).2116 * Once set, confirms selection.2117 *2118 * @param w (WebElement)2119 * @param valueKey (String)2120 */2121 @Step("Set dropdown by static index.")2122 public void setDropdownByStaticIndex(MobileElement m, String valueKey) {21232124 waitForPageLoaded();2125 Select sel = new Select(m);2126 int index = Integer.parseInt(getPropertyValue(valueKey));21272128 if (index < sel.getOptions().size()) {2129 System.out.format("[LOG]: <[%s:%s] setting dropdown value to index: %d>%n", this.id, this.testName, index);2130 String value = sel.getOptions().get(index).getAttribute("value");2131 sel.selectByIndex(index);2132 ss.assertTrue(new Select(m).getAllSelectedOptions().size() == 1, "Multiple selections unexpected.");2133 ss.assertTrue(new Select(m).getFirstSelectedOption().getAttribute("value").equals(value), "Unable to confirm selection.");2134 ss.takeScreenShot("Dropdown set by index.");2135 } else {2136 // force a descriptive fail if index is not appropriate2137 ss.assertTrue(false, "Index beyond allowable bounds.");2138 }21392140 }214121422143 /**2144 * Waits for dropdown to be found. Once found, sets dropdown to target index (runtimeData).2145 * Once set, confirms selection.2146 *2147 * @param propertyKey (String) locator properties key2148 * @param runtimeIndex (int) target option index2149 */2150 @Step("Set dropdown by dynamic index.")2151 public void setDropdownByDynamicIndex(String propertyKey, String runtimeIndex) {21522153 waitForPageLoaded();2154 Select sel = new Select(confirmElementExistence(propertyKey));2155 int index = Integer.parseInt(runtimeIndex);21562157 if ( index < sel.getOptions().size()) {2158 System.out.format("[LOG]: <[%s:%s] setting dropdown value to index: %d>%n", this.id, this.testName, index);2159 String value = sel.getOptions().get(index).getAttribute("value");2160 sel.selectByIndex(index);2161 ss.assertTrue(new Select(confirmElementExistence(propertyKey)).getAllSelectedOptions().size() == 1, "Multiple selections unexpected.");2162 ss.assertTrue(new Select(confirmElementExistence(propertyKey)).getFirstSelectedOption().getAttribute("value").equals(value), "Unable to confirm selection.");2163 ss.takeScreenShot("Dropdown set by index.");2164 } else {2165 // force a descriptive fail if index is not appropriate2166 ss.assertTrue(false, "Index beyond allowable bounds.");2167 }21682169 }217021712172 /**2173 * Waits for dropdown to be found. Once found, sets dropdown to target index (int).2174 * Once set, confirms selection.2175 * <strong></strong>2176 *2177 * @param propertyKey (String) locator properties key2178 * @param index (int) target option index2179 * @deprecated NOT PREFERRED due to hard-coding dependency. use {@link #setDropdownByDynamicIndex(String, String)} where possible2180 */2181 @Step("Set dropdown by dynamic[hard] index.")2182 @Deprecated2183 public void setDropdownByDynamicIndex(String propertyKey, int index) {21842185 waitForPageLoaded();2186 Select sel = new Select(confirmElementExistence(propertyKey));21872188 if ( index < sel.getOptions().size()) {2189 System.out.format("[LOG]: <[%s:%s] setting dropdown value to index: %d>%n", this.id, this.testName, index);2190 String value = sel.getOptions().get(index).getAttribute("value");2191 sel.selectByIndex(index);2192 ss.assertTrue(new Select(confirmElementExistence(propertyKey)).getAllSelectedOptions().size() == 1, "Multiple selections unexpected.");2193 ss.assertTrue(new Select(confirmElementExistence(propertyKey)).getFirstSelectedOption().getAttribute("value").equals(value), "Unable to confirm selection.");2194 ss.takeScreenShot("Dropdown set by index[hard].");2195 } else {2196 // force a descriptive fail if index is not appropriate2197 ss.assertTrue(false, "Index beyond allowable bounds.");2198 }21992200 }220122022203 /**2204 * Waits for dropdown to be found. Once found, sets dropdown to target value (testReference).2205 * Once set, confirms selection.2206 *2207 * @param propertyKey (String) locator properties key2208 * @param valueKey (String) value properties key2209 */2210 @Step("Set dropdown static visible text value.")2211 public void setDropdownByStaticVisibleText(String propertyKey, String valueKey) {22122213 waitForPageLoaded();2214 Select sel = new Select(confirmElementExistence(propertyKey));2215 String visibleText = getPropertyValue(valueKey);2216 List<WebElement> options = sel.getOptions();2217 boolean valueExists = false;22182219 for (WebElement w: options) {2220 if (w.getText().toLowerCase().equals(visibleText.toLowerCase())) {2221 valueExists = true;2222 break;2223 }2224 }22252226 if (valueExists) {2227 System.out.format("[LOG]: <[%s:%s] setting dropdown value to: \"%s\">%n", id, testName, visibleText);2228 sel.selectByVisibleText(visibleText);2229 ss.assertTrue(new Select(confirmElementExistence(propertyKey)).getAllSelectedOptions().size() == 1, "Multiple selections unexpected.");2230 ss.assertTrue(new Select(confirmElementExistence(propertyKey)).getFirstSelectedOption().getText().toLowerCase().equals(visibleText.toLowerCase()), "Unable to confirm selection.");2231 ss.takeScreenShot("Dropdown set by visible text.");2232 } else {2233 // force a descriptive fail if no match2234 ss.assertTrue(false, "Could not find exact visible text match.");2235 }22362237 }223822392240 /**2241 * Waits for dropdown to be found. Once found, sets dropdown to target value (runtimeData).2242 * Once set, confirms selection.2243 *2244 * @param propertyKey (String) locator properties key2245 * @param runtimeValue (String) runtimeData value2246 */2247 @Step("Set dropdown by dynamic visible text value.")2248 public void setDropdownByDynamicVisibleText(String propertyKey, String runtimeValue) {22492250 waitForPageLoaded();2251 Select sel = new Select(confirmElementExistence(propertyKey));2252 List<WebElement> options = sel.getOptions();2253 boolean valueExists = false;22542255 for (WebElement w: options) {2256 if (w.getText().toLowerCase().equals(runtimeValue.toLowerCase())) {2257 valueExists = true;2258 break;2259 }2260 }22612262 if (valueExists) {2263 System.out.format("[LOG]: <[%s:%s] setting dropdown value to: \"%s\">%n", id, testName, runtimeValue);2264 sel.selectByVisibleText(runtimeValue);2265 ss.assertTrue(new Select(confirmElementExistence(propertyKey)).getAllSelectedOptions().size() == 1, "Multiple selections unexpected.");2266 ss.assertTrue(new Select(confirmElementExistence(propertyKey)).getFirstSelectedOption().getText().toLowerCase().equals(runtimeValue.toLowerCase()), "Unable to confirm selection.");2267 ss.takeScreenShot("Dropdown set by visible text.");2268 } else {2269 // force a descriptive fail if no match2270 ss.assertTrue(false, "Could not find exact visible text match.");2271 }22722273 }227422752276 /**2277 * Waits for dropdown to be found. Once found, sets dropdown to target index,2278 * as determined by p[artial text match (properties).2279 * Once set, confirms selection.2280 *2281 * @param propertyKey (String) locator properties key2282 * @param valueKey (String) value properties key2283 */2284 @Step("Set dropdown by static partial visible text value.")2285 public void setDropdownByStaticPartialVisibleText(String propertyKey, String valueKey) {22862287 waitForPageLoaded();2288 Select sel = new Select(confirmElementExistence(propertyKey));2289 List<WebElement> options = sel.getOptions();2290 String value = getPropertyValue(valueKey);2291 //System.out.format("[DEBUG]: <[%s:%s] comparing against value: \"%s\">%n", id, testName, value);2292 int index = getIndexByPartialText(value, options);2293 //System.out.format("[DEBUG]: <[%s:%s] index of match: %d>%n", id, testName, index);22942295 if (index >= 0) {2296 System.out.format("[LOG]: <[%s:%s] setting dropdown value to index: %d, by partial text: \"%s\">%n", id, testName, index, value);2297 sel.selectByIndex(index);2298 ss.assertTrue(new Select(confirmElementExistence(propertyKey)).getAllSelectedOptions().size() == 1, "Multiple selections unexpected.");2299 ss.assertTrue(new Select(confirmElementExistence(propertyKey)).getFirstSelectedOption().getText().toLowerCase().contains(value.toLowerCase()), "Unable to confirm selection.");2300 ss.takeScreenShot("Dropdown set by partial text.");2301 } else {2302 // force a descriptive fail if no match2303 ss.assertTrue(false, "Could not find partial visible text match.");2304 }23052306 }230723082309 /**2310 * Waits for dropdown to be found. Once found, sets dropdown to target index,2311 * as determined by partial text match (properties).2312 * Once set, confirms selection.2313 *2314 * @param w (WebElement) derived element2315 * @param valueKey (string) value properties key2316 */2317 @Step("Set dropdown by static partial visible text value.")2318 public void setDropdownByStaticPartialVisibleText(MobileElement m, String valueKey) {23192320 waitForPageLoaded();2321 Select sel = new Select(m);2322 List<WebElement> options = sel.getOptions();2323 String value = getPropertyValue(valueKey);2324 //System.out.format("[DEBUG]: <[%s:%s] comparing against value: \"%s\">%n", id, testName, value);2325 int index = getIndexByPartialText(value, options);2326 //System.out.format("[DEBUG]: <[%s:%s] index of match: %d>%n", id, testName, index);23272328 if (index >= 0) {2329 System.out.format("[LOG]: <[%s:%s] setting dropdown value to index: %d, by partial text: \"%s\">%n", id, testName, index, value);2330 sel.selectByIndex(index);2331 ss.assertTrue(new Select(m).getAllSelectedOptions().size() == 1, "Multiple selections unexpected.");2332 ss.assertTrue(new Select(m).getFirstSelectedOption().getText().toLowerCase().contains(value.toLowerCase()), "Unable to confirm selection.");2333 ss.takeScreenShot("Dropdown set by partial text.");2334 } else {2335 // force a descriptive fail if no match2336 ss.assertTrue(false, "Could not find partial visible text match.");2337 }23382339 }234023412342 /**2343 * Waits for dropdown to be found. Once found, sets dropdown to target index,2344 * as determined by partial text match (runtimeData).2345 * Once set, confirms selection.2346 *2347 * @param propertyKey (String) locator properties key2348 * @param runtimeValue (String) runtimeData value2349 */2350 @Step("Set dropdown by dynamic partial visible text value.")2351 public void setDropdownByDynamicPartialVisibleText(String propertyKey, String runtimeValue) {23522353 waitForPageLoaded();2354 Select sel = new Select(confirmElementExistence(propertyKey));2355 List<WebElement> options = sel.getOptions();2356 //System.out.format("[DEBUG]: <[%s:%s] comparing against value: \"%s\">%n", id, testName, runtimeValue);2357 int index = getIndexByPartialText(runtimeValue, options);2358 //System.out.format("[DEBUG]: <[%s:%s] index of match: %d>%n", id, testName, index);23592360 if (index >= 0) {2361 System.out.format("[LOG]: <[%s:%s] setting dropdown value to index: %d, by partial text: \"%s\">%n", id, testName, index, runtimeValue);2362 sel.selectByIndex(index);2363 ss.assertTrue(new Select(confirmElementExistence(propertyKey)).getAllSelectedOptions().size() == 1, "Multiple selections unexpected.");2364 ss.assertTrue(new Select(confirmElementExistence(propertyKey)).getFirstSelectedOption().getText().toLowerCase().contains(runtimeValue.toLowerCase()), "Unable to confirm selection.");2365 ss.takeScreenShot("Dropdown set by partial text.");2366 } else {2367 // force a descriptive fail if no match2368 ss.assertTrue(false, "Could not find partial visible text match.");2369 }23702371 }237223732374 /**2375 * Waits for dropdown to be found. Once found, sets dropdown to target containing target value,2376 * as determined by partial text match (runtimeData).2377 * Once set, confirms selection.2378 *2379 * @param w (WebElement)2380 * @param runtimeValue (String)2381 */2382 @Step("Set dropdown by dynamic partial visible text value.")2383 public void setDropdownByDynamicPartialVisibleText(MobileElement m, String runtimeValue) {23842385 waitForPageLoaded();2386 Select sel = new Select(m);2387 List<WebElement> options = sel.getOptions();2388 //System.out.format("[DEBUG]: <[%s:%s] comparing against value: \"%s\">%n", id, testName, runtimeValue);2389 int index = getIndexByPartialText(runtimeValue, options);2390 //System.out.format("[DEBUG]: <[%s:%s] index of match: %d>%n", id, testName, index);23912392 if (index >= 0) {2393 System.out.format("[LOG]: <[%s:%s] setting dropdown value to index: %d, by partial text: \"%s\">%n", id, testName, index, runtimeValue);2394 sel.selectByIndex(index);2395 ss.assertTrue(new Select(m).getAllSelectedOptions().size() == 1, "Multiple selections unexpected.");2396 ss.assertTrue(new Select(m).getFirstSelectedOption().getText().toLowerCase().contains(runtimeValue.toLowerCase()), "Unable to confirm selection.");2397 ss.takeScreenShot("Dropdown set by partial text.");2398 } else {2399 // force a descriptive fail if no match2400 ss.assertTrue(false, "Could not find partial visible text match.");2401 }24022403 }240424052406 /**2407 * Helper method for {@link #setDropdownByStaticPartialVisibleText(String, String)}2408 * and {@link #setDropdownByDynamicPartialVisibleText(String, String)}.2409 *2410 * Compares list element text to a known string in order to determine index of2411 * matching element.2412 *2413 * @param match (String) text to compare against select option text2414 * @param options (List<MobileElement>) list of select options as web elements2415 * @return (int) index of match, or -12416 */2417 private int getIndexByPartialText(String match, List<WebElement> options) {24182419 for (int i = 0; i < options.size(); i++) {2420 /*if (null != options.get(i)) {2421 System.out.format("[DEBUG]: <[%s:%s] value extracted at index=%d: \"%s\">%n", id, testName, i, options.get(i).getText());2422 }*/2423 if (null != options.get(i) && options.get(i).getText().contains(match)) {2424 return i;2425 }2426 }2427 return -1;24282429 }243024312432 /**2433 * Compares a given string (property key) against the text contents of2434 * a given web element (property key)2435 *2436 * @param propertyKey (String) locator properties key2437 * @param valueKey (String) comparison string2438 * @return (WebElement)2439 */2440 @Step("Confirm text value.")2441 public MobileElement confirmStaticTextValue(String propertyKey, String valueKey) {24422443 value = getPropertyValue(valueKey);2444 me = confirmElementExistence(propertyKey);2445 System.out.format("[LOG]: <[%s:%s] comparing string contains string: \"%s:%s\">%n", this.id, this.testName, me.getText().replace("\n", ""), value);2446 ss.assertTrue(me.getText().toLowerCase().contains(value.toLowerCase()));2447 ss.takeScreenShot("Confirm text presence.");2448 return me;24492450 }245124522453 /**2454 * Compare a give string (properties) against the contents of a given dynamic web element (properties)2455 *2456 * @param propertyKey (String) compound locator properties key2457 * @param replacementKey (String) replacement text properties key2458 * @param valueKey (String) comparison value text properties key2459 */2460 @Step("Confirm text value.")2461 public MobileElement confirmStaticTextValue(String propertyKey, String replacementKey, String valueKey) {24622463 me = confirmElementExistence(propertyKey, getPropertyValue(replacementKey));2464 ss.assertTrue(me.getText().trim().toLowerCase().contains(getPropertyValue(valueKey).trim().toLowerCase()));2465 ss.takeScreenShot("Confirm text presence.");2466 return me;24672468 }246924702471 /**2472 * Compares a given string (property key) against the text contents of2473 * a given web element (property key)2474 *2475 * @param w (WebElement)2476 * @param valueKey (String) comparison string2477 * @return (WebElement)2478 */2479 @Step("Confirm text value.")2480 public MobileElement confirmStaticTextValue(MobileElement m, String valueKey) {24812482 value = getPropertyValue(valueKey);2483 System.out.format("[LOG]: <[%s:%s] comparing string contains string: \"%s:%s\">%n", this.id, this.testName, m.getText().replace("\n", ""), value);2484 ss.assertTrue(m.getText().toLowerCase().contains(value.toLowerCase()));2485 ss.takeScreenShot("Confirm text presence.");2486 return m;24872488 }24892490 /**2491 * Compares a given string (property key) against the text contents of2492 * a given web element (property key)2493 *2494 * @param w (WebElement)2495 * @param valueKeys (String) comparison string2496 * @return (WebElement)2497 */2498 @Step("Confirm text value.")2499 public MobileElement confirmStaticTextValues(MobileElement m, List<String> valueKeys) {25002501 List<String> values = new ArrayList<String>();25022503 for (String s: valueKeys) {2504 values.add(getPropertyValue(s));2505 }25062507 System.out.format("[LOG]: <[%s:%s] comparing element text matches list: \"%s:%s\">%n", this.id, this.testName, m.getAttribute("innerHTML"), String.join(",", values));2508 ss.assertTrue(elementContentInList(m.getAttribute("innerHTML"), values), "Could not confirm a suitable Process Description.");25092510 ss.takeScreenShot("Confirm text presence.");2511 return m;25122513 }251425152516 /**2517 * Helper method for {@link #confirmStaticTextValues(WebElement, List)}.2518 * Compares singular string against string list contents.2519 *2520 * @param search (String) string to compare against list values2521 * @param reference (List<String>) list of potential matches2522 * @return (boolean) search string found in list?2523 */2524 private boolean elementContentInList(String search, List<String> reference) {25252526 for (String s: reference) {2527 if (s.toLowerCase().contains(search.toLowerCase())) {2528 return true;2529 }2530 }2531 return false;25322533 }253425352536 /**2537 * Compares a given string (runtimeData/caller derived) against the text contents of2538 * a given web element (property key)2539 *2540 * @param propertyKey (String) locator properties key2541 * @param value (String) comparison string2542 */2543 @Step("Confirm text value.")2544 public MobileElement confirmDynamicTextValue(String propertyKey, String value) {25452546 me = confirmElementExistence(propertyKey);2547 System.out.format("[LOG]: <[%s:%s] comparing string contains string: \"%s:%s\">%n", this.id, this.testName, me.getText().replace("\n", ""), value);2548 ss.assertTrue(me.getText().toLowerCase().contains(value.toLowerCase()));2549 ss.takeScreenShot("Confirm text presence.");2550 return me;25512552 }255325542555 /**2556 * Compare a give string (runtimeData) against the contents of a given dynamic web element (properties)2557 *2558 * @param propertyKey (String) compound locator properties key2559 * @param replacementKey (String) replacement text properties key2560 * @param value (String) comparison value text2561 */2562 @Step("Confirm text value.")2563 public MobileElement confirmDynamicTextValue(String propertyKey, String replacementKey, String value) {25642565 me = confirmElementExistence(propertyKey, getPropertyValue(replacementKey));2566 ss.assertTrue(me.getText().trim().toLowerCase().contains(value.trim().toLowerCase()));2567 ss.takeScreenShot("Confirm text presence.");2568 return me;25692570 }257125722573 /**2574 * Compare a give string (runtimeData) against the contents of a given dynamic web element (runtimeData)2575 *2576 * @param propertyKey (String) compound locator properties key2577 * @param values (String[]) a string array containing the replacement value at position 0 and comparison value at position 12578 */2579 @Step("Confirm text value.")2580 public MobileElement confirmDynamicTextValue(String propertyKey, String[] values) {25812582 String replacementValue = values[0];2583 String value = values[1];25842585 me = confirmElementExistence(propertyKey, replacementValue);2586 ss.assertTrue(me.getText().trim().toLowerCase().contains(value.trim().toLowerCase()));2587 ss.takeScreenShot("Confirm text presence.");2588 return me;25892590 }259125922593 /**2594 * Compares a given string (runtimeData/caller derived) against the text contents of2595 * a given web element (WebElement)2596 *2597 * @param we (WebElement) selenium element wrapping text2598 * @param value (String) comparison string2599 */2600 @Step("Confirm text value.")2601 public MobileElement confirmDynamicTextValue(MobileElement me, String value) {26022603 System.out.format("[LOG]: <[%s:%s] comparing string contains string: \"%s:%s\">%n", this.id, this.testName, me.getText().replace("\n", ""), value);2604 ss.assertTrue(me.getText().toLowerCase().contains(value.toLowerCase()));2605 ss.takeScreenShot("Confirm text presence.");2606 return me;26072608 }260926102611 /**2612 * Compares a given string (runtimeData/caller derived) against the text contents of2613 * a given web element (property key), expected absence2614 *2615 * @param propertyKey (String) locator properties key2616 * @param value (String) comparison string2617 */2618 @Step("Confirm text value.")2619 public MobileElement confirmDynamicNotTextValue(String propertyKey, String value) {26202621 me = confirmElementExistence(propertyKey);2622 System.out.format("[LOG]: <[%s:%s] comparing string contains string: \"%s:%s\">%n", this.id, this.testName, me.getText().replace("\n", ""), value);2623 ss.assertTrue(!me.getText().toLowerCase().contains(value.toLowerCase()));2624 ss.takeScreenShot("Confirm text presence.");2625 return me;26262627 }262826292630 /**2631 * Compares a given string (runtimeData) against the text contents of a given web element2632 * (property key)2633 *2634 * @param propertyKey (String) locator properties key2635 * @param runtimeValue (String) comparison string2636 */2637 @Step("Confirm text value.")2638 public MobileElement confirmExactDynamicTextValue(String propertyKey, String runtimeValue) {26392640 me = confirmElementExistence(propertyKey);2641 ss.assertTrue(me.getText().equals(runtimeValue));2642 ss.takeScreenShot("Confirm text presence.");2643 return me;26442645 }264626472648 /**2649 * Compares a given string (runtimeData) against the text contents of a given web element2650 * (WebElement)2651 *2652 * @param we (WebElement) selenium element wrapping text2653 * @param runtimeValue (String) comparison string2654 */2655 @Step("Confirm text value.")2656 public MobileElement confirmExactDynamicTextValue(MobileElement me, String runtimeValue) {26572658 //System.out.format("[DEBUG]: <[%s:%s] comparing strings [exp]\"%s\":[act]\"%s\">%n", this.id, this.testName, runtimeValue.trim(), me.getText().trim());2659 ss.assertTrue(me.getText().trim().equals(runtimeValue.trim()));2660 ss.takeScreenShot("Confirm text presence.");2661 return me;26622663 }266426652666 /**2667 * Compares a given string (runtimeData) against the input text of a given input field2668 * (runtimeData)2669 *2670 * @param propertyKey (String) locator properties key2671 * @param runtimeValue (String) comparison string2672 */2673 @Step("Confirm text value.")2674 public MobileElement confirmExactDynamicInputText(String propertyKey, String runtimeValue) {26752676 me = confirmElementExistence(propertyKey);2677 String value = (String) this.jse.executeScript("return arguments[0].value", me);2678 //String value = (String) this.jse.executeScript("return $(arguments[0]).val()", loc); // has an issue with unrecognized expression that I do not understand2679 //System.out.format("[DEBUG]: <[%s:%s] value returned from javascriptexecutor: \"%s\">%n", value);2680 ss.assertTrue(value.equals(runtimeValue));2681 ss.takeScreenShot("Confirm text presence.");2682 return me;26832684 }268526862687 /**2688 * Compares a given string (runtimeData) against the input text of a given input field2689 * (runtimeData)2690 *2691 * @param we (WebElement) selenium element wrapping text2692 * @param runtimeValue (String) comparison string2693 */2694 @Step("Confirm text value.")2695 public MobileElement confirmExactDynamicInputText(MobileElement me, String runtimeValue) {26962697 String value = (String) this.jse.executeScript("return arguments[0].value", me);2698 //String value = (String) this.jse.executeScript("return $(arguments[0]).val()", loc); // has an issue with unrecognized expression that I do not understand2699 //System.out.format("[DEBUG]: <[%s:%s] value returned from javascriptexecutor: \"%s\">%n", value);2700 ss.assertTrue(value.equals(runtimeValue));2701 ss.takeScreenShot("Confirm text presence.");2702 return me;27032704 }270527062707 /**2708 * Given a target window title, cycle through open windows until title matches, else return false2709 *2710 * @param valueKey (String) window title for comparison2711 * @return (boolean) true if window found2712 */2713 @Step("Switch to window by title.")2714 public void switchToWindowByTitle(String valueKey) {27152716 String title;2717 String currentHandle = this.driver.getWindowHandle();2718 //System.out.format("[DEBUG]: <[%s:%s] current window handle: \"%s\">%n", this.id, this.testName, currentHandle);2719 Set<String> handles = this.driver.getWindowHandles();27202721 for (String handle: handles) {2722 System.out.format("[LOG]: <[%s:%s] checking window handle: \"%s\" for title match.>%n", this.id, this.testName, handle);2723 if(!handle.equals(currentHandle)) {2724 this.driver.switchTo().window(handle);2725 waitForPageLoaded(120);2726 title = this.driver.getTitle();2727 //System.out.format("[DEBUG]: <[%s:%s] comparing window title to reference: \"%s:%s\">%n", this.id, this.testName, title, getPropertyValue(valueKey));2728 //System.out.format("[DEBUG]: <[%s:%s] strings match?: %b>%n", this.id, this.testName, title.toLowerCase().equals(getPropertyValue(valueKey).toLowerCase().trim()));2729 if (title.replace("\u2013","-").toLowerCase().equals(getPropertyValue(valueKey).toLowerCase())) {2730 ss.assertTrue(true);2731 return;2732 }2733 }2734 }2735 ss.assertTrue(false, "Could not find matching window title.");27362737 }273827392740 /**2741 * Given one daughter window, switch to daughter window2742 */2743 @Step("Switch to daughter window.")2744 public String[] switchToDaughterWindow() {27452746 String currentHandle = this.driver.getWindowHandle();2747 Set<String> handles = this.driver.getWindowHandles();2748 String hndl = null;27492750 ss.assertTrue(handles.size() == 2, "More than one daughter window.");27512752 for (String handle: handles) {2753 if (!handle.equals(currentHandle)) {2754 this.driver.switchTo().window(handle);2755 waitForPageLoaded(30);2756 hndl = handle;2757 }2758 }2759 return new String[] {currentHandle, hndl};27602761 }276227632764 /**2765 * Given a window handle, switch to it2766 */2767 @Step("Switch to parent window.")2768 public void switchToWindowByHandle(String handle) {27692770 Set<String> handles = this.driver.getWindowHandles();2771 if (handles.contains(handle)) {2772 this.driver.switchTo().window(handle);2773 waitForPageLoaded(30);2774 } else {2775 ss.assertTrue(false, "Window handle not found.");2776 }27772778 }277927802781 /**2782 * Check for broken image.2783 */2784 @Step("Check for broken image.")2785 public void checkForBrokenImage(String propertyKey) {27862787 //waitForPageCompletelyLoaded();2788 me = confirmElementExistence(propertyKey);27892790 System.out.format("[LOG]: <[%s:%s] checking up to %d seconds for broken image.>", this.id, this.testName, gc.defaultTimeOut);2791 double start = System.currentTimeMillis();2792 try {27932794 this.wait2795 .withTimeout(Duration.ofSeconds((long) gc.defaultTimeOut))2796 .until(new Function<AppiumDriver<?>, Boolean>() {2797 public Boolean apply(AppiumDriver<?> drv) {2798 return (boolean) ((JavascriptExecutor) drv).executeScript("return (arguments[0].complete && typeof arguments[0].naturalWidth != \"undefined\" && arguments[0].naturalWidth > 0)", me);2799 }2800 });28012802 } catch (TimeoutException to) {2803 ss.assertTrue(false, "Image is broken.");2804 } finally {2805 System.out.format(" <waited %.2f seconds>%n", (System.currentTimeMillis() - start)/1000.0);2806 }28072808 }280928102811 /**2812 * Check for broken image.2813 */2814 @Step("Check for broken image.")2815 public void checkForBrokenImage(String propertyKey, int wait) {28162817 //waitForPageCompletelyLoaded();2818 me = confirmElementExistence(propertyKey, wait);28192820 System.out.format("[LOG]: <[%s:%s] checking up to %d seconds for broken image.>", this.id, this.testName, gc.defaultTimeOut);2821 double start = System.currentTimeMillis();2822 try {28232824 this.wait2825 .withTimeout(Duration.ofSeconds((long) gc.defaultTimeOut))2826 .until(new Function<AppiumDriver<?>, Boolean>() {2827 public Boolean apply(AppiumDriver<?> drv) {2828 return (boolean) ((JavascriptExecutor) drv).executeScript("return (arguments[0].complete && typeof arguments[0].naturalWidth != \"undefined\" && arguments[0].naturalWidth > 0)", me);2829 }2830 });28312832 } catch (TimeoutException to) {2833 ss.assertTrue(false, "Image is broken.");2834 } finally {2835 System.out.format(" <waited %.2f seconds>%n", (System.currentTimeMillis() - start)/1000.0);2836 }28372838 }283928402841 /**2842 * Populates text list from multi-element locator, compares against known text list (CSV, property key)2843 */2844 @Step("Confirm multi-element text.")2845 public void confirmMultiElementText(String propertyKey, String valueKey) {28462847 List<String> foundList = new ArrayList<String>();2848 List<String> expectedList = new ArrayList<String>();2849 List<MobileElement> meArray = new ArrayList<MobileElement>();2850 String[] values = null;28512852 meArray = confirmElementsExistence(propertyKey);2853 values = getPropertyValue(valueKey).split(",");2854 expectedList = Arrays.asList(values);28552856 for (MobileElement me: meArray) {2857 foundList.add(me.getText());2858 }28592860 StringBuilder sb = new StringBuilder();2861 sb.append("{");2862 for (String s: expectedList) {2863 sb.append(s+",");2864 }2865 sb.append("}:{");2866 for (String s: foundList) {2867 sb.append(s+",");2868 }2869 sb.append("}");28702871 System.out.format("[LOG]: <[%s:%s] comparing string lists: [%s]>%n", this.id, this.testName, sb.toString());2872 ss.assertTrue(expectedList.equals(foundList), "Lists differ.");2873 ss.takeScreenShot("Lists match.");28742875 }287628772878 /**2879 * Given a propertyKey resulting in a List of WebElements, and a comma-separated2880 * list of strings, compares per-element text with per-string text2881 *2882 * @param propertyKey (String) multi-locator property key (properties)2883 * @param valueKey (String) multi-text property key (properties)2884 */2885 @Step("Confirm multi-element text, element by element.")2886 public void confirmMultiElementTextByElement(String propertyKey, String valueKey) {28872888 List<String> foundList = new ArrayList<String>();2889 List<String> expectedList = new ArrayList<String>();2890 List<MobileElement> meArray = new ArrayList<MobileElement>();2891 String[] values = null;28922893 meArray = confirmElementsExistence(propertyKey);2894 values = getPropertyValue(valueKey).split(",");2895 expectedList = Arrays.asList(values);28962897 for (MobileElement me: meArray) {2898 foundList.add(me.getText());2899 }29002901 Iterator<String> found = foundList.listIterator();2902 Iterator<String> expected = expectedList.listIterator();2903 while (found.hasNext() && expected.hasNext()) {2904 String f = found.next();2905 String e = expected.next();2906 ss.assertTrue(f.contains(e), String.format("Found: %s; Expected: %s", f, e));2907 }2908 ss.takeScreenShot("Lists match.");29092910 }291129122913 /**2914 * Close current window2915 */2916 @Step("Close window.")2917 public void closeWindow() {29182919 this.driver.close();29202921 }292229232924 /**2925 * Takes an enum (Android software keyboard key code) and presses2926 *2927 * @param keyEnum2928 */2929 @Step("Press keyboard key.")2930 public void androidPressKey() {29312932 @SuppressWarnings("unchecked")2933 AndroidDriver<MobileElement> tempDrv = getMobileDriver(AndroidDriver.class);2934 tempDrv.pressKey(new KeyEvent(AndroidKey.ENTER));2935 tempDrv = null;29362937 }293829392940 /**2941 * Execute a boolean returning synchronous JavaScript snippet (fully defined)2942 *2943 * @param scriptKey (String) script reference (properties)2944 * @return (boolean) result of script execution as returned by JSE2945 */2946 @Step("Execute JavaScript snippet, boolean return.")2947 public boolean jseExecuteBoolean(String scriptKey) {29482949 String script = getPropertyValue(scriptKey);2950 System.out.format("[LOG]: <[%s:%s] executing script: %s;>%n", this.id, this.testName, scriptKey);2951 return (boolean) this.jse.executeScript(script);29522953 }295429552956 /**2957 * Execute a boolean returning synchronous JavaScript snippet (fully defined),2958 * respective some WebElement2959 *2960 * @param scriptKey (String) script reference (properties)2961 * @param propertyKey (String) locator (properties)2962 * @return (boolean) result of script execution as returned by JSE2963 */2964 @Step("Execute JavaScript snippet, boolean return.")2965 public boolean jseExecuteBoolean(String scriptKey, String propertyKey) {29662967 String script = getPropertyValue(scriptKey);2968 me = confirmElementExistence(propertyKey);2969 System.out.format("[LOG]: <[%s:%s] executing script: %s; against element: %s;>%n", this.id, this.testName, scriptKey, propertyKey);2970 return (boolean) this.jse.executeScript(script, me);29712972 }297329742975 /**2976 * Execute a boolean returning synchronous JavaScript snippet (fully defined),2977 * respective some WebElement2978 *2979 * @param scriptKey (String) script reference (properties)2980 * @param we (WebElement) selenium element2981 * @return (boolean) result of script execution as returned by JSE2982 */2983 @Step("Execute JavaScript snippet, boolean return.")2984 public boolean jseExecuteBoolean(String scriptKey, MobileElement me) {29852986 String script = getPropertyValue(scriptKey);2987 System.out.format("[LOG]: <[%s:%s] executing script: %s; against dynamic element.>%n", this.id, this.testName, scriptKey);2988 return (boolean) this.jse.executeScript(script, me);29892990 }299129922993 /**2994 * Execute a integer returning synchronous JavaScript snippet (fully defined)2995 *2996 * @param scriptKey (String) script reference (properties)2997 * @return (int) result of script execution as returned by JSE2998 */2999 @Step("Execute JavaScript snippet, integer return.")3000 public int jseExecuteInteger(String scriptKey) {30013002 String script = getPropertyValue(scriptKey);3003 System.out.format("[LOG]: <[%s:%s] executing script: %s;>%n", this.id, this.testName, scriptKey);3004 return (int) (long) this.jse.executeScript(script);30053006 }300730083009 /**3010 * Execute a integer returning synchronous JavaScript snippet (fully defined),3011 * respective some WebElement3012 *3013 * @param scriptKey (String) script reference (properties)3014 * @param propertyKey (String) locator (properties)3015 * @return (int) result of script execution as returned by JSE3016 */3017 @Step("Execute JavaScript snippet, integer return.")3018 public int jseExecuteInteger(String scriptKey, String propertyKey) {30193020 String script = getPropertyValue(scriptKey);3021 me = confirmElementExistence(propertyKey);3022 System.out.format("[LOG]: <[%s:%s] executing script: %s; against element: %s;>%n", this.id, this.testName, scriptKey, propertyKey);3023 return (int) (long) this.jse.executeScript(script, me);30243025 }302630273028 /**3029 * Execute a integer returning synchronous JavaScript snippet (fully defined),3030 * respective some WebElement3031 *3032 * @param scriptKey (String) script reference (properties)3033 * @param we (WebElement) selenium element3034 * @return (int) result of script execution as returned by JSE3035 */3036 @Step("Execute JavaScript snippet, integer return.")3037 public int jseExecuteInteger(String scriptKey, MobileElement me) {30383039 String script = getPropertyValue(scriptKey);3040 System.out.format("[LOG]: <[%s:%s] executing script: %s; against dynamic element.>%n", this.id, this.testName, scriptKey);3041 return (int) (long) this.jse.executeScript(script, me);30423043 }304430453046 /**3047 * Execute a String returning synchronous JavaScript snippet (fully defined)3048 *3049 * @param scriptKey (String) script reference (properties)3050 * @return (String) result of script execution as returned by JSE3051 */3052 @Step("Execute JavaScript snippet, string return.")3053 public String jseExecuteString(String scriptKey) {30543055 String script = getPropertyValue(scriptKey);3056 System.out.format("[LOG]: <[%s:%s] executing script: %s;>%n", this.id, this.testName, scriptKey);3057 return (String) this.jse.executeScript(script);30583059 }306030613062 /**3063 * Execute a String returning synchronous JavaScript snippet (fully defined),3064 * respective some WebElement3065 *3066 * @param scriptKey (String) script reference (properties)3067 * @param propertyKey (String) locator (properties)3068 * @return (String) result of script execution as returned by JSE3069 */3070 @Step("Execute JavaScript snippet, string return.")3071 public String jseExecuteString(String scriptKey, String propertyKey) {30723073 String script = getPropertyValue(scriptKey);3074 me = confirmElementExistence(propertyKey);3075 System.out.format("[LOG]: <[%s:%s] executing script: %s; against element: %s;>%n", this.id, this.testName, scriptKey, propertyKey);3076 return (String) this.jse.executeScript(script, me);30773078 }307930803081 /**3082 * Execute a String returning synchronous JavaScript snippet (fully defined),3083 * respective some WebElement3084 *3085 * @param scriptKey (String) script reference (properties)3086 * @param we (WebElement) selenium element3087 * @return (String) result of script execution as returned by JSE3088 */3089 @Step("Execute JavaScript snippet, string return.")3090 public String jseExecuteString(String scriptKey, MobileElement me) {30913092 String script = getPropertyValue(scriptKey);3093 System.out.format("[LOG]: <[%s:%s] executing script: %s; against dynamic element.>%n", this.id, this.testName, scriptKey);3094 return (String) this.jse.executeScript(script, me);30953096 }309730983099 /**3100 * Execute a synchronous JavaScript snippet (fully defined)3101 *3102 * @param scriptKey (String) script reference (properties)3103 */3104 @Step("Execute JavaScript snippet, no return.")3105 public void jseExecuteVoid(String scriptKey) {31063107 String script = getPropertyValue(scriptKey);3108 System.out.format("[LOG]: <[%s:%s] executing script: %s;>%n", this.id, this.testName, scriptKey);3109 this.jse.executeScript(script);31103111 }311231133114 /**3115 * Execute a synchronous JavaScript snippet (fully defined),3116 * respective some WebElement3117 *3118 * @param scriptKey (String) script reference (properties)3119 * @param propertyKey (String) locator (properties)3120 */3121 @Step("Execute JavaScript snippet, no return.")3122 public void jseExecuteVoid(String scriptKey, String propertyKey) {31233124 String script = getPropertyValue(scriptKey);3125 me = confirmElementExistence(propertyKey);3126 System.out.format("[LOG]: <[%s:%s] executing script: %s; against element: %s;>%n", this.id, this.testName, scriptKey, propertyKey);3127 this.jse.executeScript(script, me);31283129 }313031313132 /**3133 * Execute a synchronous JavaScript snippet (fully defined),3134 * respective some WebElement3135 *3136 * @param scriptKey (String) script reference (properties)3137 * @param we (WebElement) locator (properties)3138 */3139 @Step("Execute JavaScript snippet, no return.")3140 public void jseExecuteVoid(String scriptKey, MobileElement me) {31413142 String script = getPropertyValue(scriptKey);3143 System.out.format("[LOG]: <[%s:%s] executing script: %s; against dynamic element.>%n", this.id, this.testName, scriptKey);3144 this.jse.executeScript(script, me);31453146 }314731483149 /**3150 * Confirm the selection state of a target dropdown menu widget (runtimeData)3151 *3152 * @param propertyKey (String) locator properties key3153 * @param runtimeValue (String) value from runtimeData/GlobalConstants3154 */3155 @Step("Confirm dropdown selected value.")3156 public void confirmDynamicDropdownValue(String propertyKey, String runtimeValue) {31573158 waitForPageLoaded();3159 Select sel = new Select(confirmElementExistence(propertyKey));3160 ss.assertTrue(sel.getFirstSelectedOption().getText().toLowerCase().equals(runtimeValue.toLowerCase()));31613162 }316331643165 /**3166 * Confirm the selection state of a target dropdown menu widget (properties)3167 *3168 * @param propertyKey (String) locator properties key3169 * @param valueKey (String) option to set properties key3170 */3171 @Step("Confirm dropdown selected value.")3172 public void confirmStaticDropdownValue(String propertyKey, String valueKey) {31733174 waitForPageLoaded();3175 String value = getPropertyValue(valueKey);3176 Select sel = new Select(confirmElementExistence(propertyKey));3177 ss.assertTrue(sel.getFirstSelectedOption().getText().toLowerCase().equals(value.toLowerCase()));31783179 }31803181 /**3182 * Grab the current instance of 'driver' to use for methods in 'PageObjects'3183 *3184 */3185 @Step("Return the current instance of 'driver'")3186 public RemoteWebDriver returnDriver() {31873188 return this.driver;31893190 }3191 ...

Full Screen

Full Screen

Source:Generic.java Github

copy

Full Screen

...1037 }103810391040 /**1041 * Asserts page title equals target value1042 *1043 * @param propertyKey (String) properties file key defining string1044 */1045 @Step("Confirm page title.")1046 public void confirmTitle(String propertyKey) {10471048 ss.assertTrue(driver.getTitle().toLowerCase().equals(getPropertyValue(propertyKey)));10491050 }10511052 /**1053 * Scrolls down1054 *1055 */1056 @Step("Scroll down on the window.")1057 public void scrollDown() {10581059 JavascriptExecutor js = (JavascriptExecutor) driver;1060 js.executeScript("window.scrollBy(0,250)");10611062 }106310641065 /**1066 * Scroll to an element, direction independent1067 *1068 * @param propertyKey (String) properties file key defining string1069 */1070 public WebElement smartScroll(String propertyKey) {10711072 this.we = confirmElementExistence(propertyKey);1073 int currentY = 0;1074 int currentX = 0;1075 int afterY = 100000;1076 int afterX = 100000;10771078 System.out.format("[LOG]: <[%s:%s] scrolling to element: %s; ", this.id, this.testName, propertyKey);1079 // move to element until moving no longer changes position. in general, the move is instantaneous1080 do {1081 currentY = (int) (long) this.jse.executeScript("return window.pageYOffset;");1082 currentX = (int) (long) this.jse.executeScript("return window.pageXOffset;");1083 System.out.format("(%d,%d) -> ", currentX, currentY);10841085 this.jse.executeScript("return arguments[0].scrollIntoView(true);", this.we);10861087 afterY = (int) (long) this.jse.executeScript("return window.pageYOffset;");1088 afterX = (int) (long) this.jse.executeScript("return window.pageXOffset;");1089 System.out.format("(%d,%d)", afterX, afterY);1090 } while ((Math.abs(currentY - afterY) != 0) && (Math.abs(currentX - afterX) != 0));10911092 System.out.format(";>%n" );1093 return this.we;10941095 }109610971098 /**1099 * Scroll to an element, direction independent1100 *1101 * @param w (WebElement)1102 */1103 public WebElement smartScroll(WebElement w) {11041105 int currentY = 0;1106 int currentX = 0;1107 int afterY = 100000;1108 int afterX = 100000;11091110 System.out.format("[LOG]: <[%s:%s] scrolling to element: ", this.id, this.testName);1111 // move to element until moving no longer changes position. in general, the move is instantaneous1112 do {1113 currentY = (int) (long) this.jse.executeScript("return window.pageYOffset;");1114 currentX = (int) (long) this.jse.executeScript("return window.pageXOffset;");1115 System.out.format("(%d,%d) -> ", currentX, currentY);11161117 this.jse.executeScript("return arguments[0].scrollIntoView(true);", w);11181119 afterY = (int) (long) this.jse.executeScript("return window.pageYOffset;");1120 afterX = (int) (long) this.jse.executeScript("return window.pageXOffset;");1121 System.out.format("(%d,%d)", afterX, afterY);1122 } while ((Math.abs(currentY - afterY) != 0) && (Math.abs(currentX - afterX) != 0));11231124 System.out.format(";>%n" );1125 return w;11261127 }112811291130 /**1131 * Scrolls up1132 * @Param pixelX (int)1133 * @Param pixelY (int)1134 */1135 @Step("Scroll up on the window.")1136 public void scrollUp(int pixelX, int pixelY) {11371138 jse.executeScript("window.scrollBy(argumets[0], -1*arguments[1])", pixelX, pixelY); // aug[0], arg[1]11391140 }11411142 /**1143 * Scrolls down1144 * @Param pixelX (int)1145 * @Param pixelY (int)1146 */1147 @Step("Scroll down on the window.")1148 public void scrollDown(int pixelX, int pixelY) {11491150 jse.executeScript("window.scrollBy(argumets[0], arguments[1])", pixelX, pixelY);11511152 }11531154 /**1155 * Scrolls up1156 *1157 */1158 @Step("Scroll up on the window.")1159 public void scrollUp() {11601161 jse.executeScript("window.scrollBy(0,-250)");11621163 }116411651166 /**1167 * Navigates browser to target URL1168 *1169 * @param propertyKey (String) properties file key defining string1170 */1171 @Step("Navigate to URL.")1172 public void getUrl(String propertyKey) {11731174 driver.get(getPropertyValue(propertyKey));1175 waitForPageLoaded();1176 ss.takeScreenShot("After navigation to URL.");11771178 }117911801181 /**1182 * Navigates to target URL (runtimeData)1183 *1184 * @param runtimeValue (String) value from runtimeData/GlobalConstants1185 */1186 @Step("Navigate to URL.")1187 public void getUrl(String[] runtimeValue) {11881189 driver.get(runtimeValue[0]);1190 waitForPageLoaded();1191 ss.takeScreenShot("After navigation to URL.");11921193 }119411951196 /**1197 * Retrieves locator definition and type from WebElement property definition1198 *1199 * @param propertyKey (String) properties file key defining element locator1200 * @return (String[]) containing locator definition and locator type1201 */1202 private String[] locatorElementAndMethod(String propertyKey) {12031204 //System.out.format("[DEBUG]: <[%s:%s] key: %s>%n", this.id, this.testName, propertyKey);1205 command = null;1206 String propertyValue = null;12071208 //System.out.format("[DEBUG]: <[%s:%s] key found?: %b>%n", this.id, this.testName, this.props.containsKey(propertyKey));1209 ss.assertTrue(props.containsKey(propertyKey), "Property key \""+propertyKey+"\" not found");1210 propertyValue = this.props.getProperty(propertyKey);1211 //System.out.format("[DEBUG]: <[%s:%s] key value: %s>%n", this.id, this.testName, propertyValue);1212 command = propertyValue.split(gc.locatorSeparator);1213 // System.out.format("[DEBUG]: <[%s:%s] command length: %d>%n", this.id, this.testName, command.length);121412151216 return command;12171218 }121912201221 /**1222 * Return String value of non-WebElement property definition1223 *1224 * @param propertyKey (String) properties file key defining string1225 * @return (String) value of property1226 */1227 public String getPropertyValue(String propertyKey) {12281229 // System.out.format("[DEBUG]: <[%s:%s] key: %s>%n", this.id, this.testName, propertyKey);1230 command = null;1231 String propertyValue = null;12321233 ss.assertTrue(props.containsKey(propertyKey), "Property key \""+propertyKey+"\" not found");1234 // System.out.format("[DEBUG]: <[%s:%s] key found?: %b>%n", this.id, this.testName, props.containsKey(propertyKey));12351236 propertyValue = props.getProperty(propertyKey);1237 // System.out.format("[DEBUG]: <[%s:%s] key value: %s>%n", this.id, this.testName, propertyValue);123812391240 return propertyValue;12411242 }124312441245 /**1246 * Inserts string into target element1247 *1248 * @param propertyKey (String) properties file key defining element locator1249 * @param input (String) text to enter into target element1250 */1251 @Step("Input text.")1252 public void sendText(String propertyKey, String input) {12531254 we = confirmElementExistence(propertyKey);1255 we.clear();1256 we.sendKeys(input);1257 ss.takeScreenShot("After input");12581259 }126012611262 /**1263 * Inserts string into target element1264 *1265 * @param we (WebElement) selenium text field1266 * @param input (String) text to enter into target element1267 */1268 @Step("Input text.")1269 public void sendText(WebElement we, String input) {12701271 we.clear();1272 we.sendKeys(input);1273 ss.takeScreenShot("After input");12741275 }127612771278 /**1279 * Inserts string into target element1280 *1281 * @param propertyKey (String) properties file key defining element locator1282 * @param input (String) text to enter into target element1283 * @param takeSS (boolean) trigger to take a screenshot1284 */1285 @Step("Input text.")1286 public void sendText(String propertyKey, String input, boolean takeSS) {12871288 we = confirmElementExistence(propertyKey);1289 we.clear();1290 we.sendKeys(input);12911292 if (takeSS) {1293 ss.takeScreenShot("After input");1294 }12951296 }129712981299 /**1300 * Inserts string into target element1301 *1302 * @param we (WebElement) selenium text field1303 * @param input (String) text to enter into target element1304 * @param takeSS (boolean) trigger to take a screenshot1305 */1306 @Step("Input text.")1307 public void sendText(WebElement we, String input, boolean takeSS) {13081309 we.clear();1310 we.sendKeys(input);13111312 if (takeSS) {1313 ss.takeScreenShot("After input");1314 }13151316 }131713181319 /**1320 * Manually trigger a screenshot1321 *1322 * @param description (String) describing screenshot to be taken1323 */1324 @Step("Take Screenshot: {0}.")1325 public void takeScreenShot(String description) {13261327 ss.takeScreenShot(description);13281329 }133013311332 /**1333 * After confirming element existence, clicks element.1334 *1335 * @param propertyKey (String) properties file key defining element locator1336 */1337 @Step("Click element.")1338 public void clickElement(String propertyKey) {13391340 we = confirmElementExistence(propertyKey);1341 System.out.format("[LOG]: <[%s:%s] clicking element with property key: \"%s\">%n", this.id, this.testName, propertyKey);1342 we.click();1343 waitForPageCompletelyLoaded();13441345 }134613471348 /**1349 * After confirming element existence, clicks element.1350 *1351 * @param wel (WebElement) selenium web element1352 */1353 @Step("Click element.")1354 public void clickElement(WebElement wel) {13551356 System.out.format("[LOG]: <[%s:%s] clicking element>%n", this.id, this.testName);1357 wel.click();1358 waitForPageLoaded();13591360 }136113621363 /**1364 * After confirming element existence, clicks element.1365 *1366 * @param propertyKey (String) properties file key defining element locator1367 */1368 @Step("Click element.")1369 public void clickElement(String propertyKey, int timeOut) {13701371 we = confirmElementExistence(propertyKey);1372 System.out.format("[LOG]: <[%s:%s] clicking element with property key: \"%s\">%n", this.id, this.testName, propertyKey);1373 we.click();1374 waitForPageCompletelyLoaded(timeOut);13751376 }137713781379 /**1380 * After confirming dynamic element existence, clicks element.1381 *1382 * @param propertyKey (String) properties file key defining element locator1383 * @param replacement (String) compound locator replacement1384 */1385 @Step("Click dynamic element.")1386 public void clickElement(String propertyKey, String replacement) {13871388 we = confirmElementExistence(propertyKey, replacement);1389 System.out.format("[LOG]: <[%s:%s] clicking element with property key: \"%s\">%n", this.id, this.testName, propertyKey);1390 we.click();1391 waitForPageLoaded();13921393 }139413951396 /**1397 * Asserts element exists, includes custom error message1398 *1399 * @param propertyKeyCustomError (String[]) properties file key defining element locator, custom error message1400 * @return (WebElement)1401 */1402 @Step("Confirm element exists.")1403 public WebElement confirmElementExistence(String[] propertyKeyCustomError) {14041405 ss.assertTrue((we = waitForElement(propertyKeyCustomError[0])) instanceof WebElement, propertyKeyCustomError[1]);1406 return we;14071408 }140914101411 /**1412 * Asserts element can be found within default time constraint1413 *1414 * @param propertyKey (String) properties file key defining element locator1415 * @return (WebElement)1416 */1417 @Step("Confirm element exists.")1418 public WebElement confirmElementExistence(String propertyKey) {14191420 ss.assertTrue((we = waitForElement(propertyKey)) instanceof WebElement, "Element could not be located.");1421 return we;14221423 }142414251426 /**1427 * Asserts element can be found within default time constraint1428 *1429 * @param propertyKey (String) properties file key defining element locator1430 * @return (WebElement)1431 */1432 @Step("Confirm element exists.")1433 public WebElement confirmElementExistenceOrNone(String propertyKey, int maxWait) {14341435 return we = waitForElement(propertyKey, maxWait);14361437 }143814391440 /**1441 * Asserts element can be found within time constraint1442 *1443 * @param propertyKey (String) properties file key defining element locator1444 * @param maxWait (int) maximum time in seconds to wait for element1445 * @return (WebElement)1446 */1447 @Step("Confirm element exists within {maxWait} seconds.")1448 public WebElement confirmElementExistence(String propertyKey, int maxWait) {14491450 ss.assertTrue((we = waitForElement(propertyKey, maxWait)) instanceof WebElement, "Element could not be located.");1451 return we;14521453 }145414551456 /**1457 * Asserts element can be found within time constraint1458 *1459 * @param propertyKey (String) properties file key defining element locator1460 * @param maxWait (int) maximum time in seconds to wait for element1461 * @return (WebElement)1462 */1463 @Step("Confirm element exists within {maxWait} seconds.")1464 public WebElement confirmElementExistence(String propertyKey, int maxWait, int polling) {14651466 ss.assertTrue((we = waitForElement(propertyKey, maxWait, polling)) instanceof WebElement, "Element could not be located.");1467 return we;14681469 }147014711472 /**1473 * Asserts compound element can be found within default time constraint1474 *1475 * @param propertyKey (String) properties file key defining element locator1476 * @param replacement (String) value to replace placeholder1477 * @return (WebElement)1478 */1479 @Step("Confirm dynamic element exists.")1480 public WebElement confirmElementExistence(String propertyKey, String replacement) {14811482 ss.assertTrue((we = waitForElement(propertyKey, replacement)) instanceof WebElement, "Element could not be located.");1483 return we;14841485 }148614871488 /**1489 * Asserts compound element can be found within time constraint1490 *1491 * @param propertyKey (String) properties file key defining element locator1492 * @param replacement (String) value to replace placeholder1493 * @param maxWait (int) maximum time in seconds to wait for element1494 * @return (WebElement)1495 */1496 @Step("Confirm dynamic element exists within {maxWait} seconds.")1497 public WebElement confirmElementExistence(String propertyKey, String replacement, int maxWait) {14981499 ss.assertTrue((we = waitForElement(propertyKey, replacement, maxWait)) instanceof WebElement, "Element could not be located.");1500 return we;15011502 }150315041505 /**1506 * Asserts element can be found relative to parent element1507 *1508 * @param parentElement (WebElement)1509 * @param propertyKey (String)1510 * @return (WebElement)1511 */1512 @Step("Confirm dynamic element exists within 30 seconds.")1513 public WebElement confirmElementExistence(WebElement parentElement, String propertyKey) {15141515 ss.assertTrue((we = waitForElement(parentElement, propertyKey)) instanceof WebElement, "Element could not be located.");1516 return we;15171518 }151915201521 /**1522 * Asserts one or more elements can be found within default time constraint, includes custom error message1523 *1524 * @param propertyKeyCustomError (String[]) properties file key defining element locator, custom error messsage1525 * @return (List<WebElement>)1526 */1527 @Step("Confirm element(s) exist.")1528 public List<WebElement> confirmElementsExistence(String[] propertyKeyCustomError) {15291530 ss.assertTrue(null != (weArray = waitForElements(propertyKeyCustomError[0])), propertyKeyCustomError[1]);1531 int size = weArray.size();1532 ss.assertTrue(size > 0, propertyKeyCustomError[1]);1533 return weArray;15341535 }153615371538 /**1539 * Asserts one or more element(s) can be found within default time constraint1540 *1541 * @param propertyKey (String) properties file key defining element locator1542 * @return (List<WebElement>)1543 */1544 @Step("Confirm element(s) exist.")1545 public List<WebElement> confirmElementsExistence(String propertyKey) {15461547 ss.assertTrue(null != (weArray = waitForElements(propertyKey)), "One or more Elements could not be located.");1548 int size = weArray.size();1549 ss.assertTrue(size > 0, "One or more Elements could not be located.");1550 return weArray;15511552 }155315541555 /**1556 * Asserts zero or more element(s) can be found within default time constraint1557 *1558 * @param propertyKey (String) properties file key defining element locator1559 * @return (List<WebElement>)1560 */1561 @Step("Confirm element(s) exist.")1562 public List<WebElement> confirmElementsExistenceOrNone(String propertyKey) {15631564 ss.assertTrue(null != (weArray = waitForElements(propertyKey)), "One or more Elements could not be located.");1565 int size = weArray.size();1566 ss.assertTrue(size >= 0, "One or more Elements could not be located.");1567 return weArray;15681569 }157015711572 /**1573 * Asserts one or more element(s) can be found within time constraint1574 *1575 * @param propertyKey (String) properties file key defining element locator1576 * @param maxWait (int) maximum time in seconds to wait for element1577 * @return (List<WebElement>)1578 */1579 @Step("Confirm element(s) exist within {maxWait} seconds.")1580 public List<WebElement> confirmElementsExistence(String propertyKey, int maxWait) {15811582 ss.assertTrue(null != (weArray = waitForElements(propertyKey, maxWait)), "One or more Elements could not be located.");1583 int size = weArray.size();1584 ss.assertTrue(size > 0, "One or more Elements could not be located.");1585 return weArray;15861587 }158815891590 /**1591 * Asserts one or more element(s) can be found within time constraint1592 *1593 * @param propertyKey (String) properties file key defining element locator1594 * @param w (WebElement)1595 * @return (List<WebElement>)1596 */1597 @Step("Confirm element(s) exist within {maxWait} seconds.")1598 public List<WebElement> confirmElementsExistence(WebElement w, String propertyKey) {15991600 ss.assertTrue(null != (weArray = waitForElements(w, propertyKey)), "One or more Elements could not be located.");1601 int size = weArray.size();1602 ss.assertTrue(size > 0, "One or more Elements could not be located.");1603 return weArray;16041605 }160616071608 /**1609 * Asserts compound element(s) can be found within default time constraint1610 *1611 * @param propertyKey (String) properties file key defining element locator1612 * @param replacement (String) value to replace placeholder1613 * @return (List<WebElement>)1614 */1615 @Step("Confirm dynamic element(s) exist.")1616 public List<WebElement> confirmElementsExistence(String propertyKey, String replacement) {16171618 ss.assertTrue(null != (weArray = waitForElements(propertyKey, replacement)), "One or more Elements could not be located.");1619 int size = weArray.size();1620 ss.assertTrue(size > 0, "One or more Elements could not be located.");1621 return weArray;16221623 }162416251626 /**1627 * Asserts one or more compound element(s) can be found within time constraint1628 *1629 * @param propertyKey (String) properties file key defining element locator1630 * @param replacement (String) value to replace placeholder1631 * @param maxWait (int) maximum time in seconds to wait for element1632 * @return (List<WebElement>)1633 */1634 @Step("Confirm dynamic element(s) exist within {maxWait} seconds.")1635 public List<WebElement> confirmElementsExistence(String propertyKey, String replacement, int maxWait) {16361637 ss.assertTrue(null != (weArray = waitForElements(propertyKey, replacement, maxWait)), "One or more Elements could not be located.");1638 int size = weArray.size();1639 ss.assertTrue(size > 0, "One or more Elements could not be located.");1640 return weArray;16411642 }164316441645 /**1646 * Asserts zero or more element(s) can be found within default time constraint1647 *1648 * @param propertyKey (String) properties file key defining element locator1649 * @return (List<WebElement>)1650 */1651 @Step("Confirm element(s) exist.")1652 public List<WebElement> confirmElementsExistenceOrNone(WebElement w, String propertyKey) {16531654 ss.assertTrue(null != (weArray = waitForElements(w, propertyKey)), "One or more Elements could not be located.");1655 int size = weArray.size();1656 ss.assertTrue(size >= 0, "One or more Elements could not be located.");1657 return weArray;16581659 }166016611662 /**1663 * Asserts element cannot be found within default time constraint1664 *1665 * @param propertyKeyCustomError (String[]) properties file key defining element locator, custom error message1666 */1667 @Step("Confirm element does not exist.")1668 public void confirmElementNonExistence(String[] propertyKeyCustomError) {16691670 ss.assertFalse(waitForElementNotFound(propertyKeyCustomError[0]) instanceof WebElement, propertyKeyCustomError[1]);16711672 }167316741675 /**1676 * Asserts element cannot be found within default time constraint1677 *1678 * @param propertyKey (String) properties file key defining element locator167916801681 */1682 @Step("Confirm element does not exist.")1683 public void confirmElementNonExistence(String propertyKey) {16841685 ss.assertFalse(waitForElementNotFound(propertyKey) instanceof WebElement, "Persistent element located unexpectedly.");16861687 }168816891690 /**1691 * Asserts element cannot be found within time constraint1692 *1693 * @param propertyKey (String) properties file key defining element locator1694 * @param maxWait (int) maximum time in seconds to wait for element1695 */1696 @Step("Confirm element does not exist within {maxWait} seconds.")1697 public void confirmElementNonExistence(String propertyKey, int maxWait) {16981699 ss.assertFalse(waitForElementNotFound(propertyKey, maxWait) instanceof WebElement, "Persistent element located unexpectedly.");17001701 }170217031704 /**1705 * Asserts compound element cannot be found within default time constraint1706 *1707 * @param propertyKey (String) properties file key defining element locator1708 * @param replacement (String) value to replace placeholder1709 */1710 @Step("Confirm dynamic element does not exist.")1711 public void confirmElementNonExistence(String propertyKey, String replacement) {17121713 ss.assertFalse(waitForElementNotFound(propertyKey, replacement) instanceof WebElement, "Persistent element located unexpectedly.");17141715 }171617171718 /**1719 * Asserts compound element cannot be found within time constraint1720 *1721 * @param propertyKey (String) properties file key defining element locator1722 * @param replacement (String) value to replace placeholder1723 * @param maxWait (int) maximum time in seconds to wait for element1724 */1725 @Step("Confirm dynamic element does not exist within {maxWait} seconds.")1726 public void confirmElementNonExistence(String propertyKey, String replacement, int maxWait) {17271728 ss.assertFalse(waitForElementNotFound(propertyKey, replacement, maxWait) instanceof WebElement, "Persistent element located unexpectedly.");17291730 }173117321733 /**1734 * Asserts element cannot be found within default time constraint, including custom error message1735 *1736 * @param propertyKeyCustomError (String[]) properties file key defining element locator, custom error message1737 */1738 @Step("Confirm element(s) do not exist.")1739 public void confirmElementsNonExistence(String[] propertyKeyCustomError) {17401741 ss.assertFalse(waitForElementsNotFound(propertyKeyCustomError[0]) instanceof List<?>, propertyKeyCustomError[1]);17421743 }174417451746 /**1747 * Asserts one or more element(s) cannot be found within default time constraint1748 *1749 * @param propertyKey (String) properties file key defining element locator1750 */1751 @Step("Confirm element(s) do not exist.")1752 public void confirmElementsNonExistence(String propertyKey) {17531754 ss.assertFalse(waitForElementsNotFound(propertyKey) instanceof List<?>, "Persistent element(s) located unexpectedly.");17551756 }175717581759 /**1760 * Asserts one or more element(s) cannot be found within time constraint1761 *1762 * @param propertyKey (String) properties file key defining element locator1763 * @param maxWait (int) maximum time in seconds to wait for element1764 */1765 @Step("Confirm element(s) do not exist within {maxWait} seconds.")1766 public void confirmElementsNonExistence(String propertyKey, int maxWait) {17671768 ss.assertFalse(waitForElementsNotFound(propertyKey, maxWait) instanceof List<?>, "Persistent element(s) located unexpectedly.");17691770 }177117721773 /**1774 * Asserts one or more compound element(s) cannot be found within default time constraint1775 *1776 * @param propertyKey (String) properties file key defining element locator1777 * @param replacement (String) value to replace placeholder1778 */1779 @Step("Confirm dynamic element(S) do not exist.")1780 public void confirmElementsNonExistence(String propertyKey, String replacement) {17811782 ss.assertFalse(waitForElementsNotFound(propertyKey, replacement) instanceof List<?>, "Persistent element(s) located unexpectedly.");17831784 }178517861787 /**1788 * Asserts one or more compound element(s) cannot be found within time constraint1789 *1790 * @param propertyKey (String) properties file key defining element locator1791 * @param replacement (String) value to replace placeholder1792 * @param maxWait (int) maximum time in seconds to wait for element1793 */1794 @Step("Confirm dynamic element(s) do not exist within {maxWait} seconds.")1795 public void confirmElementsNonExistence(String propertyKey, String replacement, int maxWait) {17961797 ss.assertFalse(waitForElementsNotFound(propertyKey, replacement, maxWait) instanceof List<?>, "Persistent element(s) located unexpectedly.");17981799 }180018011802 /**1803 * Given a generic locator (includes placeholder string), replace placeholder1804 * string with desired string1805 *1806 * @param locator (String) properties file key defining element locator1807 * @param replacement (String) to replace placeholder1808 * @return (String) locator as rebuilt1809 */1810 // @Step("Build dynamic locator.")1811 private String buildDynamicLocator(String locator, String replacement) {18121813 return locator.replaceAll(gc.compoundLocatorPlaceholder, replacement);18141815 }181618171818 /**1819 * Waits up to 30s for the browser JavaScript engine to report standby.1820 *1821 */1822 @Step("Wait for page to load.")1823 public void waitForPageLoaded() {18241825 double start = System.currentTimeMillis();1826 System.out.format("[LOG]: <[%s:%s] waiting up to %d seconds for page to load.>", this.id, this.testName, gc.defaultTimeOut);18271828 try {18291830 this.wait1831 .withTimeout(Duration.ofSeconds((long) gc.defaultTimeOut))1832 .until(new Function<RemoteWebDriver, Boolean>() {1833 public Boolean apply(RemoteWebDriver drv) {1834 return ( ((JavascriptExecutor) drv).executeScript("return document.readyState").equals("complete") ||1835 ((JavascriptExecutor) drv).executeScript("return document.readyState").equals("interactive") );1836 }1837 });18381839 } catch (TimeoutException to) {1840 System.out.format(" <timed out: unexpected>");18411842 } finally {1843 System.out.format(" <waited %.2f seconds>%n", (System.currentTimeMillis() - start)/1000.0);1844 }18451846 }184718481849 /**1850 * Waits up to timeOut seconds for the browser JavaScript engine to report standby.18511852 *1853 * @param timeOut (int) maximum seconds to wait1854 */1855 @Step("Wait for page to load.")1856 public void waitForPageLoaded(int timeOut) {18571858 double start = System.currentTimeMillis();1859 System.out.format("[LOG]: <[%s:%s] waiting up to %d seconds for page to load.>", this.id, this.testName, timeOut);18601861 try {18621863 this.wait1864 .withTimeout(Duration.ofSeconds((long) timeOut))1865 .until(new Function<RemoteWebDriver, Boolean>() {1866 public Boolean apply(RemoteWebDriver drv) {1867 return ( ((JavascriptExecutor) drv).executeScript("return document.readyState").equals("complete") ||1868 ((JavascriptExecutor) drv).executeScript("return document.readyState").equals("interactive") );1869 }1870 });18711872 } catch (TimeoutException to) {1873 System.out.format(" <timed out: unexpected>");18741875 } finally {1876 System.out.format(" <waited %.2f seconds>%n", (System.currentTimeMillis() - start)/1000.0);1877 }18781879 }188018811882 /**1883 * Waits up to timeOut seconds for the browser JavaScript engine to report completed.1884 */1885 @Step("Wait for page to completely load.")1886 public void waitForPageCompletelyLoaded() {18871888 double start = System.currentTimeMillis();1889 System.out.format("[LOG]: <[%s:%s] waiting up to %d seconds for page to completely load.>", this.id, this.testName, gc.defaultTimeOut);18901891 try {1892 this.wait1893 .withTimeout(Duration.ofSeconds((long) gc.defaultTimeOut))1894 .until(new Function<RemoteWebDriver, Boolean>() {1895 public Boolean apply(RemoteWebDriver drv) {1896 return ( ((JavascriptExecutor) drv).executeScript("return document.readyState").equals("complete") );1897 }1898 });18991900 } catch (TimeoutException to) {1901 System.out.format(" <timed out: unexpected>");19021903 } finally {1904 System.out.format(" <waited %.2f seconds>%n", (System.currentTimeMillis() - start)/1000.0);1905 }19061907 }190819091910 /**1911 * Waits up to timeOut seconds for the browser JavaScript engine to report completed.1912 *1913 * @param timeOut (int) maximum seconds to wait1914 */1915 @Step("Wait for page to completely load.")1916 public void waitForPageCompletelyLoaded(int timeOut) {19171918 double start = System.currentTimeMillis();1919 System.out.format("[LOG]: <[%s:%s] waiting up to %d seconds for page to completely load.>", this.id, this.testName, timeOut);19201921 try {19221923 this.wait1924 .withTimeout(Duration.ofSeconds((long) timeOut))1925 .until(new Function<RemoteWebDriver, Boolean>() {1926 public Boolean apply(RemoteWebDriver drv) {1927 return ( ((JavascriptExecutor) drv).executeScript("return document.readyState").equals("complete") );1928 }1929 });19301931 } catch (TimeoutException to) {1932 System.out.format(" <timed out: unexpected>");19331934 } finally {1935 System.out.format(" <waited %.2f seconds>%n", (System.currentTimeMillis() - start)/1000.0);1936 }19371938 }193919401941 /**1942 * Waits up to timeOut seconds for the browser JavaScript engine to report completed.1943 *1944 * @param customMessage (String) custom logging message1945 */1946 @Step("Wait for page to completely load.")1947 public void waitForPageCompletelyLoaded(String customMessage) {19481949 double start = System.currentTimeMillis();1950 System.out.format("[LOG]: <[%s:%s] %s>", this.id, this.testName, customMessage);19511952 try {1953 this.wait1954 .withTimeout(Duration.ofSeconds((long) gc.defaultTimeOut))1955 .until(new Function<RemoteWebDriver, Boolean>() {1956 public Boolean apply(RemoteWebDriver drv) {1957 return ( ((JavascriptExecutor) drv).executeScript("return document.readyState").equals("complete") );1958 }1959 });19601961 } catch (TimeoutException to) {1962 System.out.format(" <timed out: unexpected>");19631964 } finally {1965 System.out.format(" <waited %.2f seconds>%n", (System.currentTimeMillis() - start)/1000.0);1966 }19671968 }196919701971 /**1972 * Waits for dropdown to be found. Once found, sets dropdown to target value (property key).1973 * Once set, confirms selection.1974 *1975 * @param propertyKey (String) locator properties key1976 * @param valueKey (String) option to set properties key1977 */1978 @Step("Set dropdown value.")1979 public void setDropdownByStaticValue(String propertyKey, String valueKey) {19801981 waitForPageLoaded();1982 Select sel = new Select(confirmElementExistence(propertyKey));1983 String value = getPropertyValue(valueKey);1984 List<WebElement> options = sel.getOptions();1985 boolean valueExists = false;19861987 for (WebElement we: options) {1988 if (we.getAttribute("value").toLowerCase().equals(value.toLowerCase())) {1989 valueExists = true;1990 break;1991 }1992 }19931994 if (valueExists) {1995 System.out.format("[LOG]: <[%s:%s] setting dropdown value to: \"%s\">%n", this.id, this.testName, value);1996 sel.selectByValue(value);1997 ss.assertTrue(new Select(confirmElementExistence(propertyKey)).getAllSelectedOptions().size() == 1, "Multiple selections unexpected.");1998 ss.assertTrue(new Select(confirmElementExistence(propertyKey)).getFirstSelectedOption().getAttribute("value").toLowerCase().equals(value.toLowerCase()), "Unable to confirm selection.");1999 ss.takeScreenShot("Dropdown set by value.");2000 } else {2001 // force a descriptive fail if value not found2002 ss.assertTrue(false, "Could not find value among options.");2003 }20042005 }200620072008 /**2009 * Waits for dropdown to be found. Once found, sets dropdown to target value (runtimeData).2010 * Once set, confirms selection.2011 *2012 * @param propertyKey (String) locator properties key2013 * @param runtimeValue (String) runtimeData value2014 */2015 @Step("Set dropdown by dynamic value.")2016 public void setDropdownByDynamicValue(String propertyKey, String runtimeValue) {20172018 waitForPageLoaded();2019 Select sel = new Select(confirmElementExistence(propertyKey));2020 List<WebElement> options = sel.getOptions();2021 boolean valueExists = false;20222023 for (WebElement we: options) {2024 if (we.getAttribute("value").toLowerCase().equals(runtimeValue.toLowerCase())) {2025 valueExists = true;2026 break;2027 }2028 }20292030 if (valueExists) {2031 System.out.format("[LOG]: <[%s:%s] setting dropdown value to: \"%s\">%n", this.id, this.testName, runtimeValue);2032 sel.selectByValue(runtimeValue);2033 ss.assertTrue(new Select(confirmElementExistence(propertyKey)).getAllSelectedOptions().size() == 1, "Multiple selections unexpected.");2034 ss.assertTrue(new Select(confirmElementExistence(propertyKey)).getFirstSelectedOption().getAttribute("value").toLowerCase().equals(runtimeValue.toLowerCase()), "Unable to confirm selection.");2035 ss.takeScreenShot("Dropdown set by value.");2036 } else {2037 // force a descriptive fail if value not found2038 ss.assertTrue(false, "Could not find value among options.");2039 }20402041 }204220432044 /**2045 * Waits for dropdown to be found. Once found, sets dropdown to target index (properties).2046 * Once set, confirms selection.2047 *2048 * @param propertyKey (String) locator properties key2049 * @param valueKey (String) value properties key2050 */2051 @Step("Set dropdown by static index.")2052 public void setDropdownByStaticIndex(String propertyKey, String valueKey) {20532054 waitForPageLoaded();2055 Select sel = new Select(confirmElementExistence(propertyKey));2056 int index = Integer.parseInt(getPropertyValue(valueKey));20572058 if (index < sel.getOptions().size()) {2059 System.out.format("[LOG]: <[%s:%s] setting dropdown value to index: %d>%n", this.id, this.testName, index);2060 String value = sel.getOptions().get(index).getAttribute("value");2061 sel.selectByIndex(index);2062 ss.assertTrue(new Select(confirmElementExistence(propertyKey)).getAllSelectedOptions().size() == 1, "Multiple selections unexpected.");2063 ss.assertTrue(new Select(confirmElementExistence(propertyKey)).getFirstSelectedOption().getAttribute("value").equals(value), "Unable to confirm selection.");2064 ss.takeScreenShot("Dropdown set by index.");2065 } else {2066 // force a descriptive fail if index is not appropriate2067 ss.assertTrue(false, "Index beyond allowable bounds.");2068 }20692070 }207120722073 /**2074 * Waits for dropdown to be found. Once found, sets dropdown to target index (properties).2075 * Once set, confirms selection.2076 *2077 * @param w (WebElement)2078 * @param valueKey (String)2079 */2080 @Step("Set dropdown by static index.")2081 public void setDropdownByStaticIndex(WebElement w, String valueKey) {20822083 waitForPageLoaded();2084 Select sel = new Select(w);2085 int index = Integer.parseInt(getPropertyValue(valueKey));20862087 if (index < sel.getOptions().size()) {2088 System.out.format("[LOG]: <[%s:%s] setting dropdown value to index: %d>%n", this.id, this.testName, index);2089 String value = sel.getOptions().get(index).getAttribute("value");2090 sel.selectByIndex(index);2091 ss.assertTrue(new Select(w).getAllSelectedOptions().size() == 1, "Multiple selections unexpected.");2092 ss.assertTrue(new Select(w).getFirstSelectedOption().getAttribute("value").equals(value), "Unable to confirm selection.");2093 ss.takeScreenShot("Dropdown set by index.");2094 } else {2095 // force a descriptive fail if index is not appropriate2096 ss.assertTrue(false, "Index beyond allowable bounds.");2097 }20982099 }210021012102 /**2103 * Waits for dropdown to be found. Once found, sets dropdown to target index (runtimeData).2104 * Once set, confirms selection.2105 *2106 * @param propertyKey (String) locator properties key2107 * @param runtimeIndex (int) target option index2108 */2109 @Step("Set dropdown by dynamic index.")2110 public void setDropdownByDynamicIndex(String propertyKey, String runtimeIndex) {21112112 waitForPageLoaded();2113 Select sel = new Select(confirmElementExistence(propertyKey));2114 int index = Integer.parseInt(runtimeIndex);21152116 if ( index < sel.getOptions().size()) {2117 System.out.format("[LOG]: <[%s:%s] setting dropdown value to index: %d>%n", this.id, this.testName, index);2118 String value = sel.getOptions().get(index).getAttribute("value");2119 sel.selectByIndex(index);2120 ss.assertTrue(new Select(confirmElementExistence(propertyKey)).getAllSelectedOptions().size() == 1, "Multiple selections unexpected.");2121 ss.assertTrue(new Select(confirmElementExistence(propertyKey)).getFirstSelectedOption().getAttribute("value").equals(value), "Unable to confirm selection.");2122 ss.takeScreenShot("Dropdown set by index.");2123 } else {2124 // force a descriptive fail if index is not appropriate2125 ss.assertTrue(false, "Index beyond allowable bounds.");2126 }21272128 }212921302131 /**2132 * Waits for dropdown to be found. Once found, sets dropdown to target index (int).2133 * Once set, confirms selection.2134 * <strong></strong>2135 *2136 * @param propertyKey (String) locator properties key2137 * @param index (int) target option index2138 * @deprecated NOT PREFERRED due to hard-coding dependency. use {@link #setDropdownByDynamicIndex(String, String)} where possible2139 */2140 @Step("Set dropdown by dynamic[hard] index.")2141 @Deprecated2142 public void setDropdownByDynamicIndex(String propertyKey, int index) {21432144 waitForPageLoaded();2145 Select sel = new Select(confirmElementExistence(propertyKey));21462147 if ( index < sel.getOptions().size()) {2148 System.out.format("[LOG]: <[%s:%s] setting dropdown value to index: %d>%n", this.id, this.testName, index);2149 String value = sel.getOptions().get(index).getAttribute("value");2150 sel.selectByIndex(index);2151 ss.assertTrue(new Select(confirmElementExistence(propertyKey)).getAllSelectedOptions().size() == 1, "Multiple selections unexpected.");2152 ss.assertTrue(new Select(confirmElementExistence(propertyKey)).getFirstSelectedOption().getAttribute("value").equals(value), "Unable to confirm selection.");2153 ss.takeScreenShot("Dropdown set by index[hard].");2154 } else {2155 // force a descriptive fail if index is not appropriate2156 ss.assertTrue(false, "Index beyond allowable bounds.");2157 }21582159 }216021612162 /**2163 * Waits for dropdown to be found. Once found, sets dropdown to target value (testReference).2164 * Once set, confirms selection.2165 *2166 * @param propertyKey (String) locator properties key2167 * @param valueKey (String) value properties key2168 */2169 @Step("Set dropdown static visible text value.")2170 public void setDropdownByStaticVisibleText(String propertyKey, String valueKey) {21712172 waitForPageLoaded();2173 Select sel = new Select(confirmElementExistence(propertyKey));2174 String visibleText = getPropertyValue(valueKey);2175 List<WebElement> options = sel.getOptions();2176 boolean valueExists = false;21772178 for (WebElement we: options) {2179 if (we.getText().toLowerCase().equals(visibleText.toLowerCase())) {2180 valueExists = true;2181 break;2182 }2183 }21842185 if (valueExists) {2186 System.out.format("[LOG]: <[%s:%s] setting dropdown value to: \"%s\">%n", id, testName, visibleText);2187 sel.selectByVisibleText(visibleText);2188 ss.assertTrue(new Select(confirmElementExistence(propertyKey)).getAllSelectedOptions().size() == 1, "Multiple selections unexpected.");2189 ss.assertTrue(new Select(confirmElementExistence(propertyKey)).getFirstSelectedOption().getText().toLowerCase().equals(visibleText.toLowerCase()), "Unable to confirm selection.");2190 ss.takeScreenShot("Dropdown set by visible text.");2191 } else {2192 // force a descriptive fail if no match2193 ss.assertTrue(false, "Could not find exact visible text match.");2194 }21952196 }219721982199 /**2200 * Waits for dropdown to be found. Once found, sets dropdown to target value (runtimeData).2201 * Once set, confirms selection.2202 *2203 * @param propertyKey (String) locator properties key2204 * @param runtimeValue (String) runtimeData value2205 */2206 @Step("Set dropdown by dynamic visible text value.")2207 public void setDropdownByDynamicVisibleText(String propertyKey, String runtimeValue) {22082209 waitForPageLoaded();2210 Select sel = new Select(confirmElementExistence(propertyKey));2211 List<WebElement> options = sel.getOptions();2212 boolean valueExists = false;22132214 for (WebElement we: options) {2215 if (we.getText().toLowerCase().equals(runtimeValue.toLowerCase())) {2216 valueExists = true;2217 break;2218 }2219 }22202221 if (valueExists) {2222 System.out.format("[LOG]: <[%s:%s] setting dropdown value to: \"%s\">%n", id, testName, runtimeValue);2223 sel.selectByVisibleText(runtimeValue);2224 ss.assertTrue(new Select(confirmElementExistence(propertyKey)).getAllSelectedOptions().size() == 1, "Multiple selections unexpected.");2225 ss.assertTrue(new Select(confirmElementExistence(propertyKey)).getFirstSelectedOption().getText().toLowerCase().equals(runtimeValue.toLowerCase()), "Unable to confirm selection.");2226 ss.takeScreenShot("Dropdown set by visible text.");2227 } else {2228 // force a descriptive fail if no match2229 ss.assertTrue(false, "Could not find exact visible text match.");2230 }22312232 }223322342235 /**2236 * Waits for dropdown to be found. Once found, sets dropdown to target index,2237 * as determined by p[artial text match (properties).2238 * Once set, confirms selection.2239 *2240 * @param propertyKey (String) locator properties key2241 * @param valueKey (String) value properties key2242 */2243 @Step("Set dropdown by static partial visible text value.")2244 public void setDropdownByStaticPartialVisibleText(String propertyKey, String valueKey) {22452246 waitForPageLoaded();2247 Select sel = new Select(confirmElementExistence(propertyKey));2248 List<WebElement> options = sel.getOptions();2249 String value = getPropertyValue(valueKey);2250 //System.out.format("[DEBUG]: <[%s:%s] comparing against value: \"%s\">%n", id, testName, value);2251 int index = getIndexByPartialText(value, options);2252 //System.out.format("[DEBUG]: <[%s:%s] index of match: %d>%n", id, testName, index);22532254 if (index >= 0) {2255 System.out.format("[LOG]: <[%s:%s] setting dropdown value to index: %d, by partial text: \"%s\">%n", id, testName, index, value);2256 sel.selectByIndex(index);2257 ss.assertTrue(new Select(confirmElementExistence(propertyKey)).getAllSelectedOptions().size() == 1, "Multiple selections unexpected.");2258 ss.assertTrue(new Select(confirmElementExistence(propertyKey)).getFirstSelectedOption().getText().toLowerCase().contains(value.toLowerCase()), "Unable to confirm selection.");2259 ss.takeScreenShot("Dropdown set by partial text.");2260 } else {2261 // force a descriptive fail if no match2262 ss.assertTrue(false, "Could not find partial visible text match.");2263 }22642265 }226622672268 /**2269 * Waits for dropdown to be found. Once found, sets dropdown to target index,2270 * as determined by partial text match (properties).2271 * Once set, confirms selection.2272 *2273 * @param w (WebElement) derived element2274 * @param valueKey (string) value properties key2275 */2276 @Step("Set dropdown by static partial visible text value.")2277 public void setDropdownByStaticPartialVisibleText(WebElement w, String valueKey) {22782279 waitForPageLoaded();2280 Select sel = new Select(w);2281 List<WebElement> options = sel.getOptions();2282 String value = getPropertyValue(valueKey);2283 //System.out.format("[DEBUG]: <[%s:%s] comparing against value: \"%s\">%n", id, testName, value);2284 int index = getIndexByPartialText(value, options);2285 //System.out.format("[DEBUG]: <[%s:%s] index of match: %d>%n", id, testName, index);22862287 if (index >= 0) {2288 System.out.format("[LOG]: <[%s:%s] setting dropdown value to index: %d, by partial text: \"%s\">%n", id, testName, index, value);2289 sel.selectByIndex(index);2290 ss.assertTrue(new Select(w).getAllSelectedOptions().size() == 1, "Multiple selections unexpected.");2291 ss.assertTrue(new Select(w).getFirstSelectedOption().getText().toLowerCase().contains(value.toLowerCase()), "Unable to confirm selection.");2292 ss.takeScreenShot("Dropdown set by partial text.");2293 } else {2294 // force a descriptive fail if no match2295 ss.assertTrue(false, "Could not find partial visible text match.");2296 }22972298 }229923002301 /**2302 * Waits for dropdown to be found. Once found, sets dropdown to target index,2303 * as determined by partial text match (runtimeData).2304 * Once set, confirms selection.2305 *2306 * @param propertyKey (String) locator properties key2307 * @param runtimeValue (String) runtimeData value2308 */2309 @Step("Set dropdown by dynamic partial visible text value.")2310 public void setDropdownByDynamicPartialVisibleText(String propertyKey, String runtimeValue) {23112312 waitForPageLoaded();2313 Select sel = new Select(confirmElementExistence(propertyKey));2314 List<WebElement> options = sel.getOptions();2315 //System.out.format("[DEBUG]: <[%s:%s] comparing against value: \"%s\">%n", id, testName, runtimeValue);2316 int index = getIndexByPartialText(runtimeValue, options);2317 //System.out.format("[DEBUG]: <[%s:%s] index of match: %d>%n", id, testName, index);23182319 if (index >= 0) {2320 System.out.format("[LOG]: <[%s:%s] setting dropdown value to index: %d, by partial text: \"%s\">%n", id, testName, index, runtimeValue);2321 sel.selectByIndex(index);2322 ss.assertTrue(new Select(confirmElementExistence(propertyKey)).getAllSelectedOptions().size() == 1, "Multiple selections unexpected.");2323 ss.assertTrue(new Select(confirmElementExistence(propertyKey)).getFirstSelectedOption().getText().toLowerCase().contains(runtimeValue.toLowerCase()), "Unable to confirm selection.");2324 ss.takeScreenShot("Dropdown set by partial text.");2325 } else {2326 // force a descriptive fail if no match2327 ss.assertTrue(false, "Could not find partial visible text match.");2328 }23292330 }233123322333 /**2334 * Waits for dropdown to be found. Once found, sets dropdown to target containing target value,2335 * as determined by partial text match (runtimeData).2336 * Once set, confirms selection.2337 *2338 * @param w (WebElement)2339 * @param runtimeValue (String)2340 */2341 @Step("Set dropdown by dynamic partial visible text value.")2342 public void setDropdownByDynamicPartialVisibleText(WebElement w, String runtimeValue) {23432344 waitForPageLoaded();2345 Select sel = new Select(w);2346 List<WebElement> options = sel.getOptions();2347 //System.out.format("[DEBUG]: <[%s:%s] comparing against value: \"%s\">%n", id, testName, runtimeValue);2348 int index = getIndexByPartialText(runtimeValue, options);2349 //System.out.format("[DEBUG]: <[%s:%s] index of match: %d>%n", id, testName, index);23502351 if (index >= 0) {2352 System.out.format("[LOG]: <[%s:%s] setting dropdown value to index: %d, by partial text: \"%s\">%n", id, testName, index, runtimeValue);2353 sel.selectByIndex(index);2354 ss.assertTrue(new Select(w).getAllSelectedOptions().size() == 1, "Multiple selections unexpected.");2355 ss.assertTrue(new Select(w).getFirstSelectedOption().getText().toLowerCase().contains(runtimeValue.toLowerCase()), "Unable to confirm selection.");2356 ss.takeScreenShot("Dropdown set by partial text.");2357 } else {2358 // force a descriptive fail if no match2359 ss.assertTrue(false, "Could not find partial visible text match.");2360 }23612362 }236323642365 /**2366 * Helper method for {@link #setDropdownByStaticPartialVisibleText(String, String)}2367 * and {@link #setDropdownByDynamicPartialVisibleText(String, String)}.2368 *2369 * Compares list element text to a known string in order to determine index of2370 * matching element.2371 *2372 * @param match (String) text to compare against select option text2373 * @param options (List<WebElement>) list of select options as web elements2374 * @return (int) index of match, or -12375 */2376 private int getIndexByPartialText(String match, List<WebElement> options) {23772378 for (int i = 0; i < options.size(); i++) {2379 /*if (null != options.get(i)) {2380 System.out.format("[DEBUG]: <[%s:%s] value extracted at index=%d: \"%s\">%n", id, testName, i, options.get(i).getText());2381 }*/2382 if (null != options.get(i) && options.get(i).getText().contains(match)) {2383 return i;2384 }2385 }2386 return -1;23872388 }238923902391 /**2392 * Compares a given string (property key) against the text contents of2393 * a given web element (property key)2394 *2395 * @param propertyKey (String) locator properties key2396 * @param valueKey (String) comparison string2397 * @return (WebElement)2398 */2399 @Step("Confirm text value.")2400 public WebElement confirmStaticTextValue(String propertyKey, String valueKey) {24012402 value = getPropertyValue(valueKey);2403 we = confirmElementExistence(propertyKey);2404 System.out.format("[LOG]: <[%s:%s] comparing string contains string: \"%s:%s\">%n", this.id, this.testName, we.getText().replace("\n", ""), value);2405 ss.assertTrue(we.getText().toLowerCase().contains(value.toLowerCase()));2406 ss.takeScreenShot("Confirm text presence.");2407 return we;24082409 }241024112412 /**2413 * Compare a give string (properties) against the contents of a given dynamic web element (properties)2414 *2415 * @param propertyKey (String) compound locator properties key2416 * @param replacementKey (String) replacement text properties key2417 * @param valueKey (String) comparison value text properties key2418 */2419 @Step("Confirm text value.")2420 public WebElement confirmStaticTextValue(String propertyKey, String replacementKey, String valueKey) {24212422 we = confirmElementExistence(propertyKey, getPropertyValue(replacementKey));2423 ss.assertTrue(we.getText().trim().toLowerCase().contains(getPropertyValue(valueKey).trim().toLowerCase()));2424 ss.takeScreenShot("Confirm text presence.");2425 return we;24262427 }242824292430 /**2431 * Compares a given string (property key) against the text contents of2432 * a given web element (property key)2433 *2434 * @param w (WebElement)2435 * @param valueKey (String) comparison string2436 * @return (WebElement)2437 */2438 @Step("Confirm text value.")2439 public WebElement confirmStaticTextValue(WebElement w, String valueKey) {24402441 value = getPropertyValue(valueKey);2442 System.out.format("[LOG]: <[%s:%s] comparing string contains string: \"%s:%s\">%n", this.id, this.testName, w.getText().replace("\n", ""), value);2443 ss.assertTrue(w.getText().toLowerCase().contains(value.toLowerCase()));2444 ss.takeScreenShot("Confirm text presence.");2445 return w;24462447 }24482449 /**2450 * Compares a given string (property key) against the text contents of2451 * a given web element (property key)2452 *2453 * @param w (WebElement)2454 * @param valueKeys (String) comparison string2455 * @return (WebElement)2456 */2457 @Step("Confirm text value.")2458 public WebElement confirmStaticTextValues(WebElement w, List<String> valueKeys) {24592460 List<String> values = new ArrayList<String>();24612462 for (String s: valueKeys) {2463 values.add(getPropertyValue(s));2464 }24652466 System.out.format("[LOG]: <[%s:%s] comparing element text matches list: \"%s:%s\">%n", this.id, this.testName, w.getAttribute("innerHTML"), String.join(",", values));2467 ss.assertTrue(elementContentInList(w.getAttribute("innerHTML"), values), "Could not confirm a suitable Process Description.");24682469 ss.takeScreenShot("Confirm text presence.");2470 return w;24712472 }247324742475 /**2476 * Helper method for {@link #confirmStaticTextValues(WebElement, List)}.2477 * Compares singular string against string list contents.2478 *2479 * @param search (String) string to compare against list values2480 * @param reference (List<String>) list of potential matches2481 * @return (boolean) search string found in list?2482 */2483 private boolean elementContentInList(String search, List<String> reference) {24842485 for (String s: reference) {2486 if (s.toLowerCase().contains(search.toLowerCase())) {2487 return true;2488 }2489 }2490 return false;24912492 }249324942495 /**2496 * Compares a given string (runtimeData/caller derived) against the text contents of2497 * a given web element (property key)2498 *2499 * @param propertyKey (String) locator properties key2500 * @param value (String) comparison string2501 */2502 @Step("Confirm text value.")2503 public WebElement confirmDynamicTextValue(String propertyKey, String value) {25042505 we = confirmElementExistence(propertyKey);2506 System.out.format("[LOG]: <[%s:%s] comparing string contains string: \"%s:%s\">%n", this.id, this.testName, we.getText().replace("\n", ""), value);2507 ss.assertTrue(we.getText().toLowerCase().contains(value.toLowerCase()));2508 ss.takeScreenShot("Confirm text presence.");2509 return we;25102511 }251225132514 /**2515 * Compare a give string (runtimeData) against the contents of a given dynamic web element (properties)2516 *2517 * @param propertyKey (String) compound locator properties key2518 * @param replacementKey (String) replacement text properties key2519 * @param value (String) comparison value text2520 */2521 @Step("Confirm text value.")2522 public WebElement confirmDynamicTextValue(String propertyKey, String replacementKey, String value) {25232524 we = confirmElementExistence(propertyKey, getPropertyValue(replacementKey));2525 ss.assertTrue(we.getText().trim().toLowerCase().contains(value.trim().toLowerCase()));2526 ss.takeScreenShot("Confirm text presence.");2527 return we;25282529 }253025312532 /**2533 * Compare a give string (runtimeData) against the contents of a given dynamic web element (runtimeData)2534 *2535 * @param propertyKey (String) compound locator properties key2536 * @param values (String[]) a string array containing the replacement value at position 0 and comparison value at position 12537 */2538 @Step("Confirm text value.")2539 public WebElement confirmDynamicTextValue(String propertyKey, String[] values) {25402541 String replacementValue = values[0];2542 String value = values[1];25432544 we = confirmElementExistence(propertyKey, replacementValue);2545 ss.assertTrue(we.getText().trim().toLowerCase().contains(value.trim().toLowerCase()));2546 ss.takeScreenShot("Confirm text presence.");2547 return we;25482549 }255025512552 /**2553 * Compares a given string (runtimeData/caller derived) against the text contents of2554 * a given web element (WebElement)2555 *2556 * @param we (WebElement) selenium element wrapping text2557 * @param value (String) comparison string2558 */2559 @Step("Confirm text value.")2560 public WebElement confirmDynamicTextValue(WebElement we, String value) {25612562 System.out.format("[LOG]: <[%s:%s] comparing string contains string: \"%s:%s\">%n", this.id, this.testName, we.getText().replace("\n", ""), value);2563 ss.assertTrue(we.getText().toLowerCase().contains(value.toLowerCase()));2564 ss.takeScreenShot("Confirm text presence.");2565 return we;25662567 }256825692570 /**2571 * Compares a given string (runtimeData/caller derived) against the text contents of2572 * a given web element (property key), expected absence2573 *2574 * @param propertyKey (String) locator properties key2575 * @param value (String) comparison string2576 */2577 @Step("Confirm text value.")2578 public WebElement confirmDynamicNotTextValue(String propertyKey, String value) {25792580 we = confirmElementExistence(propertyKey);2581 System.out.format("[LOG]: <[%s:%s] comparing string contains string: \"%s:%s\">%n", this.id, this.testName, we.getText().replace("\n", ""), value);2582 ss.assertTrue(!we.getText().toLowerCase().contains(value.toLowerCase()));2583 ss.takeScreenShot("Confirm text presence.");2584 return we;25852586 }258725882589 /**2590 * Compares a given string (runtimeData) against the text contents of a given web element2591 * (property key)2592 *2593 * @param propertyKey (String) locator properties key2594 * @param runtimeValue (String) comparison string2595 */2596 @Step("Confirm text value.")2597 public WebElement confirmExactDynamicTextValue(String propertyKey, String runtimeValue) {25982599 we = confirmElementExistence(propertyKey);2600 ss.assertTrue(we.getText().equals(runtimeValue));2601 ss.takeScreenShot("Confirm text presence.");2602 return we;26032604 }260526062607 /**2608 * Compares a given string (runtimeData) against the text contents of a given web element2609 * (WebElement)2610 *2611 * @param we (WebElement) selenium element wrapping text2612 * @param runtimeValue (String) comparison string2613 */2614 @Step("Confirm text value.")2615 public WebElement confirmExactDynamicTextValue(WebElement we, String runtimeValue) {26162617 //System.out.format("[DEBUG]: <[%s:%s] comparing strings [exp]\"%s\":[act]\"%s\">%n", this.id, this.testName, runtimeValue.trim(), we.getText().trim());2618 ss.assertTrue(we.getText().trim().equals(runtimeValue.trim()));2619 ss.takeScreenShot("Confirm text presence.");2620 return we;26212622 }262326242625 /**2626 * Compares a given string (runtimeData) against the input text of a given input field2627 * (runtimeData)2628 *2629 * @param propertyKey (String) locator properties key2630 * @param runtimeValue (String) comparison string2631 */2632 @Step("Confirm text value.")2633 public WebElement confirmExactDynamicInputText(String propertyKey, String runtimeValue) {26342635 we = confirmElementExistence(propertyKey);2636 String value = (String) this.jse.executeScript("return arguments[0].value", we);2637 //String value = (String) this.jse.executeScript("return $(arguments[0]).val()", loc); // has an issue with unrecognized expression that I do not understand2638 //System.out.format("[DEBUG]: <[%s:%s] value returned from javascriptexecutor: \"%s\">%n", value);2639 ss.assertTrue(value.equals(runtimeValue));2640 ss.takeScreenShot("Confirm text presence.");2641 return we;26422643 }264426452646 /**2647 * Compares a given string (runtimeData) against the input text of a given input field2648 * (runtimeData)2649 *2650 * @param we (WebElement) selenium element wrapping text2651 * @param runtimeValue (String) comparison string2652 */2653 @Step("Confirm text value.")2654 public WebElement confirmExactDynamicInputText(WebElement we, String runtimeValue) {26552656 String value = (String) this.jse.executeScript("return arguments[0].value", we);2657 //String value = (String) this.jse.executeScript("return $(arguments[0]).val()", loc); // has an issue with unrecognized expression that I do not understand2658 //System.out.format("[DEBUG]: <[%s:%s] value returned from javascriptexecutor: \"%s\">%n", value);2659 ss.assertTrue(value.equals(runtimeValue));2660 ss.takeScreenShot("Confirm text presence.");2661 return we;26622663 }266426652666 /**2667 * Given a target window title, cycle through open windows until title matches, else return false2668 *2669 * @param valueKey (String) window title for comparison2670 * @return (boolean) true if window found2671 */2672 @Step("Switch to window by title.")2673 public void switchToWindowByTitle(String valueKey) {26742675 String title;2676 String currentHandle = this.driver.getWindowHandle();2677 //System.out.format("[DEBUG]: <[%s:%s] current window handle: \"%s\">%n", this.id, this.testName, currentHandle);2678 Set<String> handles = this.driver.getWindowHandles();26792680 for (String handle: handles) {2681 System.out.format("[LOG]: <[%s:%s] checking window handle: \"%s\" for title match.>%n", this.id, this.testName, handle);2682 if(!handle.equals(currentHandle)) {2683 this.driver.switchTo().window(handle);2684 waitForPageLoaded(120);2685 title = this.driver.getTitle();2686 //System.out.format("[DEBUG]: <[%s:%s] comparing window title to reference: \"%s:%s\">%n", this.id, this.testName, title, getPropertyValue(valueKey));2687 //System.out.format("[DEBUG]: <[%s:%s] strings match?: %b>%n", this.id, this.testName, title.toLowerCase().equals(getPropertyValue(valueKey).toLowerCase().trim()));2688 if (title.replace("\u2013","-").toLowerCase().equals(getPropertyValue(valueKey).toLowerCase())) {2689 ss.assertTrue(true);2690 return;2691 }2692 }2693 }2694 ss.assertTrue(false, "Could not find matching window title.");26952696 }269726982699 /**2700 * Given one daughter window, switch to daughter window2701 */2702 @Step("Switch to daughter window.")2703 public String[] switchToDaughterWindow() {27042705 String currentHandle = this.driver.getWindowHandle();2706 Set<String> handles = this.driver.getWindowHandles();2707 String hndl = null;27082709 ss.assertTrue(handles.size() == 2, "More than one daughter window.");27102711 for (String handle: handles) {2712 if (!handle.equals(currentHandle)) {2713 this.driver.switchTo().window(handle);2714 waitForPageLoaded(30);2715 hndl = handle;2716 }2717 }2718 return new String[] {currentHandle, hndl};27192720 }272127222723 /**2724 * Given a window handle, switch to it2725 */2726 @Step("Switch to parent window.")2727 public void switchToWindowByHandle(String handle) {27282729 Set<String> handles = this.driver.getWindowHandles();2730 if (handles.contains(handle)) {2731 this.driver.switchTo().window(handle);2732 waitForPageLoaded(30);2733 } else {2734 ss.assertTrue(false, "Window handle not found.");2735 }27362737 }273827392740 /**2741 * Check for broken image.2742 */2743 @Step("Check for broken image.")2744 public void checkForBrokenImage(String propertyKey) {27452746 //waitForPageCompletelyLoaded();2747 we = confirmElementExistence(propertyKey);27482749 System.out.format("[LOG]: <[%s:%s] checking up to %d seconds for broken image.>", this.id, this.testName, gc.defaultTimeOut);2750 double start = System.currentTimeMillis();2751 try {27522753 this.wait2754 .withTimeout(Duration.ofSeconds((long) gc.defaultTimeOut))2755 .until(new Function<RemoteWebDriver, Boolean>() {2756 public Boolean apply(RemoteWebDriver drv) {2757 return (boolean) ((JavascriptExecutor) drv).executeScript("return (arguments[0].complete && typeof arguments[0].naturalWidth != \"undefined\" && arguments[0].naturalWidth > 0)", we);2758 }2759 });27602761 } catch (TimeoutException to) {2762 ss.assertTrue(false, "Image is broken.");2763 } finally {2764 System.out.format(" <waited %.2f seconds>%n", (System.currentTimeMillis() - start)/1000.0);2765 }27662767 }276827692770 /**2771 * Check for broken image.2772 */2773 @Step("Check for broken image.")2774 public void checkForBrokenImage(String propertyKey, int wait) {27752776 //waitForPageCompletelyLoaded();2777 we = confirmElementExistence(propertyKey, wait);27782779 System.out.format("[LOG]: <[%s:%s] checking up to %d seconds for broken image.>", this.id, this.testName, gc.defaultTimeOut);2780 double start = System.currentTimeMillis();2781 try {27822783 this.wait2784 .withTimeout(Duration.ofSeconds((long) gc.defaultTimeOut))2785 .until(new Function<RemoteWebDriver, Boolean>() {2786 public Boolean apply(RemoteWebDriver drv) {2787 return (boolean) ((JavascriptExecutor) drv).executeScript("return (arguments[0].complete && typeof arguments[0].naturalWidth != \"undefined\" && arguments[0].naturalWidth > 0)", we);2788 }2789 });27902791 } catch (TimeoutException to) {2792 ss.assertTrue(false, "Image is broken.");2793 } finally {2794 System.out.format(" <waited %.2f seconds>%n", (System.currentTimeMillis() - start)/1000.0);2795 }27962797 }279827992800 /**2801 * Populates text list from multi-element locator, compares against known text list (CSV, property key)2802 */2803 @Step("Confirm multi-element text.")2804 public void confirmMultiElementText(String propertyKey, String valueKey) {28052806 List<String> foundList = new ArrayList<String>();2807 List<String> expectedList = new ArrayList<String>();2808 List<WebElement> weArray = new ArrayList<WebElement>();2809 String[] values = null;28102811 weArray = confirmElementsExistence(propertyKey);2812 values = getPropertyValue(valueKey).split(",");2813 expectedList = Arrays.asList(values);28142815 for (WebElement we: weArray) {2816 foundList.add(we.getText());2817 }28182819 StringBuilder sb = new StringBuilder();2820 sb.append("{");2821 for (String s: expectedList) {2822 sb.append(s+",");2823 }2824 sb.append("}:{");2825 for (String s: foundList) {2826 sb.append(s+",");2827 }2828 sb.append("}");28292830 System.out.format("[LOG]: <[%s:%s] comparing string lists: [%s]>%n", this.id, this.testName, sb.toString());2831 ss.assertTrue(expectedList.equals(foundList), "Lists differ.");2832 ss.takeScreenShot("Lists match.");28332834 }283528362837 /**2838 * Given a propertyKey resulting in a List of WebElements, and a comma-separated2839 * list of strings, compares per-element text with per-string text2840 *2841 * @param propertyKey (String) multi-locator property key (properties)2842 * @param valueKey (String) multi-text property key (properties)2843 */2844 @Step("Confirm multi-element text, element by element.")2845 public void confirmMultiElementTextByElement(String propertyKey, String valueKey) {28462847 List<String> foundList = new ArrayList<String>();2848 List<String> expectedList = new ArrayList<String>();2849 List<WebElement> weArray = new ArrayList<WebElement>();2850 String[] values = null;28512852 weArray = confirmElementsExistence(propertyKey);2853 values = getPropertyValue(valueKey).split(",");2854 expectedList = Arrays.asList(values);28552856 for (WebElement we: weArray) {2857 foundList.add(we.getText());2858 }28592860 Iterator<String> found = foundList.listIterator();2861 Iterator<String> expected = expectedList.listIterator();2862 while (found.hasNext() && expected.hasNext()) {2863 String f = found.next();2864 String e = expected.next();2865 ss.assertTrue(f.contains(e), String.format("Found: %s; Expected: %s", f, e));2866 }2867 ss.takeScreenShot("Lists match.");28682869 }287028712872 /**2873 * Close current window2874 */2875 @Step("Close window.")2876 public void closeWindow() {28772878 this.driver.close();28792880 }288128822883 /**2884 * Execute a boolean returning synchronous JavaScript snippet (fully defined)2885 *2886 * @param scriptKey (String) script reference (properties)2887 * @return (boolean) result of script execution as returned by JSE2888 */2889 @Step("Execute JavaScript snippet, boolean return.")2890 public boolean jseExecuteBoolean(String scriptKey) {28912892 String script = getPropertyValue(scriptKey);2893 System.out.format("[LOG]: <[%s:%s] executing script: %s;>%n", this.id, this.testName, scriptKey);2894 return (boolean) this.jse.executeScript(script);28952896 }289728982899 /**2900 * Execute a boolean returning synchronous JavaScript snippet (fully defined),2901 * respective some WebElement2902 *2903 * @param scriptKey (String) script reference (properties)2904 * @param propertyKey (String) locator (properties)2905 * @return (boolean) result of script execution as returned by JSE2906 */2907 @Step("Execute JavaScript snippet, boolean return.")2908 public boolean jseExecuteBoolean(String scriptKey, String propertyKey) {29092910 String script = getPropertyValue(scriptKey);2911 we = confirmElementExistence(propertyKey);2912 System.out.format("[LOG]: <[%s:%s] executing script: %s; against element: %s;>%n", this.id, this.testName, scriptKey, propertyKey);2913 return (boolean) this.jse.executeScript(script, we);29142915 }291629172918 /**2919 * Execute a boolean returning synchronous JavaScript snippet (fully defined),2920 * respective some WebElement2921 *2922 * @param scriptKey (String) script reference (properties)2923 * @param we (WebElement) selenium element2924 * @return (boolean) result of script execution as returned by JSE2925 */2926 @Step("Execute JavaScript snippet, boolean return.")2927 public boolean jseExecuteBoolean(String scriptKey, WebElement we) {29282929 String script = getPropertyValue(scriptKey);2930 System.out.format("[LOG]: <[%s:%s] executing script: %s; against dynamic element.>%n", this.id, this.testName, scriptKey);2931 return (boolean) this.jse.executeScript(script, we);29322933 }293429352936 /**2937 * Execute a integer returning synchronous JavaScript snippet (fully defined)2938 *2939 * @param scriptKey (String) script reference (properties)2940 * @return (int) result of script execution as returned by JSE2941 */2942 @Step("Execute JavaScript snippet, integer return.")2943 public int jseExecuteInteger(String scriptKey) {29442945 String script = getPropertyValue(scriptKey);2946 System.out.format("[LOG]: <[%s:%s] executing script: %s;>%n", this.id, this.testName, scriptKey);2947 return (int) (long) this.jse.executeScript(script);29482949 }295029512952 /**2953 * Execute a integer returning synchronous JavaScript snippet (fully defined),2954 * respective some WebElement2955 *2956 * @param scriptKey (String) script reference (properties)2957 * @param propertyKey (String) locator (properties)2958 * @return (int) result of script execution as returned by JSE2959 */2960 @Step("Execute JavaScript snippet, integer return.")2961 public int jseExecuteInteger(String scriptKey, String propertyKey) {29622963 String script = getPropertyValue(scriptKey);2964 we = confirmElementExistence(propertyKey);2965 System.out.format("[LOG]: <[%s:%s] executing script: %s; against element: %s;>%n", this.id, this.testName, scriptKey, propertyKey);2966 return (int) (long) this.jse.executeScript(script, we);29672968 }296929702971 /**2972 * Execute a integer returning synchronous JavaScript snippet (fully defined),2973 * respective some WebElement2974 *2975 * @param scriptKey (String) script reference (properties)2976 * @param we (WebElement) selenium element2977 * @return (int) result of script execution as returned by JSE2978 */2979 @Step("Execute JavaScript snippet, integer return.")2980 public int jseExecuteInteger(String scriptKey, WebElement we) {29812982 String script = getPropertyValue(scriptKey);2983 System.out.format("[LOG]: <[%s:%s] executing script: %s; against dynamic element.>%n", this.id, this.testName, scriptKey);2984 return (int) (long) this.jse.executeScript(script, we);29852986 }298729882989 /**2990 * Execute a String returning synchronous JavaScript snippet (fully defined)2991 *2992 * @param scriptKey (String) script reference (properties)2993 * @return (String) result of script execution as returned by JSE2994 */2995 @Step("Execute JavaScript snippet, string return.")2996 public String jseExecuteString(String scriptKey) {29972998 String script = getPropertyValue(scriptKey);2999 System.out.format("[LOG]: <[%s:%s] executing script: %s;>%n", this.id, this.testName, scriptKey);3000 return (String) this.jse.executeScript(script);30013002 }300330043005 /**3006 * Execute a String returning synchronous JavaScript snippet (fully defined),3007 * respective some WebElement3008 *3009 * @param scriptKey (String) script reference (properties)3010 * @param propertyKey (String) locator (properties)3011 * @return (String) result of script execution as returned by JSE3012 */3013 @Step("Execute JavaScript snippet, string return.")3014 public String jseExecuteString(String scriptKey, String propertyKey) {30153016 String script = getPropertyValue(scriptKey);3017 we = confirmElementExistence(propertyKey);3018 System.out.format("[LOG]: <[%s:%s] executing script: %s; against element: %s;>%n", this.id, this.testName, scriptKey, propertyKey);3019 return (String) this.jse.executeScript(script, we);30203021 }302230233024 /**3025 * Execute a String returning synchronous JavaScript snippet (fully defined),3026 * respective some WebElement3027 *3028 * @param scriptKey (String) script reference (properties)3029 * @param we (WebElement) selenium element3030 * @return (String) result of script execution as returned by JSE3031 */3032 @Step("Execute JavaScript snippet, string return.")3033 public String jseExecuteString(String scriptKey, WebElement we) {30343035 String script = getPropertyValue(scriptKey);3036 System.out.format("[LOG]: <[%s:%s] executing script: %s; against dynamic element.>%n", this.id, this.testName, scriptKey);3037 return (String) this.jse.executeScript(script, we);30383039 }304030413042 /**3043 * Execute a synchronous JavaScript snippet (fully defined)3044 *3045 * @param scriptKey (String) script reference (properties)3046 */3047 @Step("Execute JavaScript snippet, no return.")3048 public void jseExecuteVoid(String scriptKey) {30493050 String script = getPropertyValue(scriptKey);3051 System.out.format("[LOG]: <[%s:%s] executing script: %s;>%n", this.id, this.testName, scriptKey);3052 this.jse.executeScript(script);30533054 }305530563057 /**3058 * Execute a synchronous JavaScript snippet (fully defined),3059 * respective some WebElement3060 *3061 * @param scriptKey (String) script reference (properties)3062 * @param propertyKey (String) locator (properties)3063 */3064 @Step("Execute JavaScript snippet, no return.")3065 public void jseExecuteVoid(String scriptKey, String propertyKey) {30663067 String script = getPropertyValue(scriptKey);3068 we = confirmElementExistence(propertyKey);3069 System.out.format("[LOG]: <[%s:%s] executing script: %s; against element: %s;>%n", this.id, this.testName, scriptKey, propertyKey);3070 this.jse.executeScript(script, we);30713072 }307330743075 /**3076 * Execute a synchronous JavaScript snippet (fully defined),3077 * respective some WebElement3078 *3079 * @param scriptKey (String) script reference (properties)3080 * @param we (WebElement) locator (properties)3081 */3082 @Step("Execute JavaScript snippet, no return.")3083 public void jseExecuteVoid(String scriptKey, WebElement we) {30843085 String script = getPropertyValue(scriptKey);3086 System.out.format("[LOG]: <[%s:%s] executing script: %s; against dynamic element.>%n", this.id, this.testName, scriptKey);3087 this.jse.executeScript(script, we);30883089 }309030913092 /**3093 * Force fail a test3094 */3095 @Step("Force a FAIL.")3096 public void failTest() {30973098 ss.assertTrue(false, "This assertion intended to FAIL.");30993100 }31013102 /**3103 * Confirm the selection state of a target dropdown menu widget (runtimeData)3104 *3105 * @param propertyKey (String) locator properties key3106 * @param runtimeValue (String) value from runtimeData/GlobalConstants3107 */3108 @Step("Confirm dropdown selected value.")3109 public void confirmDynamicDropdownValue(String propertyKey, String runtimeValue) {31103111 waitForPageLoaded();3112 Select sel = new Select(confirmElementExistence(propertyKey));3113 ss.assertTrue(sel.getFirstSelectedOption().getText().toLowerCase().equals(runtimeValue.toLowerCase()));31143115 }311631173118 /**3119 * Confirm the selection state of a target dropdown menu widget (properties)3120 *3121 * @param propertyKey (String) locator properties key3122 * @param valueKey (String) option to set properties key3123 */3124 @Step("Confirm dropdown selected value.")3125 public void confirmStaticDropdownValue(String propertyKey, String valueKey) {31263127 waitForPageLoaded();3128 String value = getPropertyValue(valueKey);3129 Select sel = new Select(confirmElementExistence(propertyKey));3130 ss.assertTrue(sel.getFirstSelectedOption().getText().toLowerCase().equals(value.toLowerCase()));31313132 }31333134 /**3135 * Grab the current instance of 'driver' to use for methods in 'PageObjects'3136 *3137 */3138 @Step("Return the current instance of 'driver'")3139 public RemoteWebDriver returnDriver() {31403141 return this.driver;31423143 }3144}

Full Screen

Full Screen

Source:SoloIncomeEntry.java Github

copy

Full Screen

...109 String name= record.getText().toString();110 String[]nameArray= name.split("-");111 String GMC_Code= nameArray[0].toString().trim();112 String GPSoloName= nameArray[1].toString().trim();113 if((strGMCCode.equalsIgnoreCase(GMC_Code))&&(strGPSoloName.equalsIgnoreCase(GPSoloName))){114 record.click();115 Thread.sleep(2000);116 break;117 }118 }119 wait.until(ExpectedConditions.elementToBeClickable(applicantSearch)).click();120 Thread.sleep(2000);121 scrolltoElement(driver, soloStartDate);122 enterDataInTextField(soloStartDate, fromDate, wait);123 Thread.sleep(1000);124 enterDataInTextField(soloEndDate, toDate, wait);125 scrolltoElement(driver, payAmount);126 enterDataInTextField(payAmount, strPayExcludingNHSPS, wait);127 Thread.sleep(1000);128 enterDataInTextField(professionalExp, strProfessionalExpenses, wait);129 professionalExp.sendKeys(Keys.TAB);130 CommonFunctions.PageLoadExternalwait_OP(driver);131 Thread.sleep(2000);132 wait.until(ExpectedConditions.elementToBeClickable(tickToConfirm)).click();133 return new SoloIncomeEntry(driver);134 }135 public boolean verifyPensionableAmount(String colName, String file, String sheet) throws InterruptedException{136 boolean matched=false;137 String strPayExcludingNHSPS= ExcelUtilities.getKeyValueByPosition(file, sheet, "PayExcludingNHSPS", colName);138 double payExcludingNHSPS= Double.parseDouble(strPayExcludingNHSPS);139 Thread.sleep(500);140 String strProfessionalExpenses= ExcelUtilities.getKeyValueByPosition(file, sheet, "ProfessionalExpenses", colName);141 double professionalExpenses= Double.parseDouble(strProfessionalExpenses);142 Thread.sleep(500);143 String strPayExcludingNHSPS_Portal= Support.getValueByJavaScript(driver, "SOLODetails_ExcludingNHSPSContributions");144 strPayExcludingNHSPS_Portal= strPayExcludingNHSPS_Portal.replaceAll(",", "");145 double payExcludingNHSPS_Portal= Double.parseDouble(strPayExcludingNHSPS_Portal);146 Thread.sleep(500);147 String strProfessionalExpenses_Portal= Support.getValueByJavaScript(driver, "SOLODetails_ProfessionalNHSExpenses");148 strProfessionalExpenses_Portal= strProfessionalExpenses_Portal.replaceAll(",", "");149 double professionalExpenses_Portal= Double.parseDouble(strProfessionalExpenses_Portal);150 Thread.sleep(500);151 double actualAmt= payExcludingNHSPS-professionalExpenses;152 actualAmt= GPPHelpers.convertValueToDecimals(actualAmt,2);153 double expAmt= payExcludingNHSPS_Portal-professionalExpenses_Portal;154 expAmt= GPPHelpers.convertValueToDecimals(expAmt,2);155 156 if(actualAmt==expAmt){157 matched=true;158 }159 return matched;160 }161 162 public void captureSoloIncomeEntrySnaps(String note) throws InterruptedException, IOException {163 Screenshot.TakeSnap(driver, note+"_1");164 Thread.sleep(1000);165 166 ((JavascriptExecutor) driver).executeScript("window.scrollBy(0,800)", "");167 Screenshot.TakeSnap(driver, note+"_2");168 }169 public boolean verifyEmployeeContribution(String scriptKey, String testDataFileName, String testDataSheet,String amtTierSheet) throws InterruptedException {170 boolean contributionMatched=false;171 List<Double>expActualValues= getCalculatedValues(scriptKey,testDataFileName,testDataSheet,amtTierSheet);172 double contributionAmt= expActualValues.get(0);173 double actualContriAmt= expActualValues.get(1);174 if(contributionAmt==actualContriAmt){175 contributionMatched=true;176 }177 return contributionMatched;178 }179 private List<Double> getCalculatedValues(String scriptKey, String testDataFileName, String testDataSheet,180 String amtTierSheet) throws InterruptedException {181 List<Double> values= new ArrayList<Double>();182 double criteria = 0.00,startRange=0.00,endRange,contributionAmt=0.00;183 String strPensionableAmt= Support.getValueByJavaScript(driver, "SOLODetails_NHSPensionablePay");184 strPensionableAmt= strPensionableAmt.replaceAll(",", "");185 double pensionableAmt= Double.parseDouble(strPensionableAmt);186 Thread.sleep(500);187 pensionableAmt= GPPHelpers.convertValueToDecimals(pensionableAmt,2);188 189 String strAnnualAmt= ExcelUtilities.getKeyValueByPosition(testDataFileName, testDataSheet, "AnnualIncome", scriptKey);190 double annualAmt= Double.parseDouble(strAnnualAmt);191 Thread.sleep(500);192 annualAmt= GPPHelpers.convertValueToDecimals(annualAmt,2);193 194 double finalAmount= pensionableAmt+annualAmt;195 196 List<String>ranges= ExcelUtilities.getCellValuesByPosition(testDataFileName, amtTierSheet, "Range");197 int rangeSize= ranges.size();198 List<String>critria= ExcelUtilities.getCellValuesByPosition(testDataFileName, amtTierSheet, "Criteria");199 200 for(int i=0;i<rangeSize;i++){201 String range= ranges.get(i);202 String[]rangeArray= range.split("-");203 String strStartRange= rangeArray[0].toString();204 startRange= Double.parseDouble(strStartRange);205 Thread.sleep(500);206 startRange= GPPHelpers.convertValueToDecimals(startRange,2);207 String strEndRange= rangeArray[1].toString();208 if(!(strEndRange.equalsIgnoreCase("over"))){209 endRange= Double.parseDouble(strEndRange);210 Thread.sleep(500);211 endRange= GPPHelpers.convertValueToDecimals(endRange,2);212 if((finalAmount>=startRange)&&(finalAmount<=endRange)){213 String strCriteria= critria.get(i);214 criteria= Double.parseDouble(strCriteria);215 Thread.sleep(500);216 criteria= GPPHelpers.convertValueToDecimals(criteria,2);217 break;218 }219 }else{220 Thread.sleep(500);221 if((finalAmount>=startRange)){222 String strCriteria= critria.get(i);...

Full Screen

Full Screen

Source:SilverlightWrapper.java Github

copy

Full Screen

...23 protected JavascriptExecutor getJSExecutor() {24 return this.jsDriver;25 }26 public SilverlightWrapper(final WebDriver driver, final String silverLightObjectId, final String constScriptKey) {27 if (constScriptKey != null && !constScriptKey.equals("")) {28 // got some meaningful value, replacing29 this.scriptKey = constScriptKey + ".";30 }31 setDriver(driver);32 // verify the browser type33 String userAgent = getUserAgent();34 if (userAgent.contains(BrowserConstants.FIREFOX3.getPrefix())35 || userAgent.contains(BrowserConstants.IE.getPrefix())) {36 this.silverLightJSStringPrefix = createJSPrefixViaWindowDocument(silverLightObjectId);37 } else {38 this.silverLightJSStringPrefix = createJSPrefixViaDocument(silverLightObjectId);39 }40 }41 /**42 * Constructor for general purpose.43 * 44 * @param driver45 * WebDriver displaying the page46 * @param silverLightObjectId47 * html id value of the silverlight component.48 */49 public SilverlightWrapper(final WebDriver driver, final String silverLightObjectId) {50 setDriver(driver);51 // verify the browser type52 String userAgent = getUserAgent();53 if (userAgent.contains(BrowserConstants.FIREFOX3.getPrefix())54 || userAgent.contains(BrowserConstants.IE.getPrefix())) {55 silverLightJSStringPrefix = createJSPrefixViaWindowDocument(silverLightObjectId);56 } else {57 silverLightJSStringPrefix = createJSPrefixViaDocument(silverLightObjectId);58 }59 }60 /**61 * Retrieve the user agent from the browser.62 * 63 * @return user agent of the browser.64 */65 private String getUserAgent() {66 String userAgent = getJSExecutor().executeScript("return navigator.userAgent;").toString();67 return userAgent;68 }69 /**70 * This constructor is used for test purposes.71 * 72 * @param driver73 * WebDriver displaying the page74 * @param silverLightObjectId75 * id of the SilverLight object on the page76 * @param constSilverLightJSStringPrefix77 * JavaScript prefix to communicate with the SilverLight object78 * @param testOnly79 * is this a test?80 */81 SilverlightWrapper(final WebDriver driver, final String silverLightObjectId,82 final String constSilverLightJSStringPrefix, final boolean testOnly) {83 setDriver(driver);84 this.silverLightJSStringPrefix = constSilverLightJSStringPrefix;85 }86 /**87 * Setting the driver, initialising some help structures.88 * 89 * @param driver90 * WebDriver displaying the page.91 */92 private void setDriver(final WebDriver driver) {93 if (driver instanceof JavascriptExecutor) {94 this.jsDriver = (JavascriptExecutor) driver;95 } else {96 throw new UnsupportedOperationException("Thid driver doesn't support JavaScript execution");97 }98 }99 /**100 * Method used to create an instance for test purpose.101 * 102 * @param driver103 * WebDriver displaying the page104 * @param silverLightObjectId105 * id of the SilverLight object on the page106 * @return instance of SilverlightWrapper107 */108 static SilverlightWrapper createSilverLightObjAsDocument(final WebDriver driver, final String silverLightObjectId) {109 return new SilverlightWrapper(driver, silverLightObjectId, createJSPrefixViaDocument(silverLightObjectId), true);110 }111 /**112 * SilverLight object is the Window document? (whatever)113 * 114 * @param driver115 * WebDriver displaying the page116 * @param silverLightObjectId117 * id of the SilverLight object on the page118 * @return instance of SilverlightWrapper119 */120 static SilverlightWrapper createSilverLightObjAsWindowDocument(final WebDriver driver,121 final String silverLightObjectId) {122 return new SilverlightWrapper(driver, silverLightObjectId,123 createJSPrefixViaWindowDocument(silverLightObjectId), true);124 }125 /**126 * JavaScript prefix to access via 'window.document'.127 * 128 * @param silverLightObjectId129 * id of the SilverLight object to interact with130 * @return JavaScript prefix131 */132 static String createJSPrefixViaWindowDocument(final String silverLightObjectId) {133 return "return window.document['" + silverLightObjectId + "'].";134 }135 /**136 * JavaScript prefix to access via 'document'.137 * 138 * @param silverLightObjectId139 * id of the SilverLight object to interact with140 * @return JavaScript prefix141 */142 static String createJSPrefixViaDocument(final String silverLightObjectId) {143 return "return document['" + silverLightObjectId + "'].";144 }145 /**146 * Execute function as a direct method.147 * 148 * @param functionName149 * function to be executed150 * @param args151 * parameters for the function152 * @return result153 */154 public final String executeDirectMethod(final String functionName, final String... args) {155 return getJSExecutor().executeScript(this.jsForDirectMethod(functionName, args)).toString();156 }157 public String executeContentMethod(final String functionName, final String... args) {158 return getJSExecutor().executeScript(this.jsForContentMethod(functionName, args)).toString();159 }160 public String getPropertyValue(String propertyName) {161 return getJSExecutor().executeScript(this.jsForContentScriptGetProperty(propertyName)).toString();162 }163 public String setPropertyValue(String propertyName, String arg) {164 return getJSExecutor().executeScript(this.jsForContentScriptSetProperty(propertyName, arg)).toString();165 }166 public String call(String functionName, String... args) {167 return getJSExecutor().executeScript(this.jsForContentScriptMethod(functionName, args)).toString();168 }169 public String getSettingsProperty(String propertyName) {170 return getJSExecutor().executeScript(this.jsForSettingsProperty(propertyName)).toString();171 }172 public String getContentProperty(String propertyName) {173 return getJSExecutor().executeScript(this.jsForContentProperty(propertyName)).toString();174 }175 public String getDirectProperty(String propertyName) {176 return getJSExecutor().executeScript(this.jsForDirectProperty(propertyName)).toString();177 }178 String silverLightJSStringPrefix() {179 return this.silverLightJSStringPrefix;180 }181 String jsForDirectMethod(String functionName, String... args) {182 String functionArgs = "";183 if (args.length > 0) {184 for (int i = 0; i < args.length; i++) {185 functionArgs = functionArgs + "'" + args[i] + "',";186 }187 // remove last comma188 functionArgs = functionArgs.substring(0, functionArgs.length() - 1);189 }190 return silverLightJSStringPrefix + functionName + "(" + functionArgs + ");";191 }192 String jsForContentScriptMethod(final String functionName, String... args) {193 String functionArgs = "";194 if (args.length > 0) {195 for (int i = 0; i < args.length; i++) {196 functionArgs = functionArgs + "'" + args[i] + "',";197 }198 // remove last comma199 functionArgs = functionArgs.substring(0, functionArgs.length() - 1);200 }201 return silverLightJSStringPrefix + "content." + scriptKey + functionName + "(" + functionArgs + ");";202 }203 String jsForContentScriptGetProperty(String propertyName) {204 return silverLightJSStringPrefix + "content." + scriptKey + propertyName + ";";205 }206 String jsForContentScriptSetProperty(String propertyName, String arg) {207 return silverLightJSStringPrefix + "content." + scriptKey + propertyName + "='" + arg + "';";208 }209 String jsForContentMethod(String functionName, String... args) {210 String functionArgs = "";211 if (args.length > 0) {212 for (int i = 0; i < args.length; i++) {213 functionArgs = functionArgs + "'" + args[i] + "',";214 }215 // remove last comma216 functionArgs = functionArgs.substring(0, functionArgs.length() - 1);217 }218 return silverLightJSStringPrefix + "content." + functionName + "(" + functionArgs + ");";219 }220 String jsForSettingsProperty(String propertyName) {221 return silverLightJSStringPrefix + "settings." + propertyName + ";";222 }223 String jsForContentProperty(String propertyName) {224 return silverLightJSStringPrefix + "content." + propertyName + ";";225 }226 /**227 * Construct JavaScript to read direct property.228 * 229 * @param propertyName230 * which direct property to ask for231 * @return JavaScript to read direct property232 */233 final String jsForDirectProperty(final String propertyName) {234 return silverLightJSStringPrefix + propertyName + ";";235 }236 @Override237 public final int hashCode() {238 final int prime = 31;239 int result = 1;240 int jsExecutorHash = 0;241 if (getJSExecutor() != null) {242 jsExecutorHash = getJSExecutor().hashCode();243 }244 result = prime * result + jsExecutorHash;245 int jssStringPrefixHash = 0;246 if (silverLightJSStringPrefix != null) {247 jssStringPrefixHash = silverLightJSStringPrefix.hashCode();248 }249 result = prime * result + jssStringPrefixHash;250 return result;251 }252 @Override253 public final boolean equals(final Object obj) {254 if (this == obj) {255 return true;256 }257 if (obj == null) {258 return false;259 }260 if (getClass() != obj.getClass()) {261 return false;262 }263 final SilverlightWrapper other = (SilverlightWrapper) obj;264 if (getJSExecutor() == null) {265 if (other.getJSExecutor() != null) {266 return false;267 }268 } else if (!getJSExecutor().equals(other.getJSExecutor())) {269 return false;270 }271 if (silverLightJSStringPrefix == null) {272 if (other.silverLightJSStringPrefix != null) {273 return false;274 }275 } else if (!silverLightJSStringPrefix.equals(other.silverLightJSStringPrefix)) {276 return false;277 }278 return true;279 }280 /**281 * Verify whether this version of Silverlight is being supported.282 * 283 * @param versionString284 * version to be checked285 * @return yes/no286 */287 public final Boolean isVersionSupported(final String versionString) {288 return new Boolean(this.executeDirectMethod("isVersionSupported", versionString));289 }...

Full Screen

Full Screen

Source:SoloIncomeApproval.java Github

copy

Full Screen

...61 Thread.sleep(5000);62 WindowHandleSupport.getRequiredWindowDriverWithIndex(driver, 1);63 boolean isApplicationPresent= false;64 String docNo= refNo.getText().toString();65 if(refNumber.equalsIgnoreCase(docNo)){66 isApplicationPresent= true;67 }68 return isApplicationPresent;69 }70 71 public boolean verifyPensionableAmount(String colName, String file, String sheet) throws InterruptedException{72 boolean matched=false;73 String strPayExcludingNHSPS= ExcelUtilities.getKeyValueByPosition(file, sheet, "PayExcludingNHSPS", colName);74 double payExcludingNHSPS= Double.parseDouble(strPayExcludingNHSPS);75 Thread.sleep(500);76 String strProfessionalExpenses= ExcelUtilities.getKeyValueByPosition(file, sheet, "ProfessionalExpenses", colName);77 double professionalExpenses= Double.parseDouble(strProfessionalExpenses);78 Thread.sleep(500);79 String strPayExcludingNHSPS_Portal= Support.getValueByJavaScript(driver, "SOLODetails_ExcludingNHSPSContributions");80 double payExcludingNHSPS_Portal= Double.parseDouble(strPayExcludingNHSPS_Portal);81 Thread.sleep(500);82 String strProfessionalExpenses_Portal= Support.getValueByJavaScript(driver, "SOLODetails_ProfessionalNHSExpenses");83 double professionalExpenses_Portal= Double.parseDouble(strProfessionalExpenses_Portal);84 Thread.sleep(500);85 double actualAmt= payExcludingNHSPS-professionalExpenses;86 actualAmt= GPPHelpers.convertValueToDecimals(actualAmt,2);87 double expAmt= payExcludingNHSPS_Portal-professionalExpenses_Portal;88 expAmt= GPPHelpers.convertValueToDecimals(expAmt,2);89 90 if(actualAmt==expAmt){91 matched=true;92 }93 return matched;94 }95 96 public boolean verifyEmployeeContribution(String scriptKey, String testDataFileName, String testDataSheet,String amtTierSheet) throws InterruptedException {97 boolean contributionMatched=false;98 List<Double>expActualValues= getCalculatedValues(scriptKey,testDataFileName,testDataSheet,amtTierSheet);99 double contributionAmt= expActualValues.get(0);100 double actualContriAmt= expActualValues.get(1);101 if(contributionAmt==actualContriAmt){102 contributionMatched=true;103 }104 return contributionMatched;105 }106 107 private List<Double> getCalculatedValues(String scriptKey, String testDataFileName, String testDataSheet,108 String amtTierSheet) throws InterruptedException {109 List<Double> values= new ArrayList<Double>();110 double criteria = 0.00,startRange=0.00,endRange,contributionAmt=0.00;111 String strPensionableAmt= Support.getValueByJavaScript(driver, "SOLODetails_NHSPensionablePay");112 double pensionableAmt= Double.parseDouble(strPensionableAmt);113 Thread.sleep(500);114 pensionableAmt= GPPHelpers.convertValueToDecimals(pensionableAmt,2);115 116 String strAnnualAmt= ExcelUtilities.getKeyValueByPosition(testDataFileName, testDataSheet, "AnnualIncome", scriptKey);117 double annualAmt= Double.parseDouble(strAnnualAmt);118 Thread.sleep(500);119 annualAmt= GPPHelpers.convertValueToDecimals(annualAmt,2);120 121 double finalAmount= pensionableAmt+annualAmt;122 123 List<String>ranges= ExcelUtilities.getCellValuesByPosition(testDataFileName, amtTierSheet, "Range");124 int rangeSize= ranges.size();125 List<String>critria= ExcelUtilities.getCellValuesByPosition(testDataFileName, amtTierSheet, "Criteria");126 127 for(int i=0;i<rangeSize;i++){128 String range= ranges.get(i);129 String[]rangeArray= range.split("-");130 String strStartRange= rangeArray[0].toString();131 startRange= Double.parseDouble(strStartRange);132 startRange= GPPHelpers.convertValueToDecimals(startRange,2);133 String strEndRange= rangeArray[1].toString();134 if(!(strEndRange.equalsIgnoreCase("over"))){135 endRange= Double.parseDouble(strEndRange);136 Thread.sleep(500);137 endRange= GPPHelpers.convertValueToDecimals(endRange,2);138 if((finalAmount>=startRange)&&(finalAmount<=endRange)){139 String strCriteria= critria.get(i);140 criteria= Double.parseDouble(strCriteria);141 Thread.sleep(500);142 criteria= GPPHelpers.convertValueToDecimals(criteria,2);143 break;144 }145 }else{146 Thread.sleep(500);147 if((finalAmount>=startRange)){148 String strCriteria= critria.get(i);...

Full Screen

Full Screen

Source:JavascriptExecutor.java Github

copy

Full Screen

1// Licensed to the Software Freedom Conservancy (SFC) under one2// or more contributor license agreements. See the NOTICE file3// distributed with this work for additional information4// regarding copyright ownership. The SFC licenses this file5// to you under the Apache License, Version 2.0 (the6// "License"); you may not use this file except in compliance7// with the License. You may obtain a copy of the License at8//9// http://www.apache.org/licenses/LICENSE-2.010//11// Unless required by applicable law or agreed to in writing,12// software distributed under the License is distributed on an13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY14// KIND, either express or implied. See the License for the15// specific language governing permissions and limitations16// under the License.17package org.openqa.selenium;18import org.openqa.selenium.internal.Require;19import java.util.Collections;20import java.util.Set;21import java.util.stream.Collectors;22/**23 * Indicates that a driver can execute JavaScript, providing access to the mechanism to do so.24 *25 * <p>26 * Because of cross domain policies browsers enforce your script execution may fail unexpectedly27 * and without adequate error messaging. This is particularly pertinent when creating your own28 * XHR request or when trying to access another frame. Most times when troubleshooting failure it's29 * best to view the browser's console after executing the WebDriver request.30 */31public interface JavascriptExecutor {32 /**33 * Executes JavaScript in the context of the currently selected frame or window. The script34 * fragment provided will be executed as the body of an anonymous function.35 *36 * <p>37 * Within the script, use <code>document</code> to refer to the current document. Note that local38 * variables will not be available once the script has finished executing, though global variables39 * will persist.40 *41 * <p>42 * If the script has a return value (i.e. if the script contains a <code>return</code> statement),43 * then the following steps will be taken:44 *45 * <ul>46 * <li>For an HTML element, this method returns a WebElement</li>47 * <li>For a decimal, a Double is returned</li>48 * <li>For a non-decimal number, a Long is returned</li>49 * <li>For a boolean, a Boolean is returned</li>50 * <li>For all other cases, a String is returned.</li>51 * <li>For an array, return a List&lt;Object&gt; with each object following the rules above. We52 * support nested lists.</li>53 * <li>For a map, return a Map&lt;String, Object&gt; with values following the rules above.</li>54 * <li>Unless the value is null or there is no return value, in which null is returned</li>55 * </ul>56 *57 * <p>58 * Arguments must be a number, a boolean, a String, WebElement, or a List of any combination of59 * the above. An exception will be thrown if the arguments do not meet these criteria. The60 * arguments will be made available to the JavaScript via the "arguments" magic variable, as if61 * the function were called via "Function.apply"62 *63 * @param script The JavaScript to execute64 * @param args The arguments to the script. May be empty65 * @return One of Boolean, Long, Double, String, List, Map or WebElement. Or null.66 */67 Object executeScript(String script, Object... args);68 /**69 * Execute an asynchronous piece of JavaScript in the context of the currently selected frame or70 * window. Unlike executing {@link #executeScript(String, Object...) synchronous JavaScript},71 * scripts executed with this method must explicitly signal they are finished by invoking the72 * provided callback. This callback is always injected into the executed function as the last73 * argument.74 *75 * <p>76 * The first argument passed to the callback function will be used as the script's result. This77 * value will be handled as follows:78 *79 * <ul>80 * <li>For an HTML element, this method returns a WebElement</li>81 * <li>For a number, a Long is returned</li>82 * <li>For a boolean, a Boolean is returned</li>83 * <li>For all other cases, a String is returned.</li>84 * <li>For an array, return a List&lt;Object&gt; with each object following the rules above. We85 * support nested lists.</li>86 * <li>For a map, return a Map&lt;String, Object&gt; with values following the rules above.</li>87 * <li>Unless the value is null or there is no return value, in which null is returned</li>88 * </ul>89 *90 * <p>91 * The default timeout for a script to be executed is 0ms. In most cases, including the examples92 * below, one must set the script timeout93 * {@link WebDriver.Timeouts#setScriptTimeout(java.time.Duration)} beforehand94 * to a value sufficiently large enough.95 *96 *97 * <p>98 * Example #1: Performing a sleep in the browser under test. <pre>{@code99 * long start = System.currentTimeMillis();100 * ((JavascriptExecutor) driver).executeAsyncScript(101 * "window.setTimeout(arguments[arguments.length - 1], 500);");102 * System.out.println(103 * "Elapsed time: " + System.currentTimeMillis() - start);104 * }</pre>105 *106 * <p>107 * Example #2: Synchronizing a test with an AJAX application: <pre>{@code108 * WebElement composeButton = driver.findElement(By.id("compose-button"));109 * composeButton.click();110 * ((JavascriptExecutor) driver).executeAsyncScript(111 * "var callback = arguments[arguments.length - 1];" +112 * "mailClient.getComposeWindowWidget().onload(callback);");113 * driver.switchTo().frame("composeWidget");114 * driver.findElement(By.id("to")).sendKeys("bog@example.com");115 * }</pre>116 *117 * <p>118 * Example #3: Injecting a XMLHttpRequest and waiting for the result: <pre>{@code119 * Object response = ((JavascriptExecutor) driver).executeAsyncScript(120 * "var callback = arguments[arguments.length - 1];" +121 * "var xhr = new XMLHttpRequest();" +122 * "xhr.open('GET', '/resource/data.json', true);" +123 * "xhr.onreadystatechange = function() {" +124 * " if (xhr.readyState == 4) {" +125 * " callback(xhr.responseText);" +126 * " }" +127 * "};" +128 * "xhr.send();");129 * JsonObject json = new JsonParser().parse((String) response);130 * assertEquals("cheese", json.get("food").getAsString());131 * }</pre>132 *133 * <p>134 * Script arguments must be a number, a boolean, a String, WebElement, or a List of any135 * combination of the above. An exception will be thrown if the arguments do not meet these136 * criteria. The arguments will be made available to the JavaScript via the "arguments"137 * variable.138 *139 *140 * @param script The JavaScript to execute.141 * @param args The arguments to the script. May be empty.142 * @return One of Boolean, Long, String, List, Map, WebElement, or null.143 * @see WebDriver.Timeouts#setScriptTimeout(java.time.Duration)144 */145 Object executeAsyncScript(String script, Object... args);146 /**147 * Commonly used scripts may be "pinned" to the WebDriver session,148 * allowing them to be called efficiently by their handle rather than149 * sending the entire script across the wire for every call.150 * <p>151 * The default implementation of this adheres to the API's expectations152 * but is inefficient.153 *154 * @see #executeScript(ScriptKey, Object...)155 * @param script The Javascript to execute.156 * @return A handle which may later be used in {@link #executeScript(ScriptKey, Object...)}157 * @throws JavascriptException If the script cannot be pinned for some reason.158 */159 default ScriptKey pin(String script) {160 Require.nonNull("Script to pin", script);161 return UnpinnedScriptKey.pin(this, script);162 }163 /**164 * Deletes the reference to a script that has previously been pinned.165 * Subsequent calls to {@link #executeScript(ScriptKey, Object...)} will166 * fail for the given {@code key}.167 */168 default void unpin(ScriptKey key) {169 Require.nonNull("Key to unpin", key);170 Require.stateCondition(171 key instanceof UnpinnedScriptKey,172 "Script key should have been generated by this driver");173 UnpinnedScriptKey.unpin(this, (UnpinnedScriptKey) key);174 }175 /**176 * @return The {@link ScriptKey}s of all currently pinned scripts.177 */178 default Set<ScriptKey> getPinnedScripts() {179 return Collections.unmodifiableSet(UnpinnedScriptKey.getPinnedScripts(this).stream()180 .map(key -> (ScriptKey) key)181 .collect(Collectors.toSet()));182 }183 /**184 * Calls a script by the {@link ScriptKey} returned by {@link #pin(String)}.185 * This can be thought of as inlining the pinned script and simply calling186 * {@link #executeScript(String, Object...)}.187 *188 * @see #executeScript(String, Object...)189 */190 default Object executeScript(ScriptKey key, Object... args) {191 Require.stateCondition(192 key instanceof UnpinnedScriptKey,193 "Script key should have been generated by this driver");194 if (!getPinnedScripts().contains(key)) {195 throw new JavascriptException("Script is unpinned");196 }197 return executeScript(((UnpinnedScriptKey) key).getScript(), args);198 }199}...

Full Screen

Full Screen

Source:UnpinnedScriptKey.java Github

copy

Full Screen

...49 String getScript() {50 return script;51 }52 @Override53 public boolean equals(Object o) {54 if (this == o) {55 return true;56 }57 if (o == null || getClass() != o.getClass()) {58 return false;59 }60 if (!super.equals(o)) {61 return false;62 }63 UnpinnedScriptKey that = (UnpinnedScriptKey) o;64 return Objects.equals(this.script, that.script);65 }66 @Override67 public int hashCode() {68 return Objects.hash(super.hashCode(), script);69 }70}...

Full Screen

Full Screen

Source:ScriptKey.java Github

copy

Full Screen

...22 public ScriptKey(String identifier) {23 this.identifier = Require.nonNull("Script ID", identifier);24 }25 @Override26 public boolean equals(Object o) {27 if (!(o instanceof ScriptKey)) {28 return false;29 }30 ScriptKey that = (ScriptKey) o;31 return Objects.equals(this.identifier, that.identifier);32 }33 @Override34 public int hashCode() {35 return Objects.hash(identifier);36 }37 private String toJson() {38 return identifier;39 }40 private static ScriptKey fromJson(String identifier) {41 return new ScriptKey(identifier);42 }43}...

Full Screen

Full Screen

equals

Using AI Code Generation

copy

Full Screen

1driver.findElement(By.name("q")).sendKeys(Keys.chord(Keys.CONTROL, "a"), "webdriver");2driver.findElement(By.name("q")).sendKeys(Keys.chord(Keys.CONTROL, "a"), "webdriver");3driver.findElement(By.name("q")).sendKeys(Keys.chord(Keys.CONTROL, "a"), "webdriver");4driver.findElement(By.name("q")).sendKeys(Keys.chord(Keys.CONTROL, "a"), "webdriver");5driver.findElement(By.name("q")).sendKeys(Keys.chord(Keys.CONTROL, "a"), "webdriver");6driver.findElement(By.name("q")).sendKeys(Keys.chord(Keys.CONTROL, "a"), "webdriver");7driver.findElement(By.name("q")).sendKeys(Keys.chord(Keys.CONTROL, "a"), "webdriver");8driver.findElement(By.name("q")).sendKeys(Keys.chord(Keys.CONTROL, "a"), "webdriver");9driver.findElement(By.name("q")).sendKeys(Keys.chord(Keys.CONTROL, "a"), "webdriver");10driver.findElement(By.name("q")).sendKeys(Keys.chord(Keys.CONTROL, "a"), "webdriver");11driver.findElement(By.name("q")).sendKeys(Keys.chord(Keys.CONTROL, "a"), "webdriver");12driver.findElement(By.name("q")).sendKeys(Keys.chord(Keys.CONTROL, "a"), "webdriver");13driver.findElement(By.name("q")).sendKeys(Keys.chord(Keys.CONTROL, "a"), "webdriver");14driver.findElement(By.name("q")).sendKeys(Keys.chord(Keys.CONTROL, "a"), "webdriver");15driver.findElement(By.name("q")).sendKeys(Keys.chord(Keys.CONTROL, "a"), "webdriver");16driver.findElement(By.name("q")).sendKeys(Keys.chord(Keys.CONTROL, "a"), "webdriver");17driver.findElement(By.name("q")).sendKeys(Keys.chord(Keys.CONTROL, "a"), "webdriver");18driver.findElement(By.name("q")).sendKeys(Keys.chord(Keys.CONTROL, "a"), "webdriver");

Full Screen

Full Screen

equals

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.Keys;2String value = Keys.chord(Keys.CONTROL, "a");3System.out.println(value);4System.out.println(Keys.chord(Keys.CONTROL, "a").equals(value));5import org.openqa.selenium.interactions.Action;6import org.openqa.selenium.interactions.Actions;7Action action = new Actions(driver).sendKeys(Keys.chord(Keys.CONTROL, "a")).build();8System.out.println(action);9System.out.println(action.equals(action));10import org.openqa.selenium.WebDriver;11import org.openqa.selenium.chrome.ChromeDriver;12WebDriver driver = new ChromeDriver();13System.out.println(driver.manage().window());14System.out.println(driver.manage().window().equals(driver.manage().window()));15import org.openqa.selenium.WebDriver;16import org.openqa.selenium.chrome.ChromeDriver;17WebDriver driver = new ChromeDriver();18System.out.println(driver.navigate());19System.out.println(driver.navigate().equals(driver.navigate()));20import org.openqa.selenium.WebDriver;21import org.openqa.selenium.chrome.ChromeDriver;22WebDriver driver = new ChromeDriver();23System.out.println(driver.switchTo());24System.out.println(driver.switchTo().equals(driver.switchTo()));25import org.openqa.selenium.WebDriver;26import org.openqa.selenium.chrome.ChromeDriver;27WebDriver driver = new ChromeDriver();28System.out.println(driver.manage().timeouts());29System.out.println(driver.manage().timeouts().equals(driver.manage().timeouts()));30import org.openqa.selenium.WebDriver;31import org.openqa

Full Screen

Full Screen

equals

Using AI Code Generation

copy

Full Screen

1driver.findElement(By.id("login")).sendKeys(ScriptKey.ENTER);2driver.findElement(By.id("login")).sendKeys(ScriptKey.BACK_SPACE);3driver.findElement(By.id("login")).sendKeys(ScriptKey.TAB);4driver.findElement(By.id("login")).sendKeys(ScriptKey.DELETE);5driver.findElement(By.id("login")).sendKeys(ScriptKey.ESCAPE);6driver.findElement(By.id("login")).sendKeys(ScriptKey.SPACE);7driver.findElement(By.id("login")).sendKeys(ScriptKey.PAGE_UP);8driver.findElement(By.id("login")).sendKeys(ScriptKey.PAGE_DOWN);9driver.findElement(By.id("login")).sendKeys(ScriptKey.END);10driver.findElement(By.id("login")).sendKeys(ScriptKey.HOME);11driver.findElement(By.id("login")).sendKeys(ScriptKey.INSERT);12driver.findElement(By.id("login")).sendKeys(ScriptKey.F1);

Full Screen

Full Screen

equals

Using AI Code Generation

copy

Full Screen

1${CHROME_DRIVER_PATH} C:/Users/Prashanth/Documents/Python/Python38/chromedriver.exe2${BROWSER} Chrome3${IMPLICIT_WAIT} 104${TIMEOUT} 105${SCRIPT_TIMEOUT} 106${PAGE_LOAD_TIMEOUT} 107${SEARCH_TEXT} Selenium8${SEARCH_TEXT2} Selenium Python9${SEARCH_TEXT3} Selenium Python Tutorial10 Open Browser ${URL} ${BROWSER} chrome_options=${CHROME_OPTIONS}11 Set Selenium Implicit Wait ${IMPLICIT_WAIT}12 Set Selenium Timeout ${TIMEOUT}13 Set Selenium Script Timeout ${SCRIPT_TIMEOUT}14 Set Selenium Page Load Timeout ${PAGE_LOAD_TIMEOUT}

Full Screen

Full Screen

Selenium 4 Tutorial:

LambdaTest’s Selenium 4 tutorial is covering every aspects of Selenium 4 testing with examples and best practices. Here you will learn basics, such as how to upgrade from Selenium 3 to Selenium 4, to some advanced concepts, such as Relative locators and Selenium Grid 4 for Distributed testing. Also will learn new features of Selenium 4, such as capturing screenshots of specific elements, opening a new tab or window on the browser, and new protocol adoptions.

Chapters:

  1. Upgrading From Selenium 3 To Selenium 4?: In this chapter, learn in detail how to update Selenium 3 to Selenium 4 for Java binding. Also, learn how to upgrade while using different build tools such as Maven or Gradle and get comprehensive guidance for upgrading Selenium.

  2. What’s New In Selenium 4 & What’s Being Deprecated? : Get all information about new implementations in Selenium 4, such as W3S protocol adaption, Optimized Selenium Grid, and Enhanced Selenium IDE. Also, learn what is deprecated for Selenium 4, such as DesiredCapabilites and FindsBy methods, etc.

  3. Selenium 4 With Python: Selenium supports all major languages, such as Python, C#, Ruby, and JavaScript. In this chapter, learn how to install Selenium 4 for Python and the features of Python in Selenium 4, such as Relative locators, Browser manipulation, and Chrom DevTool protocol.

  4. Selenium 4 Is Now W3C Compliant: JSON Wireframe protocol is retiring from Selenium 4, and they are adopting W3C protocol to learn in detail about the advantages and impact of these changes.

  5. How To Use Selenium 4 Relative Locator? : Selenium 4 came with new features such as Relative Locators that allow constructing locators with reference and easily located constructors nearby. Get to know its different use cases with examples.

  6. Selenium Grid 4 Tutorial For Distributed Testing: Selenium Grid 4 allows you to perform tests over different browsers, OS, and device combinations. It also enables parallel execution browser testing, reads up on various features of Selenium Grid 4 and how to download it, and runs a test on Selenium Grid 4 with best practices.

  7. Selenium Video Tutorials: Binge on video tutorials on Selenium by industry experts to get step-by-step direction from automating basic to complex test scenarios with Selenium.

Selenium 101 certifications:

LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.

Run Selenium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in ScriptKey

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful