From 766e93ccaa11f8534e9ffae5c095399aedc04c2e Mon Sep 17 00:00:00 2001 From: Tom Bishop Date: Tue, 30 Jan 2024 14:38:28 -0500 Subject: [PATCH] CLDR-17316 cldr-apps-webdriver Java formatting with spotless (#41) -Add toggleOffOn in pom.xml (the cldr project does not have that) -Add spotless:on and spotless:off comments in SurveyDriverData.java, replacing prettier-ignore -Other changes are only formatting results of running mvn spotless:apply --- pom.xml | 1 + .../cldr/surveydriver/SurveyDriver.java | 377 +++++++++++------- .../surveydriver/SurveyDriverCredentials.java | 9 +- .../surveydriver/SurveyDriverDashboard.java | 5 +- .../cldr/surveydriver/SurveyDriverData.java | 64 +-- .../SurveyDriverVettingTable.java | 124 +++--- .../surveydriver/SurveyDriverXMLUploader.java | 42 +- 7 files changed, 361 insertions(+), 261 deletions(-) diff --git a/pom.xml b/pom.xml index a4dfcc3..f7f8923 100644 --- a/pom.xml +++ b/pom.xml @@ -58,6 +58,7 @@ NONE + diff --git a/src/test/java/org/unicode/cldr/surveydriver/SurveyDriver.java b/src/test/java/org/unicode/cldr/surveydriver/SurveyDriver.java index 118bb96..4af10e4 100644 --- a/src/test/java/org/unicode/cldr/surveydriver/SurveyDriver.java +++ b/src/test/java/org/unicode/cldr/surveydriver/SurveyDriver.java @@ -130,8 +130,10 @@ private void setUp() { ChromeOptions options = new ChromeOptions(); options.setCapability("goog:loggingPrefs", logPrefs); - // options.addArguments("start-maximized"); // this works, but inconvenient especially if more than one - // options.addArguments("auto-open-devtools-for-tabs"); // this works, but makes window too narrow + // options.addArguments("start-maximized"); // this works, but inconvenient especially if + // more than one + // options.addArguments("auto-open-devtools-for-tabs"); // this works, but makes window too + // narrow if (USE_REMOTE_WEBDRIVER) { try { driver = new RemoteWebDriver(new URL(REMOTE_WEBDRIVER_URL + "/wd/hub"), options); @@ -139,11 +141,16 @@ private void setUp() { SurveyDriverLog.println(e); } sessionId = ((RemoteWebDriver) driver).getSessionId(); - SurveyDriverLog.println("Session id = " + sessionId); // e.g., 9c0d7d317d64cb53b6eaefc70427d4d8 + SurveyDriverLog.println( + "Session id = " + sessionId); // e.g., 9c0d7d317d64cb53b6eaefc70427d4d8 } else { driver = new ChromeDriver(options); } - wait = new WebDriverWait(driver, Duration.ofSeconds(TIME_OUT_SECONDS), Duration.ofMillis(SLEEP_MILLISECONDS)); + wait = + new WebDriverWait( + driver, + Duration.ofSeconds(TIME_OUT_SECONDS), + Duration.ofMillis(SLEEP_MILLISECONDS)); if (USE_REMOTE_WEBDRIVER) { userIndex = getUserIndexFromGrid(sessionId); } @@ -151,7 +158,8 @@ private void setUp() { /** Clean up when finished testing. */ private void tearDown() { - SurveyDriverLog.println("cldr-apps-webdriver is quitting, goodbye from sessionId " + sessionId); + SurveyDriverLog.println( + "cldr-apps-webdriver is quitting, goodbye from sessionId " + sessionId); if (driver != null) { /* * This five-second sleep may not always be appropriate. It can help to see the browser for a few seconds @@ -206,7 +214,8 @@ private boolean testFastVoting() { * If this exception becomes problematic, we should investigate ways to catch it * and continue wherever it occurs. */ - SurveyDriverLog.println("Continuing main loop after StaleElementReferenceException, i = " + i); + SurveyDriverLog.println( + "Continuing main loop after StaleElementReferenceException, i = " + i); } } SurveyDriverLog.println("✅ Fast vote test passed for " + loc + ", " + page); @@ -264,8 +273,10 @@ private boolean testFastVotingInner(String page, String url) { * Adangme ► ada row_7d1d3cbd260601a4 * Acoli appears to be a new addition. */ - String[] rowIds = { "f3d4397b739b287", "6899b21f19eef8cc", "1660459cc74c9aec", "7d1d3cbd260601a4" }; - String[] cellClasses = { "nocell", "proposedcell" }; + String[] rowIds = { + "f3d4397b739b287", "6899b21f19eef8cc", "1660459cc74c9aec", "7d1d3cbd260601a4" + }; + String[] cellClasses = {"nocell", "proposedcell"}; final boolean verbose = true; for (String cell : cellClasses) { for (int i = 0; i < rowIds.length; i++) { @@ -279,7 +290,7 @@ private boolean testFastVotingInner(String page, String url) { String op = cell.equals("nocell") ? "Abstain" : "Vote"; SurveyDriverLog.println(op + " row " + (i + 1) + " (" + rowId + ")"); } - for (;;) { + for (; ; ) { try { rowEl = driver.findElement(By.id(rowId)); } catch (StaleElementReferenceException e) { @@ -287,18 +298,18 @@ private boolean testFastVotingInner(String page, String url) { break; } SurveyDriverLog.println( - "Continuing after StaleElementReferenceException for findElement by id rowId " + - rowId + - " for " + - url - ); + "Continuing after StaleElementReferenceException for findElement by id rowId " + + rowId + + " for " + + url); continue; } catch (Exception e) { SurveyDriverLog.println(e); break; } if (rowEl == null) { - SurveyDriverLog.println("❌ Fast vote test failed, missing row id " + rowId + " for " + url); + SurveyDriverLog.println( + "❌ Fast vote test failed, missing row id " + rowId + " for " + url); return false; } try { @@ -308,11 +319,10 @@ private boolean testFastVotingInner(String page, String url) { break; } SurveyDriverLog.println( - "Continuing after StaleElementReferenceException for findElement by class cellClass " + - cellClass + - " for " + - url - ); + "Continuing after StaleElementReferenceException for findElement by class cellClass " + + cellClass + + " for " + + url); continue; } catch (Exception e) { SurveyDriverLog.println(e); @@ -320,8 +330,12 @@ private boolean testFastVotingInner(String page, String url) { } if (columnEl == null) { SurveyDriverLog.println( - "❌ Fast vote test failed, no column " + cellClass + " for row " + rowId + " for " + url - ); + "❌ Fast vote test failed, no column " + + cellClass + + " for row " + + rowId + + " for " + + url); return false; } try { @@ -331,11 +345,10 @@ private boolean testFastVotingInner(String page, String url) { break; } SurveyDriverLog.println( - "Continuing after StaleElementReferenceException for findElement by tagName " + - rowId + - " for " + - url - ); + "Continuing after StaleElementReferenceException for findElement by tagName " + + rowId + + " for " + + url); continue; } catch (Exception e) { SurveyDriverLog.println(e); @@ -345,11 +358,17 @@ private boolean testFastVotingInner(String page, String url) { } if (clickEl == null) { SurveyDriverLog.println( - "❌ Fast vote test failed, no tag " + tagName + " for row " + rowId + " for " + url - ); + "❌ Fast vote test failed, no tag " + + tagName + + " for row " + + rowId + + " for " + + url); return false; } - clickEl = waitUntilRowCellTagElementClickable(clickEl, rowId, cellClass, tagName, url); + clickEl = + waitUntilRowCellTagElementClickable( + clickEl, rowId, cellClass, tagName, url); if (clickEl == null) { return false; } @@ -358,11 +377,10 @@ private boolean testFastVotingInner(String page, String url) { } catch (Exception e) { SurveyDriverLog.println(e); SurveyDriverLog.println( - "❌ Fast vote test failed, invisibilityOfElementLocated overlay for row " + - rowId + - " for " + - url - ); + "❌ Fast vote test failed, invisibilityOfElementLocated overlay for row " + + rowId + + " for " + + url); return false; } if (firstClickTime == 0.0) { @@ -375,15 +393,18 @@ private boolean testFastVotingInner(String page, String url) { break; } SurveyDriverLog.println( - "Continuing after StaleElementReferenceException for clickEl.click for row " + - rowId + - " for " + - url - ); + "Continuing after StaleElementReferenceException for clickEl.click for row " + + rowId + + " for " + + url); continue; } catch (Exception e) { SurveyDriverLog.println(e); - SurveyDriverLog.println("❌ Fast vote test failed, clickEl.click for row " + rowId + " for " + url); + SurveyDriverLog.println( + "❌ Fast vote test failed, clickEl.click for row " + + rowId + + " for " + + url); return false; } if (doAdd) { @@ -395,12 +416,16 @@ private boolean testFastVotingInner(String page, String url) { */ WebElement inputEl = waitInputBoxAppears(rowEl, url); if (inputEl == null) { - SurveyDriverLog.println("Warning: continuing, didn't see input box for " + url); + SurveyDriverLog.println( + "Warning: continuing, didn't see input box for " + url); continue; } - inputEl = waitUntilRowCellTagElementClickable(inputEl, rowId, cellClass, "input", url); + inputEl = + waitUntilRowCellTagElementClickable( + inputEl, rowId, cellClass, "input", url); if (inputEl == null) { - SurveyDriverLog.println("Warning: continuing, input box not clickable for " + url); + SurveyDriverLog.println( + "Warning: continuing, input box not clickable for " + url); continue; } inputEl.clear(); @@ -409,8 +434,10 @@ private boolean testFastVotingInner(String page, String url) { inputEl.sendKeys(Keys.RETURN); } catch (WebDriverException e) { SurveyDriverLog.println( - "Continuing after WebDriverException for doAdd for row " + rowId + " for " + url - ); + "Continuing after WebDriverException for doAdd for row " + + rowId + + " for " + + url); } } } @@ -425,7 +452,8 @@ private boolean testFastVotingInner(String page, String url) { return false; } double deltaTime = System.currentTimeMillis() - firstClickTime; - SurveyDriverLog.println("Total time elapsed since first click = " + deltaTime / 1000.0 + " sec"); + SurveyDriverLog.println( + "Total time elapsed since first click = " + deltaTime / 1000.0 + " sec"); return true; } @@ -511,12 +539,16 @@ private boolean inputTextByXpath(String xpath, String text, String url) { private WebElement getClickableElementByXpath(String xpath, String url) { try { - wait.until((ExpectedCondition) webDriver -> driver.findElement(By.xpath(xpath)) != null); + wait.until( + (ExpectedCondition) + webDriver -> driver.findElement(By.xpath(xpath)) != null); } catch (Exception e) { SurveyDriverLog.println(e); SurveyDriverLog.println( - "❌ Test failed, timed out waiting for element to be found by xpath " + xpath + " in url " + url - ); + "❌ Test failed, timed out waiting for element to be found by xpath " + + xpath + + " in url " + + url); return null; } WebElement el; @@ -526,8 +558,10 @@ private WebElement getClickableElementByXpath(String xpath, String url) { } catch (Exception e) { SurveyDriverLog.println(e); SurveyDriverLog.println( - "❌ Test failed, timed out waiting for " + xpath + " button to be clickable in " + url - ); + "❌ Test failed, timed out waiting for " + + xpath + + " button to be clickable in " + + url); return null; } return el; @@ -562,7 +596,8 @@ private boolean chooseComprehensiveCoverage(String url) { try { item.click(); } catch (Exception e) { - SurveyDriverLog.println("Exception caught while trying to choose Comprehensive from Coverage menu"); + SurveyDriverLog.println( + "Exception caught while trying to choose Comprehensive from Coverage menu"); SurveyDriverLog.println(e); return false; } @@ -577,7 +612,8 @@ private boolean testAllLocalesAndPages() { * Reference: https://unicode.org/cldr/trac/ticket/11238 "browser console shows error message, * there is INHERITANCE_MARKER without inheritedValue" */ - String searchString = "INHERITANCE_MARKER without inheritedValue"; // formerly, "there is no Bailey Target + String searchString = + "INHERITANCE_MARKER without inheritedValue"; // formerly, "there is no Bailey Target // item" for (String loc : locales) { @@ -615,18 +651,27 @@ private boolean testOneLocationAndPage(String loc, String page, String searchStr int searchStringCount = countLogEntriesContainingString(searchString); if (searchStringCount > 0) { SurveyDriverLog.println( - "❌ Test failed: " + searchStringCount + " occurrences in log of '" + searchString + "' for " + url - ); + "❌ Test failed: " + + searchStringCount + + " occurrences in log of '" + + searchString + + "' for " + + url); return false; } SurveyDriverLog.println( - "✅ Test passed: zero occurrences in log of '" + searchString + "' for " + loc + ", " + page - ); + "✅ Test passed: zero occurrences in log of '" + + searchString + + "' for " + + loc + + ", " + + page); WebElement el = null; try { el = driver.findElement(By.id("row_44fca52aa81abcb2")); - } catch (Exception ignored) {} + } catch (Exception ignored) { + } if (el != null) { SurveyDriverLog.println("✅✅✅ Got it in " + url); } @@ -705,13 +750,16 @@ private int countLogEntriesContainingString(String searchString) { public boolean waitForTitle(String s, String url) { try { wait.until( - (ExpectedCondition) webDriver -> (Objects.requireNonNull(webDriver).getTitle().contains(s)) - ); + (ExpectedCondition) + webDriver -> + (Objects.requireNonNull(webDriver).getTitle().contains(s))); } catch (Exception e) { SurveyDriverLog.println(e); SurveyDriverLog.println( - "❌ Test failed, maybe timed out, waiting for title to contain " + s + " in " + url - ); + "❌ Test failed, maybe timed out, waiting for title to contain " + + s + + " in " + + url); return false; } return true; @@ -727,16 +775,16 @@ public boolean waitUntilLoadingMessageDone(String url) { String loadingId = "LoadingMessageSection"; try { wait.until( - (ExpectedCondition) webDriver -> - Objects - .requireNonNull(webDriver) - .findElement(By.id(loadingId)) - .getCssValue("display") - .contains("none") - ); + (ExpectedCondition) + webDriver -> + Objects.requireNonNull(webDriver) + .findElement(By.id(loadingId)) + .getCssValue("display") + .contains("none")); } catch (Exception e) { SurveyDriverLog.println(e); - SurveyDriverLog.println("❌ Test failed, maybe timed out, waiting for " + loadingId + " in " + url); + SurveyDriverLog.println( + "❌ Test failed, maybe timed out, waiting for " + loadingId + " in " + url); return false; } return true; @@ -788,14 +836,16 @@ public boolean hideLeftSidebar(String url) { public boolean waitUntilElementActive(String id, String url) { try { wait.until( - (ExpectedCondition) webDriver -> { - WebElement el = Objects.requireNonNull(webDriver).findElement(By.id(id)); - return el != null && el.getAttribute("class").contains("active"); - } - ); + (ExpectedCondition) + webDriver -> { + WebElement el = + Objects.requireNonNull(webDriver).findElement(By.id(id)); + return el != null && el.getAttribute("class").contains("active"); + }); } catch (Exception e) { SurveyDriverLog.println(e); - SurveyDriverLog.println("❌ Test failed, maybe timed out, waiting for " + id + " in " + url); + SurveyDriverLog.println( + "❌ Test failed, maybe timed out, waiting for " + id + " in " + url); return false; } return true; @@ -811,14 +861,16 @@ public boolean waitUntilElementActive(String id, String url) { public boolean waitUntilElementInactive(String id, String url) { try { wait.until( - (ExpectedCondition) webDriver -> { - WebElement el = Objects.requireNonNull(webDriver).findElement(By.id(id)); - return el == null || !el.getAttribute("class").contains("active"); - } - ); + (ExpectedCondition) + webDriver -> { + WebElement el = + Objects.requireNonNull(webDriver).findElement(By.id(id)); + return el == null || !el.getAttribute("class").contains("active"); + }); } catch (Exception e) { SurveyDriverLog.println(e); - SurveyDriverLog.println("❌ Test failed, maybe timed out, waiting for inactive id " + id + " in " + url); + SurveyDriverLog.println( + "❌ Test failed, maybe timed out, waiting for inactive id " + id + " in " + url); return false; } return true; @@ -840,10 +892,13 @@ public WebElement waitInputBoxAppears(WebElement rowEl, String url) { */ WebElement inputEl = null; int repeats = 0; - for (;;) { + for (; ; ) { try { WebElement addCell = rowEl.findElement(By.className("addcell")); - inputEl = wait.until(ExpectedConditions.presenceOfNestedElementLocatedBy(addCell, By.tagName("input"))); + inputEl = + wait.until( + ExpectedConditions.presenceOfNestedElementLocatedBy( + addCell, By.tagName("input"))); /* * TODO: don't wait here for 30 seconds, as sometimes happens... */ @@ -851,7 +906,8 @@ public WebElement waitInputBoxAppears(WebElement rowEl, String url) { if (++repeats > 4) { break; } - SurveyDriverLog.println("waitInputBoxAppears repeating for StaleElementReferenceException"); + SurveyDriverLog.println( + "waitInputBoxAppears repeating for StaleElementReferenceException"); continue; } catch (Exception e) { /* @@ -859,7 +915,8 @@ public WebElement waitInputBoxAppears(WebElement rowEl, String url) { * input (tried for 30 second(s) with 100 milliseconds interval) */ SurveyDriverLog.println(e); - SurveyDriverLog.println("❌ Test failed, maybe timed out, waiting for input in addcell in " + url); + SurveyDriverLog.println( + "❌ Test failed, maybe timed out, waiting for input in addcell in " + url); } break; } @@ -872,7 +929,8 @@ public WebElement waitInputBoxAppears(WebElement rowEl, String url) { * @param className the class name * @param url the url we're loading * @return true for success, false for failure - */ public boolean clickButtonByClassName(String className, String url) { + */ + public boolean clickButtonByClassName(String className, String url) { WebElement button = driver.findElement(By.className(className)); if (!waitUntilElementClickable(button, url)) { return false; @@ -882,8 +940,10 @@ public WebElement waitInputBoxAppears(WebElement rowEl, String url) { } catch (Exception e) { SurveyDriverLog.println(e); SurveyDriverLog.println( - "❌ Test failed, maybe timed out, waiting button with class " + className + " to be clickable in " + url - ); + "❌ Test failed, maybe timed out, waiting button with class " + + className + + " to be clickable in " + + url); return false; } return true; @@ -902,8 +962,10 @@ public boolean waitUntilElementClickable(WebElement el, String url) { } catch (Exception e) { SurveyDriverLog.println(e); SurveyDriverLog.println( - "❌ Test failed, maybe timed out, waiting for " + el + " to be clickable in " + url - ); + "❌ Test failed, maybe timed out, waiting for " + + el + + " to be clickable in " + + url); return false; } return true; @@ -920,14 +982,9 @@ public boolean waitUntilElementClickable(WebElement el, String url) { * @return the (possibly updated) clickEl for success, null for failure */ public WebElement waitUntilRowCellTagElementClickable( - WebElement clickEl, - String rowId, - String cellClass, - String tagName, - String url - ) { + WebElement clickEl, String rowId, String cellClass, String tagName, String url) { int repeats = 0; - for (;;) { + for (; ; ) { try { wait.until(ExpectedConditions.elementToBeClickable(clickEl)); return clickEl; @@ -936,8 +993,7 @@ public WebElement waitUntilRowCellTagElementClickable( break; } SurveyDriverLog.println( - "waitUntilRowCellTagElementClickable repeating for StaleElementReferenceException" - ); + "waitUntilRowCellTagElementClickable repeating for StaleElementReferenceException"); WebElement rowEl = driver.findElement(By.id(rowId)); WebElement columnEl = rowEl.findElement(By.className(cellClass)); clickEl = columnEl.findElement(By.tagName(tagName)); @@ -945,7 +1001,8 @@ public WebElement waitUntilRowCellTagElementClickable( if (++repeats > 4) { break; } - SurveyDriverLog.println("waitUntilRowCellTagElementClickable repeating for NoSuchElementException"); + SurveyDriverLog.println( + "waitUntilRowCellTagElementClickable repeating for NoSuchElementException"); WebElement rowEl = driver.findElement(By.id(rowId)); WebElement columnEl = rowEl.findElement(By.className(cellClass)); clickEl = columnEl.findElement(By.tagName(tagName)); @@ -962,15 +1019,14 @@ public WebElement waitUntilRowCellTagElementClickable( } } SurveyDriverLog.println( - "❌ Test failed in waitUntilRowCellTagElementClickable for " + - rowId + - "," + - cellClass + - "," + - tagName + - " in " + - url - ); + "❌ Test failed in waitUntilRowCellTagElementClickable for " + + rowId + + "," + + cellClass + + "," + + tagName + + " in " + + url); return null; } @@ -984,14 +1040,9 @@ public WebElement waitUntilRowCellTagElementClickable( * @param url the url we're loading */ public void clickOnRowCellTagElement( - WebElement clickEl, - String rowId, - String cellClass, - String tagName, - String url - ) { + WebElement clickEl, String rowId, String cellClass, String tagName, String url) { int repeats = 0; - for (;;) { + for (; ; ) { try { clickEl.click(); return; @@ -1000,19 +1051,21 @@ public void clickOnRowCellTagElement( break; } SurveyDriverLog.println( - "clickOnRowCellTagElement repeating for StaleElementReferenceException for " + - rowId + - "," + - cellClass + - "," + - tagName + - " in " + - url - ); - int recreateStringCount = countLogEntriesContainingString("insertRows: recreating table from scratch"); + "clickOnRowCellTagElement repeating for StaleElementReferenceException for " + + rowId + + "," + + cellClass + + "," + + tagName + + " in " + + url); + int recreateStringCount = + countLogEntriesContainingString( + "insertRows: recreating table from scratch"); SurveyDriverLog.println( - "clickOnRowCellTagElement: log has " + recreateStringCount + " scratch messages" - ); + "clickOnRowCellTagElement: log has " + + recreateStringCount + + " scratch messages"); WebElement rowEl = driver.findElement(By.id(rowId)); WebElement columnEl = rowEl.findElement(By.className(cellClass)); clickEl = columnEl.findElement(By.tagName(tagName)); @@ -1022,8 +1075,14 @@ public void clickOnRowCellTagElement( } } SurveyDriverLog.println( - "❗ Test failed in clickOnRowCellTagElement for " + rowId + "," + cellClass + "," + tagName + " in " + url - ); + "❗ Test failed in clickOnRowCellTagElement for " + + rowId + + "," + + cellClass + + "," + + tagName + + " in " + + url); } /** @@ -1038,20 +1097,22 @@ public void clickOnRowCellTagElement( public boolean waitUntilClassExists(String className, boolean checking, String url) { try { wait.until( - (ExpectedCondition) webDriver -> { - int elCount = Objects.requireNonNull(webDriver).findElements(By.className(className)).size(); - return checking ? (elCount > 0) : (elCount == 0); - } - ); + (ExpectedCondition) + webDriver -> { + int elCount = + Objects.requireNonNull(webDriver) + .findElements(By.className(className)) + .size(); + return checking ? (elCount > 0) : (elCount == 0); + }); } catch (Exception e) { SurveyDriverLog.println(e); SurveyDriverLog.println( - "❌ Test failed, maybe timed out, waiting for class " + - className + - (checking ? "" : " not") + - " to exist for " + - url - ); + "❌ Test failed, maybe timed out, waiting for class " + + className + + (checking ? "" : " not") + + " to exist for " + + url); return false; } return true; @@ -1069,20 +1130,22 @@ public boolean waitUntilClassExists(String className, boolean checking, String u public boolean waitUntilIdExists(String idName, boolean checking, String url) { try { wait.until( - (ExpectedCondition) webDriver -> { - int elCount = Objects.requireNonNull(webDriver).findElements(By.id(idName)).size(); - return checking ? (elCount > 0) : (elCount == 0); - } - ); + (ExpectedCondition) + webDriver -> { + int elCount = + Objects.requireNonNull(webDriver) + .findElements(By.id(idName)) + .size(); + return checking ? (elCount > 0) : (elCount == 0); + }); } catch (Exception e) { SurveyDriverLog.println(e); SurveyDriverLog.println( - "❌ Test failed, maybe timed out, waiting for id " + - idName + - (checking ? "" : " not") + - " to exist for " + - url - ); + "❌ Test failed, maybe timed out, waiting for id " + + idName + + (checking ? "" : " not") + + " to exist for " + + url); return false; } return true; @@ -1134,7 +1197,11 @@ private int getUserIndexFromGrid(SessionId sessionId) { } if (uIndex < 0) { uIndex = new Random().nextInt(9); - System.out.println("Setting user index randomly to " + uIndex + "; unable to determine from " + url); + System.out.println( + "Setting user index randomly to " + + uIndex + + "; unable to determine from " + + url); } return uIndex; } diff --git a/src/test/java/org/unicode/cldr/surveydriver/SurveyDriverCredentials.java b/src/test/java/org/unicode/cldr/surveydriver/SurveyDriverCredentials.java index 6437f83..1782f8f 100644 --- a/src/test/java/org/unicode/cldr/surveydriver/SurveyDriverCredentials.java +++ b/src/test/java/org/unicode/cldr/surveydriver/SurveyDriverCredentials.java @@ -10,6 +10,7 @@ public class SurveyDriverCredentials { * "driver-123@cldr-apps-webdriver.org" */ private static final String EMAIL_AT_DOMAIN = "@cldr-apps-webdriver.org"; + private static final String EMAIL_PREFIX = "driver-"; /** @@ -17,6 +18,7 @@ public class SurveyDriverCredentials { * -- not in version control; contains a line WEBDRIVER_PASSWORD=... */ private static final String PROPS_FILENAME = "surveydriver.properties"; + private static final String PROPS_PASSWORD_KEY = "WEBDRIVER_PASSWORD"; private static String webdriverPassword = null; @@ -27,8 +29,8 @@ private SurveyDriverCredentials(String email) { } /** - * Get credentials for logging in as a particular user depending on which Selenium slot - * we're running on. + * Get credentials for logging in as a particular user depending on which Selenium slot we're + * running on. */ public static SurveyDriverCredentials getForUser(int userIndex) { String email = EMAIL_PREFIX + userIndex + EMAIL_AT_DOMAIN; @@ -43,7 +45,8 @@ public String getPassword() { if (webdriverPassword != null) { return webdriverPassword; } - final InputStream stream = SurveyDriverCredentials.class.getResourceAsStream(PROPS_FILENAME); + final InputStream stream = + SurveyDriverCredentials.class.getResourceAsStream(PROPS_FILENAME); if (stream == null) { throw new RuntimeException("File not found: " + PROPS_FILENAME); } diff --git a/src/test/java/org/unicode/cldr/surveydriver/SurveyDriverDashboard.java b/src/test/java/org/unicode/cldr/surveydriver/SurveyDriverDashboard.java index 5deeabc..9fb0e78 100644 --- a/src/test/java/org/unicode/cldr/surveydriver/SurveyDriverDashboard.java +++ b/src/test/java/org/unicode/cldr/surveydriver/SurveyDriverDashboard.java @@ -1,8 +1,6 @@ package org.unicode.cldr.surveydriver; -import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; public class SurveyDriverDashboard { @@ -53,7 +51,8 @@ private boolean testOne(int i) { // button is from GeneralInfo.vue, and its class includes "general-open-dash". // There are other "Open Dashboard" buttons produced in cldrGui.mjs, and a // "Dashboard" item in the left-sidebar. - // For unknown reasons, clickButtonByXpath with "//button[contains(., 'Open Dashboard')]" fails here. + // For unknown reasons, clickButtonByXpath with "//button[contains(., 'Open Dashboard')]" + // fails here. if (!s.clickButtonByClassName("general-open-dash", url)) { return false; } diff --git a/src/test/java/org/unicode/cldr/surveydriver/SurveyDriverData.java b/src/test/java/org/unicode/cldr/surveydriver/SurveyDriverData.java index 6148bd3..2b89758 100644 --- a/src/test/java/org/unicode/cldr/surveydriver/SurveyDriverData.java +++ b/src/test/java/org/unicode/cldr/surveydriver/SurveyDriverData.java @@ -1,36 +1,35 @@ -/** - * - */ +/** */ package org.unicode.cldr.surveydriver; -/** - * Data for SurveyDriver: lists of locales and pages - */ +/** Data for SurveyDriver: lists of locales and pages */ public class SurveyDriverData { /** - * This list of page names was created by temporarily commenting out the toString function - * in PathHeader.java, and inserting this line into the PageId initialization function: + * This list of page names was created by temporarily commenting out the toString function in + * PathHeader.java, and inserting this line into the PageId initialization function: * System.out.println("PageId raw name: " + this.toString()); - *

- * It would be better to have an API for requesting this list from the ST back end at runtime! - *

- * There is a PageId enum defined in PathHeader.java. We could link with the - * cldr-apps code and access that enum directly. However, there are difficulties - * with initiation, like "java.lang.RuntimeException: CLDRConfigImpl used before SurveyMain.init() called!" - * "Set -DCLDR_ENVIRONMENT=UNITTEST if you are in the test cases." Follow up on that possibility later. - * In the meantime, we can copy and simplify the enum from PathHeader.java, since all we need here - * is an array of strings. - *

- * PageId versus SectionId: PageId.Alphabetic_Information is in the section SectionId.Core_Data - *

- * Alphabetic_Information(SectionId.Core_Data, "Alphabetic Information") - *

- * Each page is one web page; a section may encompass multiple pages, not all visible at once. - * (There may also be multiple headers in one page. See PathHeader.txt which is a source file.) + * + *

It would be better to have an API for requesting this list from the ST back end at + * runtime! + * + *

There is a PageId enum defined in PathHeader.java. We could link with the cldr-apps code + * and access that enum directly. However, there are difficulties with initiation, like + * "java.lang.RuntimeException: CLDRConfigImpl used before SurveyMain.init() called!" "Set + * -DCLDR_ENVIRONMENT=UNITTEST if you are in the test cases." Follow up on that possibility + * later. In the meantime, we can copy and simplify the enum from PathHeader.java, since all we + * need here is an array of strings. + * + *

PageId versus SectionId: PageId.Alphabetic_Information is in the section + * SectionId.Core_Data + * + *

Alphabetic_Information(SectionId.Core_Data, "Alphabetic Information") + * + *

Each page is one web page; a section may encompass multiple pages, not all visible at + * once. (There may also be multiple headers in one page. See PathHeader.txt which is a source + * file.) */ private static final String[] pages = { - // prettier-ignore + // spotless:off "Alphabetic_Information", "Numbering_Systems", "LinguisticElements", "Locale_Name_Patterns", "Languages_A_D", "Languages_E_J", "Languages_K_N", "Languages_O_S", "Languages_T_Z", "Scripts", "Territories", "T_NAmerica", "T_SAmerica", "T_Africa", "T_Europe", "T_Asia", "T_Oceania", "Locale_Variants", @@ -55,23 +54,23 @@ public class SurveyDriverData { "WeekData", "Measurement", "Language", "RBNF", "Segmentation", "DayPeriod", "Category", "Smileys", "People", "Animals_Nature", "Food_Drink", "Travel_Places", "Activities", "Objects", "Symbols2", "Flags", "Component", "Typography", + // spotless:on }; - /** - * These are pages for which special annotation vote resolution is applicable - */ + /** These are pages for which special annotation vote resolution is applicable */ private static final String[] annotationPages = { - // prettier-ignore + // spotless:off "Category", "Smileys", "People", "Animals_Nature", "Food_Drink", "Travel_Places", "Activities", "Objects", "Symbols2", "Flags", + // spotless:on }; /** - * This list of locales was obtained by putting a breakpoint on SurveyAjax.getLocalesSet, getting its - * return value, and adding quotation marks by search/replace. + * This list of locales was obtained by putting a breakpoint on SurveyAjax.getLocalesSet, + * getting its return value, and adding quotation marks by search/replace. */ private static final String[] locales = { - // prettier-ignore + // spotless:off "aa", "aa_DJ", "aa_ER", "aa_ET", "af", "af_NA", "af_ZA", "agq", "agq_CM", "ak", "ak_GH", "am", "am_ET", "ar", "ar_001", "ar_AE", "ar_BH", "ar_DJ", "ar_DZ", "ar_EG", "ar_EH", "ar_ER", @@ -151,6 +150,7 @@ public class SurveyDriverData { "yue_Hans", "yue_Hans_CN", "yue_Hant", "yue_Hant_HK", "zgh", "zgh_MA", "zh", "zh_Hans", "zh_Hans_CN", "zh_Hans_HK", "zh_Hans_MO", "zh_Hans_SG", "zh_Hant", "zh_Hant_HK", "zh_Hant_MO", "zh_Hant_TW", "zu", "zu_ZA", + // spotless:on }; public static String[] getPages() { diff --git a/src/test/java/org/unicode/cldr/surveydriver/SurveyDriverVettingTable.java b/src/test/java/org/unicode/cldr/surveydriver/SurveyDriverVettingTable.java index 42ed095..405a5bb 100644 --- a/src/test/java/org/unicode/cldr/surveydriver/SurveyDriverVettingTable.java +++ b/src/test/java/org/unicode/cldr/surveydriver/SurveyDriverVettingTable.java @@ -15,9 +15,11 @@ public class SurveyDriverVettingTable { /** - * Test the vetting table to make sure it contains the expected content under certain circumstances. - *

- * Purpose: make sure that code revisions do not cause unintended changes to the table contents. + * Test the vetting table to make sure it contains the expected content under certain + * circumstances. + * + *

Purpose: make sure that code revisions do not cause unintended changes to the table + * contents. */ public static boolean testVettingTable(SurveyDriver s) { if (!s.login()) { @@ -46,7 +48,8 @@ public static boolean testVettingTable(SurveyDriver s) { } JavascriptExecutor js = (JavascriptExecutor) driver; - js.executeScript("window.testTable = function(theTable, reuseTable) { console.log(theTable.json); }"); + js.executeScript( + "window.testTable = function(theTable, reuseTable) { console.log(theTable.json); }"); /* * Get the table three times. @@ -55,7 +58,7 @@ public static boolean testVettingTable(SurveyDriver s) { * Third time, after voting for new value "taml" in first row. * Finally, abstain so the next user will find the db the same as it was. */ - String[] table = { null, null, null }; + String[] table = {null, null, null}; final int tableCount = 3; String dataDirName; try { @@ -76,11 +79,12 @@ public static boolean testVettingTable(SurveyDriver s) { return false; } if (t > 0 && table[t].equals(table[t - 1])) { - SurveyDriverLog.println("File " + fName + " should not be identical to the previous file"); + SurveyDriverLog.println( + "File " + fName + " should not be identical to the previous file"); return false; } } - String[] cellClasses = { "proposedcell", "input", "nocell" }; + String[] cellClasses = {"proposedcell", "input", "nocell"}; String rowId = "r@7b8ee7884f773afa"; int i = 0; int goodTableCount = 0; @@ -106,7 +110,8 @@ public static boolean testVettingTable(SurveyDriver s) { try { Thread.sleep(5000); } catch (Exception e) { - SurveyDriverLog.println("Sleep interrupted before finished waiting to get table html; " + e); + SurveyDriverLog.println( + "Sleep interrupted before finished waiting to get table html; " + e); } /* @@ -125,18 +130,17 @@ public static boolean testVettingTable(SurveyDriver s) { ++goodTableCount; } else { SurveyDriverLog.println( - "❌ table " + - i + - " is different (" + - tableHtml.length() + - " units):\n" + - tableHtml + - "\n\nExpected (" + - table[i].length() + - " units):\n" + - table[i] + - "\n" - ); + "❌ table " + + i + + " is different (" + + tableHtml.length() + + " units):\n" + + tableHtml + + "\n\nExpected (" + + table[i].length() + + " units):\n" + + table[i] + + "\n"); } ++i; boolean doAdd = cell.equals("input"); @@ -145,7 +149,7 @@ public static boolean testVettingTable(SurveyDriver s) { WebElement rowEl = null, columnEl, clickEl = null; int repeats = 0; - for (;;) { + for (; ; ) { try { rowEl = driver.findElement(By.id(rowId)); } catch (StaleElementReferenceException e) { @@ -153,18 +157,18 @@ public static boolean testVettingTable(SurveyDriver s) { break; } SurveyDriverLog.println( - "Continuing after StaleElementReferenceException for findElement by id rowId " + - rowId + - " for " + - url - ); + "Continuing after StaleElementReferenceException for findElement by id rowId " + + rowId + + " for " + + url); continue; } catch (Exception e) { SurveyDriverLog.println(e); break; } if (rowEl == null) { - SurveyDriverLog.println("❌ Vetting-table test failed, missing row id " + rowId + " for " + url); + SurveyDriverLog.println( + "❌ Vetting-table test failed, missing row id " + rowId + " for " + url); return false; } try { @@ -174,11 +178,10 @@ public static boolean testVettingTable(SurveyDriver s) { break; } SurveyDriverLog.println( - "Continuing after StaleElementReferenceException for findElement by class cellClass " + - cellClass + - " for " + - url - ); + "Continuing after StaleElementReferenceException for findElement by class cellClass " + + cellClass + + " for " + + url); continue; } catch (Exception e) { SurveyDriverLog.println(e); @@ -186,8 +189,12 @@ public static boolean testVettingTable(SurveyDriver s) { } if (columnEl == null) { SurveyDriverLog.println( - "❌ Vetting-table test failed, no column " + cellClass + " for row " + rowId + " for " + url - ); + "❌ Vetting-table test failed, no column " + + cellClass + + " for row " + + rowId + + " for " + + url); return false; } try { @@ -197,11 +204,10 @@ public static boolean testVettingTable(SurveyDriver s) { break; } SurveyDriverLog.println( - "Continuing after StaleElementReferenceException for findElement by tagName " + - rowId + - " for " + - url - ); + "Continuing after StaleElementReferenceException for findElement by tagName " + + rowId + + " for " + + url); continue; } catch (Exception e) { SurveyDriverLog.println(e); @@ -211,11 +217,16 @@ public static boolean testVettingTable(SurveyDriver s) { } if (clickEl == null) { SurveyDriverLog.println( - "❌ Vetting-table test failed, no tag " + tagName + " for row " + rowId + " for " + url - ); + "❌ Vetting-table test failed, no tag " + + tagName + + " for row " + + rowId + + " for " + + url); return false; } - clickEl = s.waitUntilRowCellTagElementClickable(clickEl, rowId, cellClass, tagName, url); + clickEl = + s.waitUntilRowCellTagElementClickable(clickEl, rowId, cellClass, tagName, url); if (clickEl == null) { return false; } @@ -224,8 +235,10 @@ public static boolean testVettingTable(SurveyDriver s) { } catch (Exception e) { SurveyDriverLog.println(e); SurveyDriverLog.println( - "❌ Fast vote test failed, invisibilityOfElementLocated overlay for row " + rowId + " for " + url - ); + "❌ Fast vote test failed, invisibilityOfElementLocated overlay for row " + + rowId + + " for " + + url); return false; } try { @@ -235,12 +248,18 @@ public static boolean testVettingTable(SurveyDriver s) { break; } SurveyDriverLog.println( - "Continuing after StaleElementReferenceException for clickEl.click for row " + rowId + " for " + url - ); + "Continuing after StaleElementReferenceException for clickEl.click for row " + + rowId + + " for " + + url); continue; } catch (Exception e) { SurveyDriverLog.println(e); - SurveyDriverLog.println("❌ Vetting-table test failed, clickEl.click for row " + rowId + " for " + url); + SurveyDriverLog.println( + "❌ Vetting-table test failed, clickEl.click for row " + + rowId + + " for " + + url); return false; } if (doAdd) { @@ -254,9 +273,12 @@ public static boolean testVettingTable(SurveyDriver s) { SurveyDriverLog.println("Warning: continuing, didn't see input box for " + url); continue; } - inputEl = s.waitUntilRowCellTagElementClickable(inputEl, rowId, cellClass, "input", url); + inputEl = + s.waitUntilRowCellTagElementClickable( + inputEl, rowId, cellClass, "input", url); if (inputEl == null) { - SurveyDriverLog.println("Warning: continuing, input box not clickable for " + url); + SurveyDriverLog.println( + "Warning: continuing, input box not clickable for " + url); continue; } inputEl.clear(); @@ -281,7 +303,9 @@ private static String normalizeTable(String tableHtml) { * Work around it here by changing "fallback_root" to "fallback". */ tableHtml = tableHtml.replace("fallback_root", "fallback"); - tableHtml = tableHtml.replaceFirst("\\s*\\s* !handle.equals(currentTabHandle)) - .findFirst() - .get(); + String newTabHandle = + driver.getWindowHandles().stream() + .filter(handle -> !handle.equals(currentTabHandle)) + .findFirst() + .get(); driver.switchTo().window(newTabHandle); try { Thread.sleep(1000); @@ -102,11 +102,12 @@ private boolean clickOnMainMenu(String url) { clickEl = clickEl.findElement(By.xpath("./..")); // parent new Actions(s.driver).moveToElement(clickEl, 0, 0).build().perform(); if (!s.waitUntilElementClickable(clickEl, url)) { - SurveyDriverLog.println("❌ XML-Upload test failed waiting for main menu to be clickable"); + SurveyDriverLog.println( + "❌ XML-Upload test failed waiting for main menu to be clickable"); return false; } int repeats = 0; - for (;;) { + for (; ; ) { try { clickEl.click(); return true; @@ -114,7 +115,8 @@ private boolean clickOnMainMenu(String url) { if (++repeats > 4) { break; } - SurveyDriverLog.println("clickOnMainMenu repeating for StaleElementReferenceException in " + url); + SurveyDriverLog.println( + "clickOnMainMenu repeating for StaleElementReferenceException in " + url); clickEl = s.driver.findElement(By.className(className)); } catch (Exception e) { SurveyDriverLog.println(e); @@ -145,11 +147,12 @@ private boolean clickOnUploadXMLElement(String url) { } new Actions(s.driver).moveToElement(clickEl, 0, 0).build().perform(); if (!s.waitUntilElementClickable(clickEl, url)) { - SurveyDriverLog.println("❌ XML-Upload test failed waiting for " + linkText + " menu to be clickable"); + SurveyDriverLog.println( + "❌ XML-Upload test failed waiting for " + linkText + " menu to be clickable"); return false; } int repeats = 0; - for (;;) { + for (; ; ) { try { clickEl.click(); return true; @@ -157,7 +160,9 @@ private boolean clickOnUploadXMLElement(String url) { if (++repeats > 4) { break; } - SurveyDriverLog.println("clickOnGearElement repeating for StaleElementReferenceException in " + url); + SurveyDriverLog.println( + "clickOnGearElement repeating for StaleElementReferenceException in " + + url); clickEl = s.driver.findElement(By.partialLinkText(linkText)); } catch (Exception e) { SurveyDriverLog.println(e); @@ -177,9 +182,9 @@ private boolean clickOnUploadXMLElement(String url) { private boolean specifyXmlFileToUpload(String url) { final String id = "file"; final String xmlPathname = - "/Users/tbishop/Documents/WenlinDocs/Organizations/Unicode/CLDR_job/xml_upload_test.xml"; + "/Users/tbishop/Documents/WenlinDocs/Organizations/Unicode/CLDR_job/xml_upload_test.xml"; int repeats = 0; - for (;;) { + for (; ; ) { if (!s.waitUntilIdExists(id, true, url)) { SurveyDriverLog.println("❌ XML-Upload test failed waiting for id to exist: " + id); return false; @@ -191,7 +196,8 @@ private boolean specifyXmlFileToUpload(String url) { } new Actions(s.driver).moveToElement(clickEl, 0, 0).build().perform(); if (!s.waitUntilElementClickable(clickEl, url)) { - SurveyDriverLog.println("❌ XML-Upload test failed waiting for element to be clickable: " + id); + SurveyDriverLog.println( + "❌ XML-Upload test failed waiting for element to be clickable: " + id); return false; } try { @@ -203,8 +209,8 @@ private boolean specifyXmlFileToUpload(String url) { break; } SurveyDriverLog.println( - "specifyXmlFileToUpload repeating for StaleElementReferenceException in " + url - ); + "specifyXmlFileToUpload repeating for StaleElementReferenceException in " + + url); } catch (Exception e) { SurveyDriverLog.println(e); break;