diff --git a/src/main/java/com/github/markusbernhardt/seleniumlibrary/SeleniumLibrary.java b/src/main/java/com/github/markusbernhardt/seleniumlibrary/SeleniumLibrary.java index a889e27..bfc3491 100644 --- a/src/main/java/com/github/markusbernhardt/seleniumlibrary/SeleniumLibrary.java +++ b/src/main/java/com/github/markusbernhardt/seleniumlibrary/SeleniumLibrary.java @@ -63,7 +63,6 @@ public SeleniumLibrary(String timeout, String implicitWait, String keywordToRunO if (!screenshotPath.isEmpty()) { screenshot.setScreenshotDirectory(screenshotPath); } - } // ############################## @@ -79,7 +78,6 @@ public SeleniumLibrary(String timeout, String implicitWait, String keywordToRunO @Autowired Screenshot screenshot; - @Override public String getKeywordDocumentation(String keywordName) { if (keywordName.equals("__intro__")) { @@ -185,6 +183,5 @@ public String getKeywordDocumentation(String keywordName) { } } return keywordName; - } } diff --git a/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/Cookie.java b/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/Cookie.java index db21fc2..7f4d0bd 100644 --- a/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/Cookie.java +++ b/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/Cookie.java @@ -42,12 +42,12 @@ public void deleteCookie(String name) { @RobotKeyword("Returns all cookies of the current page.") public String getCookies() { - StringBuffer ret = new StringBuffer(); + StringBuilder ret = new StringBuilder(); - ArrayList cookies = new ArrayList(browserManagement + ArrayList cookies = new ArrayList<>(browserManagement .getCurrentWebDriver().manage().getCookies()); for (int i = 0; i < cookies.size(); i++) { - ret.append(cookies.get(i).getName() + "=" + cookies.get(i).getValue()); + ret.append(cookies.get(i).getName()).append('=').append(cookies.get(i).getValue()); if (i != cookies.size() - 1) { ret.append("; "); } diff --git a/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/Element.java b/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/Element.java index a8c3ac4..d480b92 100644 --- a/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/Element.java +++ b/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/Element.java @@ -366,7 +366,6 @@ public void elementShouldBeClickable(String locator, String...params) { } } - @RobotKeyword("Verify the element identified by ``locator`` is not clickable.\r\n" + "\r\n" + "Key attributes for arbitrary elements are id and name. See `Introduction` for details about locators.") @@ -404,7 +403,6 @@ public void elementTextShouldBe(String locator, String text, String...params) { } } - @RobotKeyword("Verify the text of the element identified by ``locator`` is not exactly ``text``.\r\n" + "\r\n" + "In contrast to `Element Should Not Contain`, this keyword does not try a substring match but an exact match on the element identified by locator.\r\n" + @@ -448,7 +446,6 @@ public String getElementAttribute(String attributeLocator) { "Passing attribute name as part of the locator was removed in SeleniumLibrary 3.2. The explicit attribute argument should be used instead.") @ArgumentNames({ "locator", "attribute" }) public String getElementAttribute(String locator, String attribute) { - List elements = elementFind(locator, true, false); if (elements.size() == 0) { @@ -494,7 +491,6 @@ public String getInnerElementId(String locator, String matchid, int index) { logging.info(String.format("Found element ID: '%s'.", eId)); return eId; - } @RobotKeyword("Returns horizontal position of element identified by ``locator``.\r\n" + @@ -778,7 +774,6 @@ public void pressKey(String locator, String key) { // Keywords - Links // ############################## - @RobotKeyword("Click on the link identified by ``locator``.\r\n" + "\r\n" + "Key attributes for links are id, name, href and link text. See `Introduction` for details about locators.") @@ -794,7 +789,7 @@ public void clickLink(String locator) { "\r\n" + "If a link has no id, an empty string will be in the list instead.") public ArrayList getAllLinks() { - ArrayList ret = new ArrayList(); + ArrayList ret = new ArrayList<>(); List elements = elementFind("tag:a", false, false, "a"); for (WebElement element : elements) { @@ -965,7 +960,7 @@ protected List elementFind(String locator, boolean firstOnly, boolea if (firstOnly) { if (elements.size() > 1) { - List tmp = new ArrayList(); + List tmp = new ArrayList<>(); tmp.add(elements.get(0)); elements = tmp; } @@ -1079,9 +1074,8 @@ protected boolean pageContains(String text) { } List elements = elementFind("xpath://frame|//iframe", false, false); - Iterator it = elements.iterator(); - while (it.hasNext()) { - current.switchTo().frame(it.next()); + for (WebElement element : elements) { + current.switchTo().frame(element); boolean found = isTextPresent(text); current.switchTo().defaultContent(); if (found) { diff --git a/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/JavaScript.java b/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/JavaScript.java index b2b249c..2d26459 100644 --- a/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/JavaScript.java +++ b/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/JavaScript.java @@ -137,7 +137,7 @@ public String confirmAction() { @ArgumentNames({ "*code" }) public Object executeJavascript(String... code) { String js = getJavascriptToExecute(Python.join("", Arrays.asList(code))); - String.format("Executing JavaScript:\n%s", js); + logging.html(String.format("Executing JavaScript:\n%s", js)); return ((JavascriptExecutor) browserManagement.getCurrentWebDriver()).executeScript(js); } @@ -155,7 +155,7 @@ public Object executeJavascript(String... code) { @ArgumentNames({ "*code" }) public Object executeAsyncJavascript(String... code) { String js = getJavascriptToExecute(Python.join("", Arrays.asList(code))); - String.format("Executing JavaScript:\n%s", js); + logging.html(String.format("Executing JavaScript:\n%s", js)); return ((JavascriptExecutor) browserManagement.getCurrentWebDriver()).executeAsyncScript(js); } @@ -165,8 +165,7 @@ public Object executeAsyncJavascript(String... code) { public String getAlertMessage() { try { Alert alert = browserManagement.getCurrentWebDriver().switchTo().alert(); - String text = alert.getText().replace("\n", ""); - return text; + return alert.getText().replace("\n", ""); } catch (WebDriverException wde) { throw new SeleniumLibraryNonFatalException("There were no alerts"); } @@ -177,14 +176,11 @@ public String getAlertMessage() { // ############################## protected static String readFile(String path) throws IOException { - FileInputStream stream = new FileInputStream(new File(path)); - try { + try (FileInputStream stream = new FileInputStream(new File(path))) { FileChannel fc = stream.getChannel(); MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size()); /* Instead of using default, pass in a decoder. */ return Charset.defaultCharset().decode(bb).toString(); - } finally { - stream.close(); } } diff --git a/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/Logging.java b/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/Logging.java index 3047fba..8f75c51 100644 --- a/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/Logging.java +++ b/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/Logging.java @@ -24,7 +24,7 @@ public class Logging extends RunOnFailureKeywordsAdapter { protected static String logDir = null; static { - VALID_LOG_LEVELS = new HashMap(); + VALID_LOG_LEVELS = new HashMap<>(); VALID_LOG_LEVELS.put("debug", new String[] { "debug", "" }); VALID_LOG_LEVELS.put("html", new String[] { "info", ", True, False" }); VALID_LOG_LEVELS.put("info", new String[] { "info", "" }); @@ -60,7 +60,6 @@ public List logWindowIdentifiers(String...params) { return windowIdentifiers; } - @RobotKeyword("Logs and returns the names of all windows known to the current browser instance.\r\n" + "\r\n" + "See `Introduction` for details about the ``logLevel``.") @@ -131,7 +130,6 @@ public String logSystemInfo(String...params) { return actual; } - @RobotKeyword("Returns the actually supported capabilities of the remote browser instance.\r\n" + "\r\n" + "Not all server implementations will support every WebDriver feature. Therefore, the client and server should use JSON objects with the properties listed below when describing which features a user requests that a session support. *If a session cannot support a capability that is requested in the desired capabilities, no error is thrown*; a read-only capabilities object is returned that indicates the capabilities the session actually supports. For more information see: [https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities|DesiredCapabilities]\r\n" + @@ -239,7 +237,6 @@ protected void log0(String msg, String methodName, String methodArguments) { } protected File getLogDir() { - if (logDir == null && !loggingPythonInterpreter.get().eval("EXECUTION_CONTEXTS.current").toString().equals("None")) { PyString logDirName = (PyString) loggingPythonInterpreter.get() @@ -258,14 +255,10 @@ public static void setLogDir(String logDirectory) { logDir = logDirectory; } - protected static ThreadLocal loggingPythonInterpreter = new ThreadLocal() { - - @Override - protected PythonInterpreter initialValue() { - PythonInterpreter pythonInterpreter = new PythonInterpreter(); - pythonInterpreter.exec( - "from robot.libraries.BuiltIn import BuiltIn; from robot.running.context import EXECUTION_CONTEXTS; from robot.api import logger;"); - return pythonInterpreter; - } - }; + protected static ThreadLocal loggingPythonInterpreter = ThreadLocal.withInitial(() -> { + PythonInterpreter pythonInterpreter = new PythonInterpreter(); + pythonInterpreter.exec( + "from robot.libraries.BuiltIn import BuiltIn; from robot.running.context import EXECUTION_CONTEXTS; from robot.api import logger;"); + return pythonInterpreter; + }); } diff --git a/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/Robot.java b/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/Robot.java index 987be24..bd0f9bd 100644 --- a/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/Robot.java +++ b/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/Robot.java @@ -1,13 +1,11 @@ package com.github.markusbernhardt.seleniumlibrary.keywords; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - +import com.google.gson.Gson; import org.python.util.PythonInterpreter; import org.robotframework.javalib.annotation.RobotKeywords; -import com.google.gson.Gson; +import java.util.List; +import java.util.Map; @RobotKeywords public class Robot { @@ -38,20 +36,20 @@ public T getParamsValue(String[] params, int index, T defaultValue) { } @SuppressWarnings({ "unchecked", "resource" }) - public Map parseRobotDictionary(String dictionary) { - logging.debug("Dictionary going to be parsed to Map: " + dictionary); - Map json = new HashMap(); - try { - PythonInterpreter py = new PythonInterpreter(); - py.exec("import json"); - json = new Gson().fromJson(py.eval("json.dumps(" + dictionary + ")").toString(), Map.class); - } catch (RuntimeException e) { - logging.error(String.format("Parsing of dictionary %s failed.", dictionary)); - throw e; - } - - return json; - } + public Map parseRobotDictionary(String dictionary) { + logging.debug("Dictionary going to be parsed to Map: " + dictionary); + Map json; + try { + PythonInterpreter py = new PythonInterpreter(); + py.exec("import json"); + json = new Gson().fromJson(py.eval("json.dumps(" + dictionary + ")").toString(), Map.class); + } catch (RuntimeException e) { + logging.error(String.format("Parsing of dictionary %s failed.", dictionary)); + throw e; + } + + return json; + } @SuppressWarnings("unchecked") public List parseRobotList(String list) { diff --git a/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/RunOnFailure.java b/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/RunOnFailure.java index 50da8e6..3787571 100644 --- a/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/RunOnFailure.java +++ b/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/RunOnFailure.java @@ -61,15 +61,11 @@ public String registerKeywordToRunOnFailure(String keyword) { // Internal Methods // ############################## - protected static ThreadLocal runOnFailurePythonInterpreter = new ThreadLocal() { - - @Override - protected PythonInterpreter initialValue() { - PythonInterpreter pythonInterpreter = new PythonInterpreter(); - pythonInterpreter.exec("from robot.libraries.BuiltIn import BuiltIn; from robot.running.context import EXECUTION_CONTEXTS; BIN = BuiltIn();"); - return pythonInterpreter; - } - }; + protected static ThreadLocal runOnFailurePythonInterpreter = ThreadLocal.withInitial(() -> { + PythonInterpreter pythonInterpreter = new PythonInterpreter(); + pythonInterpreter.exec("from robot.libraries.BuiltIn import BuiltIn; from robot.running.context import EXECUTION_CONTEXTS; BIN = BuiltIn();"); + return pythonInterpreter; + }); public void runOnFailure() { if (runOnFailureKeyword == null) { diff --git a/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/Screenshot.java b/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/Screenshot.java index 4645957..17c5afc 100644 --- a/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/Screenshot.java +++ b/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/Screenshot.java @@ -1,9 +1,7 @@ package com.github.markusbernhardt.seleniumlibrary.keywords; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; - +import com.github.markusbernhardt.seleniumlibrary.RunOnFailureKeywordsAdapter; +import com.github.markusbernhardt.seleniumlibrary.utils.Robotframework; import org.apache.commons.lang3.exception.ExceptionUtils; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; @@ -13,8 +11,9 @@ import org.robotframework.javalib.annotation.RobotKeyword; import org.robotframework.javalib.annotation.RobotKeywords; -import com.github.markusbernhardt.seleniumlibrary.RunOnFailureKeywordsAdapter; -import com.github.markusbernhardt.seleniumlibrary.utils.Robotframework; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; @RobotKeywords public class Screenshot extends RunOnFailureKeywordsAdapter { @@ -50,15 +49,15 @@ public String setScreenshotDirectory(String path) { screenshotDir = new File(path); return oldDir; } - - @RobotKeyword("Take a screenshot of the current page and embed it into the log.\r\n" + - "\r\n" + - "The ``filename`` argument specifies the name of the file to write the screenshot into. If no filename is given, the screenshot is saved into file selenium-screenshot-{index}.png under the directory where the Robot Framework log file is written into. The filename is also considered relative to the same directory, if it is not given in absolute format.\r\n" + - "\r\n" + - "if ``filename`` contains marker {index}, it will be automatically replaced with unique running index preventing files to be overwritten. Indices start from 1.\r\n" + - "\r\n" + - "A CSS can be used to modify how the screenshot is taken. By default the background color is changed to avoid possible problems with background leaking when the page layout is somehow broken.") - @ArgumentNames({ "filename=selenium-screenshot-{index}.png" }) + + @RobotKeyword("Take a screenshot of the current page and embed it into the log.\r\n" + + "\r\n" + + "The ``filename`` argument specifies the name of the file to write the screenshot into. If no filename is given, the screenshot is saved into file selenium-screenshot-{index}.png under the directory where the Robot Framework log file is written into. The filename is also considered relative to the same directory, if it is not given in absolute format.\r\n" + + "\r\n" + + "if ``filename`` contains marker {index}, it will be automatically replaced with unique running index preventing files to be overwritten. Indices start from 1.\r\n" + + "\r\n" + + "A CSS can be used to modify how the screenshot is taken. By default the background color is changed to avoid possible problems with background leaking when the page layout is somehow broken.") + @ArgumentNames({"filename=selenium-screenshot-{index}.png"}) public void capturePageScreenshot(String...params) { String filename = robot.getParamsValue(params, 0, null); File logdir = screenshotDir != null ? screenshotDir : logging.getLogDir(); @@ -68,7 +67,6 @@ public void capturePageScreenshot(String...params) { if (currentWebDriver.getClass().toString().contains("HtmlUnit")) { logging.warn("HTMLunit is not supporting screenshots."); - return; } else { try { TakesScreenshot takesScreenshot = ((TakesScreenshot) currentWebDriver); @@ -79,8 +77,7 @@ public void capturePageScreenshot(String...params) { "", link, link)); } catch (NullPointerException e) { logging.warn("Can't take screenshot. No open browser found"); - return; - } + } } } diff --git a/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/SelectElement.java b/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/SelectElement.java index 43b2b8c..8ba69cb 100644 --- a/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/SelectElement.java +++ b/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/SelectElement.java @@ -1,6 +1,8 @@ package com.github.markusbernhardt.seleniumlibrary.keywords; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.List; import org.openqa.selenium.NoSuchElementException; @@ -47,7 +49,6 @@ public List getListItems(String locator) { return getLabelsForOptions(options); } - @RobotKeyword("Returns the visible label of the first selected element from the select list identified by ``locator``.\r\n" + "\r\n" + "Select list keywords work on both lists and combo boxes. Key attributes for select lists are id and name. See `Introduction` for details about locators.") @@ -142,11 +143,11 @@ public void listShouldHaveNoSelections(String locator) { logging.info(String.format("Verifying list '%s' has no selection.", locator)); List options = getSelectListOptionsSelected(locator); - if (!options.equals(null)) { + if (!options.isEmpty()) { List selectedLabels = getLabelsForOptions(options); String items = Python.join(" | ", selectedLabels); throw new SeleniumLibraryNonFatalException(String.format( - "List '%s' should have had no selection (selection was [ %s ]).", locator, items.toString())); + "List '%s' should have had no selection (selection was [ %s ]).", locator, items)); } } @@ -211,7 +212,7 @@ public void selectFromList(String locator, String... items) { } boolean lastItemFound = false; - List nonExistingItems = new ArrayList(); + List nonExistingItems = new ArrayList<>(); for (String item : items) { lastItemFound = true; try { @@ -257,10 +258,8 @@ public void selectFromListByIndex(String locator, String... indexes) { throw new SeleniumLibraryNonFatalException("No index given."); } - List tmp = new ArrayList(); - for (String index : indexes) { - tmp.add(index); - } + List tmp = new ArrayList<>(); + Collections.addAll(tmp, indexes); String items = String.format("index(es) '%s'", Python.join(", ", tmp)); logging.info(String.format("Selecting %s from list '%s'.", items, locator)); @@ -343,11 +342,11 @@ public void unselectFromList(String locator, String... items) { "Select list keywords work on both lists and combo boxes. Key attributes for select lists are id and name. See `Introduction` for details about locators.") @ArgumentNames({ "locator", "*indexes" }) public void unselectFromListByIndex(String locator, Integer... indexes) { - if (indexes.equals(null)) { + if (indexes.length == 0) { throw new SeleniumLibraryNonFatalException("No index given."); } - List tmp = new ArrayList(); + List tmp = new ArrayList<>(); for (Integer index : indexes) { tmp.add(index.toString()); } @@ -371,7 +370,7 @@ public void unselectFromListByIndex(String locator, Integer... indexes) { "Select list keywords work on both lists and combo boxes. Key attributes for select lists are id and name. See `Introduction` for details about locators.") @ArgumentNames({ "locator", "*values" }) public void unselectFromListByValue(String locator, String... values) { - if (values.equals(null)) { + if (values.length == 0) { throw new SeleniumLibraryNonFatalException("No value given."); } @@ -395,7 +394,7 @@ public void unselectFromListByValue(String locator, String... values) { "Select list keywords work on both lists and combo boxes. Key attributes for select lists are id and name. See `Introduction` for details about locators.") @ArgumentNames({ "locator", "*labels" }) public void unselectFromListByLabel(String locator, String... labels) { - if (labels.equals(null)) { + if (labels.length == 0) { throw new SeleniumLibraryNonFatalException("No value given."); } @@ -419,7 +418,7 @@ public void unselectFromListByLabel(String locator, String... labels) { // ############################## protected List getLabelsForOptions(List options) { - List labels = new ArrayList(); + List labels = new ArrayList<>(); for (WebElement option : options) { labels.add(option.getText()); @@ -435,7 +434,7 @@ protected Select getSelectList(String locator) { } protected List getSelectListOptions(Select select) { - return new ArrayList(select.getOptions()); + return new ArrayList<>(select.getOptions()); } protected List getSelectListOptions(String locator) { @@ -447,11 +446,11 @@ protected List getSelectListOptions(String locator) { protected List getSelectListOptionsSelected(String locator) { Select select = getSelectList(locator); - return new ArrayList(select.getAllSelectedOptions()); + return new ArrayList<>(select.getAllSelectedOptions()); } protected List getValuesForOptions(List options) { - ArrayList labels = new ArrayList(); + ArrayList labels = new ArrayList<>(); for (WebElement option : options) { labels.add(option.getAttribute("value")); diff --git a/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/TableElement.java b/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/TableElement.java index 507c3d6..e956e9a 100644 --- a/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/TableElement.java +++ b/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/TableElement.java @@ -80,7 +80,7 @@ public void tableCellShouldContain(String tableLocator, int row, int column, Str String message = String.format("Cell in table '%s' in row #%d and column #%d should have contained text '%s'.", tableLocator, row, column, text); - String content = ""; + String content; try { content = getTableCell(tableLocator, row, column, logLevel); } catch (SeleniumLibraryNonFatalException e) { diff --git a/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/Waiting.java b/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/Waiting.java index 06842e9..e8a735c 100644 --- a/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/Waiting.java +++ b/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/Waiting.java @@ -1,5 +1,8 @@ package com.github.markusbernhardt.seleniumlibrary.keywords; +import com.github.markusbernhardt.seleniumlibrary.RunOnFailureKeywordsAdapter; +import com.github.markusbernhardt.seleniumlibrary.SeleniumLibraryNonFatalException; +import com.github.markusbernhardt.seleniumlibrary.utils.Robotframework; import org.apache.commons.lang3.exception.ExceptionUtils; import org.openqa.selenium.JavascriptExecutor; import org.robotframework.javalib.annotation.ArgumentNames; @@ -7,10 +10,6 @@ import org.robotframework.javalib.annotation.RobotKeyword; import org.robotframework.javalib.annotation.RobotKeywords; -import com.github.markusbernhardt.seleniumlibrary.RunOnFailureKeywordsAdapter; -import com.github.markusbernhardt.seleniumlibrary.SeleniumLibraryNonFatalException; -import com.github.markusbernhardt.seleniumlibrary.utils.Robotframework; - @RobotKeywords public class Waiting extends RunOnFailureKeywordsAdapter { @@ -52,14 +51,10 @@ public void waitForCondition(final String condition, String...params) { if (message == null) { message = String.format("Condition '%s' did not become true in ", condition); } - waitUntil(timeout, message, new WaitUntilFunction() { - - @Override - public boolean isFinished() { - return Boolean.TRUE.equals(((JavascriptExecutor) browserManagement.getCurrentWebDriver()) - .executeScript(condition)); - } - }); + waitUntil( + timeout, + message, + () -> Boolean.TRUE.equals(((JavascriptExecutor) browserManagement.getCurrentWebDriver()).executeScript(condition))); } @RobotKeyword("Waits until the current page contains ``text``.\r\n" + @@ -74,13 +69,10 @@ public void waitUntilPageContains(final String text, String...params) { if (message == null) { message = String.format("Text '%s' did not appear in ", text); } - waitUntil(timeout, message, new WaitUntilFunction() { - - @Override - public boolean isFinished() { - return element.isTextPresent(text); - } - }); + waitUntil( + timeout, + message, + () -> element.isTextPresent(text)); } @RobotKeyword("Waits until the current page does not contain ``text``.\r\n" + @@ -95,13 +87,10 @@ public void waitUntilPageNotContains(final String text, String...params) { if (message == null) { message = String.format("Text '%s' did not disappear in ", text); } - waitUntil(timeout, message, new WaitUntilFunction() { - - @Override - public boolean isFinished() { - return !element.isTextPresent(text); - } - }); + waitUntil( + timeout, + message, + () -> !element.isTextPresent(text)); } @RobotKeyword("Waits until the current page does not contain ``text``.\r\n" + @@ -128,13 +117,10 @@ public void waitUntilPageContainsElement(final String locator, String...params) if (message == null) { message = String.format("Element '%s' did not appear in ", locator); } - waitUntil(timeout, message, new WaitUntilFunction() { - - @Override - public boolean isFinished() { - return element.isElementPresent(locator); - } - }); + waitUntil( + timeout, + message, + () -> element.isElementPresent(locator)); } @RobotKeyword("Waits until the element identified by ``locator`` is not found on the current page.\r\n" + @@ -149,13 +135,10 @@ public void waitUntilPageNotContainsElement(final String locator, String...param if (message == null) { message = String.format("Element '%s' did not disappear in ", locator); } - waitUntil(timeout, message, new WaitUntilFunction() { - - @Override - public boolean isFinished() { - return !element.isElementPresent(locator); - } - }); + waitUntil( + timeout, + message, + () -> !element.isElementPresent(locator)); } @RobotKeyword("Waits until the element identified by ``locator`` is not found on the current page.\r\n" + @@ -182,13 +165,10 @@ public void waitUntilElementIsVisible(final String locator, String...params) { if (message == null) { message = String.format("Element '%s' not visible in ", locator); } - waitUntil(timeout, message, new WaitUntilFunction() { - - @Override - public boolean isFinished() { - return element.isVisible(locator); - } - }); + waitUntil( + timeout, + message, + () -> element.isVisible(locator)); } @RobotKeyword("Waits until the element identified by ``locator`` is not visible.\r\n" + @@ -203,13 +183,10 @@ public void waitUntilElementIsNotVisible(final String locator, String...params) if (message == null) { message = String.format("Element '%s' still visible in ", locator); } - waitUntil(timeout, message, new WaitUntilFunction() { - - @Override - public boolean isFinished() { - return !element.isVisible(locator); - } - }); + waitUntil( + timeout, + message, + () -> !element.isVisible(locator)); } @RobotKeyword("Waits until the element identified by ``locator`` is clickable.\r\n" + @@ -224,13 +201,10 @@ public void waitUntilElementIsClickable(final String locator, String...params) { if (message == null) { message = String.format("Element '%s' not clickable in ", locator); } - waitUntil(timeout, message, new WaitUntilFunction() { - - @Override - public boolean isFinished() { - return element.isClickable(locator); - } - }); + waitUntil( + timeout, + message, + () -> element.isClickable(locator)); } @RobotKeyword("Waits until the element identified by ``locator`` is not clickable.\r\n" + @@ -245,13 +219,10 @@ public void waitUntilElementIsNotClickable(final String locator, String...params if (message == null) { message = String.format("Element '%s' still clickable in ", locator); } - waitUntil(timeout, message, new WaitUntilFunction() { - - @Override - public boolean isFinished() { - return !element.isClickable(locator); - } - }); + waitUntil( + timeout, + message, + () -> !element.isClickable(locator)); } @RobotKeyword("Waits until the element identified by ``locator`` is succesfully clicked on.\r\n" + @@ -266,14 +237,13 @@ public void waitUntilElementIsSuccessfullyClicked(final String locator, String.. if (message == null) { message = String.format("Element '%s' not successfully clicked in ", locator); } - waitUntil(timeout, message, new WaitUntilFunction() { - - @Override - public boolean isFinished() { - element.clickElement(locator); - return true; - } - }); + waitUntil( + timeout, + message, + () -> { + element.clickElement(locator); + return true; + }); } @RobotKeyword("Waits until the element identified by ``locator`` is selected.\r\n" + @@ -288,13 +258,10 @@ public void waitUntilElementIsSelected(final String locator, String...params) { if (message == null) { message = String.format("Element '%s' not selected in ", locator); } - waitUntil(timeout, message, new WaitUntilFunction() { - - @Override - public boolean isFinished() { - return element.isSelected(locator); - } - }); + waitUntil( + timeout, + message, + () -> element.isSelected(locator)); } @RobotKeyword("Waits until the element identified by ``locator`` is not selected.\r\n" + @@ -309,13 +276,10 @@ public void waitUntilElementIsNotSelected(final String locator, String...params) if (message == null) { message = String.format("Element '%s' still selected in ", locator); } - waitUntil(timeout, message, new WaitUntilFunction() { - - @Override - public boolean isFinished() { - return !element.isSelected(locator); - } - }); + waitUntil( + timeout, + message, + () -> !element.isSelected(locator)); } @RobotKeyword("Waits until the current page title contains ``title``.\r\n" + @@ -330,14 +294,13 @@ public void waitUntilTitleContains(final String title, String...params) { if (message == null) { message = String.format("Title '%s' did not appear in ", title); } - waitUntil(timeout, message, new WaitUntilFunction() { - - @Override - public boolean isFinished() { - String currentTitle = browserManagement.getTitle(); - return currentTitle != null && currentTitle.contains(title); - } - }); + waitUntil( + timeout, + message, + () -> { + String currentTitle = browserManagement.getTitle(); + return currentTitle != null && currentTitle.contains(title); + }); } @RobotKeyword("Waits until the current page title does not contain ``title``.\r\n" + @@ -352,14 +315,13 @@ public void waitUntilTitleNotContains(final String title, String...params) { if (message == null) { message = String.format("Title '%s' did not appear in ", title); } - waitUntil(timeout, message, new WaitUntilFunction() { - - @Override - public boolean isFinished() { - String currentTitle = browserManagement.getTitle(); - return currentTitle == null || !currentTitle.contains(title); - } - }); + waitUntil( + timeout, + message, + () -> { + String currentTitle = browserManagement.getTitle(); + return currentTitle == null || !currentTitle.contains(title); + }); } @RobotKeyword("Waits until the current page title is exactly ``title``.\r\n" + @@ -374,14 +336,13 @@ public void waitUntilTitleIs(final String title, String...params) { if (message == null) { message = String.format("Title '%s' did not appear in ", title); } - waitUntil(timeout, message, new WaitUntilFunction() { - - @Override - public boolean isFinished() { - String currentTitle = browserManagement.getTitle(); - return currentTitle != null && currentTitle.equals(title); - } - }); + waitUntil( + timeout, + message, + () -> { + String currentTitle = browserManagement.getTitle(); + return currentTitle != null && currentTitle.equals(title); + }); } @RobotKeyword("Waits until the current page title is not exactly ``title``.\r\n" + @@ -396,14 +357,13 @@ public void waitUntilTitleIsNot(final String title, String...params) { if (message == null) { message = String.format("Title '%s' did not appear in ", title); } - waitUntil(timeout, message, new WaitUntilFunction() { - - @Override - public boolean isFinished() { - String currentTitle = browserManagement.getTitle(); - return currentTitle == null || !currentTitle.equals(title); - } - }); + waitUntil( + timeout, + message, + () -> { + String currentTitle = browserManagement.getTitle(); + return currentTitle == null || !currentTitle.equals(title); + }); } // ############################## @@ -429,12 +389,13 @@ protected void waitUntil(String timestr, String message, WaitUntilFunction funct } try { Thread.sleep(200); - } catch (InterruptedException e) { + } catch (InterruptedException ignored) { } } } - protected static interface WaitUntilFunction { + @FunctionalInterface + protected interface WaitUntilFunction { boolean isFinished(); } diff --git a/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/Window.java b/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/Window.java index fcf90ae..1fb90d8 100644 --- a/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/Window.java +++ b/src/main/java/com/github/markusbernhardt/seleniumlibrary/keywords/Window.java @@ -75,7 +75,7 @@ public List getWindowTitles() { @RobotKeyword("Returns and logs URLs of all known browser windows.") public List getLocations() { - List locations = new ArrayList(); + List locations = new ArrayList<>(); for (SessionIdAliasWebDriverTuple sessionIdAliasWebdriverTuple : browserManagement.getWebDriverCache().getWebDrivers()) { locations.add(sessionIdAliasWebdriverTuple.webDriver.getCurrentUrl()); } @@ -114,14 +114,13 @@ public void setWindowSize(String width, String height) { browserManagement.getWebDriverCache().getCurrent().manage().window() .setSize(new Dimension(Integer.parseInt(width), Integer.parseInt(height))); } - - + protected List toList(List items) { return toList(items, "item"); } protected List toList(List items, String what) { - List msg = new ArrayList(); + List msg = new ArrayList<>(); msg.add(String.format("Altogether %d %s%s.\n", items.size(), what, items.size() == 1 ? "" : "s")); for (int index = 0; index < items.size(); index++) { msg.add(String.format("%d: %s", index + 1, items.get(index))); diff --git a/src/main/java/com/github/markusbernhardt/seleniumlibrary/locators/ElementFinder.java b/src/main/java/com/github/markusbernhardt/seleniumlibrary/locators/ElementFinder.java index 2566cf0..347886a 100644 --- a/src/main/java/com/github/markusbernhardt/seleniumlibrary/locators/ElementFinder.java +++ b/src/main/java/com/github/markusbernhardt/seleniumlibrary/locators/ElementFinder.java @@ -1,31 +1,24 @@ package com.github.markusbernhardt.seleniumlibrary.locators; -import java.util.ArrayList; -import java.util.Hashtable; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.TreeMap; - -import org.openqa.selenium.By; -import org.openqa.selenium.JavascriptExecutor; -import org.openqa.selenium.SearchContext; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; -import org.python.util.PythonInterpreter; - import com.github.markusbernhardt.seleniumlibrary.SeleniumLibraryNonFatalException; import com.github.markusbernhardt.seleniumlibrary.keywords.Element; import com.github.markusbernhardt.seleniumlibrary.utils.Python; +import org.openqa.selenium.*; +import org.python.util.PythonInterpreter; + +import java.util.*; +import java.util.Map.Entry; public class ElementFinder { - protected final static Hashtable registeredLocationStrategies = new Hashtable(); + protected final static Hashtable registeredLocationStrategies = new Hashtable<>(); protected enum KeyAttrs { - DEFAULT("@id,@name"), A("@id,@name,@href,normalize-space(descendant-or-self::text())"), IMG( - "@id,@name,@src,@alt"), INPUT("@id,@name,@value,@src"), BUTTON( - "@id,@name,@value,normalize-space(descendant-or-self::text())"); + DEFAULT("@id,@name"), + A("@id,@name,@href,normalize-space(descendant-or-self::text())"), + IMG("@id,@name,@src,@alt"), + INPUT("@id,@name,@value,@src"), + BUTTON("@id,@name,@value,normalize-space(descendant-or-self::text())"); protected String[] keyAttrs; @@ -40,8 +33,7 @@ public String[] getKeyAttrs() { protected interface Strategy { List findBy(WebDriver webDriver, FindByCoordinates findByCoordinates); - - }; + } protected enum StrategyEnum implements Strategy { DEFAULT { @@ -150,7 +142,7 @@ protected static List filterElements(List elements, Find return elements; } - List result = new ArrayList(); + List result = new ArrayList<>(); for (WebElement element : elements) { if (elementMatches(element, findByCoordinates)) { result.add(element); @@ -189,13 +181,13 @@ protected static List findByKeyAttrs(WebDriver webDriver, FindByCoor if (findByCoordinates.tag == null) { xpathTag = "*"; } - List xpathConstraints = new ArrayList(); + List xpathConstraints = new ArrayList<>(); if (findByCoordinates.constraints != null) { for (Entry entry : findByCoordinates.constraints.entrySet()) { xpathConstraints.add(String.format("@%s='%s'", entry.getKey(), entry.getValue())); } } - List xpathSearchers = new ArrayList(); + List xpathSearchers = new ArrayList<>(); for (String attr : keyAttrs.getKeyAttrs()) { xpathSearchers.add(String.format("%s=%s", attr, xpathCriteria)); } @@ -207,7 +199,7 @@ protected static List findByKeyAttrs(WebDriver webDriver, FindByCoor } protected static List getAttrsWithUrl(WebDriver webDriver, KeyAttrs keyAttrs, String criteria) { - List attrs = new ArrayList(); + List attrs = new ArrayList<>(); String url = null; String xpathUrl = null; String[] srcHref = { "@src", "@href" }; @@ -252,19 +244,15 @@ public static List find(WebDriver webDriver, String locator, String FindByCoordinates findByCoordinates = new FindByCoordinates(); Strategy strategy = parseLocator(findByCoordinates, locator); - parseTag(findByCoordinates, strategy, tag); + parseTag(findByCoordinates, tag); return strategy.findBy(webDriver, findByCoordinates); } - protected static ThreadLocal loggingPythonInterpreter = new ThreadLocal() { - - @Override - protected PythonInterpreter initialValue() { - PythonInterpreter pythonInterpreter = new PythonInterpreter(); - pythonInterpreter.exec("from robot.libraries.BuiltIn import BuiltIn; from robot.api import logger;"); - return pythonInterpreter; - } - }; + protected static ThreadLocal loggingPythonInterpreter = ThreadLocal.withInitial(() -> { + PythonInterpreter pythonInterpreter = new PythonInterpreter(); + pythonInterpreter.exec("from robot.libraries.BuiltIn import BuiltIn; from robot.api import logger;"); + return pythonInterpreter; + }); protected static void warn(String msg) { loggingPythonInterpreter.get().exec( @@ -301,32 +289,42 @@ protected static Strategy parseLocator(FindByCoordinates findByCoordinates, Stri return strategy; } - protected static void parseTag(FindByCoordinates findByCoordinates, Strategy strategy, String tag) { + protected static void parseTag(FindByCoordinates findByCoordinates, String tag) { if (tag == null) { return; } + tag = tag.toLowerCase(); - Map constraints = new TreeMap(); - if (tag.equals("link")) { - tag = "a"; - } else if (tag.equals("image")) { - tag = "img"; - } else if (tag.equals("list")) { - tag = "select"; - } else if (tag.equals("text area")) { - tag = "textarea"; - } else if (tag.equals("radio button")) { - tag = "input"; - constraints.put("type", "radio"); - } else if (tag.equals("checkbox")) { - tag = "input"; - constraints.put("type", "checkbox"); - } else if (tag.equals("text field")) { - tag = "input"; - constraints.put("type", "text"); - } else if (tag.equals("file upload")) { - tag = "input"; - constraints.put("type", "file"); + Map constraints = new TreeMap<>(); + switch(tag) { + case "link": + tag = "a"; + break; + case "image": + tag = "img"; + break; + case "list": + tag = "select"; + break; + case "text area": + tag = "textarea"; + break; + case "radio button": + tag = "input"; + constraints.put("type", "radio"); + break; + case "checkbox": + tag = "input"; + constraints.put("type", "checkbox"); + break; + case "text field": + tag = "input"; + constraints.put("type", "text"); + break; + case "file upload": + tag = "input"; + constraints.put("type", "file"); + break; } findByCoordinates.tag = tag; findByCoordinates.constraints = constraints; @@ -337,7 +335,7 @@ protected static List toList(Object o) { if (o instanceof List) { return (List) o; } - List list = new ArrayList(); + List list = new ArrayList<>(); if (o instanceof WebElement) { list.add((WebElement) o); return list; @@ -369,16 +367,14 @@ public List findBy(final WebDriver webDriver, final FindByCoordinate @Override public List findElements(SearchContext context) { - Object[] arguments = null; + Object[] arguments; if (delimiter == null) { arguments = new Object[1]; arguments[0] = findByCoordinates.criteria; } else { String[] splittedCriteria = findByCoordinates.criteria.split(delimiter); arguments = new Object[splittedCriteria.length]; - for (int i = 0; i < splittedCriteria.length; i++) { - arguments[i] = splittedCriteria[i]; - } + System.arraycopy(splittedCriteria, 0, arguments, 0, splittedCriteria.length); } Object o = ((JavascriptExecutor) webDriver).executeScript(functionDefinition, arguments); return toList(o); diff --git a/src/main/java/com/github/markusbernhardt/seleniumlibrary/locators/TableElementFinder.java b/src/main/java/com/github/markusbernhardt/seleniumlibrary/locators/TableElementFinder.java index 61b4143..02ec4ed 100644 --- a/src/main/java/com/github/markusbernhardt/seleniumlibrary/locators/TableElementFinder.java +++ b/src/main/java/com/github/markusbernhardt/seleniumlibrary/locators/TableElementFinder.java @@ -1,9 +1,6 @@ package com.github.markusbernhardt.seleniumlibrary.locators; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.TreeMap; +import java.util.*; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; @@ -13,7 +10,7 @@ public class TableElementFinder { protected final static TreeMap> locatorSuffixesMap; static { - locatorSuffixesMap = new TreeMap>(); + locatorSuffixesMap = new TreeMap<>(); addLocatorSuffix(locatorSuffixesMap, "css.default", ""); addLocatorSuffix(locatorSuffixesMap, "css.content", ""); addLocatorSuffix(locatorSuffixesMap, "css.header", " th"); @@ -58,7 +55,7 @@ public static WebElement findByFooter(WebDriver webDriver, String tableLocator, public static WebElement findByRow(WebDriver webDriver, String tableLocator, int row, String content) { List locators = parseTableLocator(tableLocator, "row"); - List formattedLocators = new ArrayList(); + List formattedLocators = new ArrayList<>(); for (String locator : locators) { formattedLocators.add(String.format(locator, Integer.toString(row))); } @@ -67,7 +64,7 @@ public static WebElement findByRow(WebDriver webDriver, String tableLocator, int public static WebElement findByCol(WebDriver webDriver, String tableLocator, int col, String content) { List locators = parseTableLocator(tableLocator, "col"); - List formattedLocators = new ArrayList(); + List formattedLocators = new ArrayList<>(); for (String locator : locators) { formattedLocators.add(String.format(locator, Integer.toString(col))); } @@ -75,15 +72,13 @@ public static WebElement findByCol(WebDriver webDriver, String tableLocator, int } protected static void addLocatorSuffix(Map> locatorSuffixesMap, String key, String... values) { - List list = new ArrayList(); - for (String value : values) { - list.add(value); - } + List list = new ArrayList<>(); + Collections.addAll(list, values); locatorSuffixesMap.put(key, list); } protected static List parseTableLocator(String tableLocator, String locationMethod) { - String tableLocatorType = null; + String tableLocatorType; if (tableLocator.startsWith("xpath=") || tableLocator.startsWith("xpath:")) { tableLocatorType = "xpath."; @@ -99,7 +94,7 @@ protected static List parseTableLocator(String tableLocator, String loca List locatorSuffixes = locatorSuffixesMap.get(tableLocatorType + locationMethod); - List parsedTabeLocators = new ArrayList(); + List parsedTabeLocators = new ArrayList<>(); for (String locatorSuffix : locatorSuffixes) { parsedTabeLocators.add(tableLocator + locatorSuffix); } diff --git a/src/main/java/com/github/markusbernhardt/seleniumlibrary/locators/WindowManager.java b/src/main/java/com/github/markusbernhardt/seleniumlibrary/locators/WindowManager.java index 4e6956d..2d59c3a 100644 --- a/src/main/java/com/github/markusbernhardt/seleniumlibrary/locators/WindowManager.java +++ b/src/main/java/com/github/markusbernhardt/seleniumlibrary/locators/WindowManager.java @@ -29,13 +29,13 @@ public void select(WebDriver webDriver, SelectCoordinates selectCoordinates) { try { NAME.select(webDriver, selectCoordinates); return; - } catch (Throwable t) { + } catch (Throwable ignored) { } try { TITLE.select(webDriver, selectCoordinates); return; - } catch (Throwable t) { + } catch (Throwable ignored) { } throw new SeleniumLibraryNonFatalException("Unable to locate window with name or title '" + selectCoordinates.criteria + "'"); @@ -45,45 +45,31 @@ public void select(WebDriver webDriver, SelectCoordinates selectCoordinates) { @Override public void select(WebDriver webDriver, final SelectCoordinates selectCoordinates) { - selectMatching(webDriver, new Matcher() { - - @Override - public boolean match(List currentWindowInfo) { - return currentWindowInfo.get(WINDOW_INFO_INDEX_DOCUMENT_TITLE).trim().toLowerCase() - .equals(selectCoordinates.criteria.toLowerCase()); - } - - }, "Unable to locate window with title '" + selectCoordinates.criteria + "'"); + String selectionCriteria = selectCoordinates.criteria; + selectMatching(webDriver, + currentWindowInfo -> currentWindowInfo.get(WINDOW_INFO_INDEX_DOCUMENT_TITLE).trim() + .equalsIgnoreCase(selectionCriteria), + String.format("Unable to locate window with title '%s'", selectionCriteria)); } }, NAME { @Override public void select(WebDriver webDriver, final SelectCoordinates selectCoordinates) { - selectMatching(webDriver, new Matcher() { - - @Override - public boolean match(List currentWindowInfo) { - return currentWindowInfo.get(WINDOW_INFO_INDEX_WINDOW_NAME).trim().toLowerCase() - .equals(selectCoordinates.criteria.toLowerCase()); - } - - }, "Unable to locate window with name '" + selectCoordinates.criteria + "'"); + String selectionCriteria = selectCoordinates.criteria; + selectMatching(webDriver, + currentWindowInfo -> currentWindowInfo.get(WINDOW_INFO_INDEX_WINDOW_NAME).trim().equalsIgnoreCase(selectionCriteria), + String.format("Unable to locate window with name '%s'", selectionCriteria)); } }, URL { @Override public void select(WebDriver webDriver, final SelectCoordinates selectCoordinates) { - selectMatching(webDriver, new Matcher() { - - @Override - public boolean match(List currentWindowInfo) { - return currentWindowInfo.get(WINDOW_INFO_INDEX_DOCUMENT_URL).trim().toLowerCase() - .equals(selectCoordinates.criteria.toLowerCase()); - } - - }, "Unable to locate window with URL '" + selectCoordinates.criteria + "'"); + String selectionCriteria = selectCoordinates.criteria; + selectMatching(webDriver, + currentWindowInfo -> currentWindowInfo.get(WINDOW_INFO_INDEX_DOCUMENT_URL).trim().equalsIgnoreCase(selectionCriteria), + String.format("Unable to locate window with URL '%s'", selectionCriteria)); } }; @@ -112,7 +98,7 @@ protected static void selectMatching(WebDriver webDriver, Matcher matcher, Strin } public static List getWindowIds(WebDriver webDriver) { - List windowIds = new ArrayList(); + List windowIds = new ArrayList<>(); for (List windowInfo : getWindowInfos(webDriver)) { windowIds.add(windowInfo.get(0)); } @@ -120,7 +106,7 @@ public static List getWindowIds(WebDriver webDriver) { } public static List getWindowNames(WebDriver webDriver) { - List windowNames = new ArrayList(); + List windowNames = new ArrayList<>(); for (List windowInfo : getWindowInfos(webDriver)) { windowNames.add(windowInfo.get(1)); } @@ -128,7 +114,7 @@ public static List getWindowNames(WebDriver webDriver) { } public static List getWindowTitles(WebDriver webDriver) { - List windowTitles = new ArrayList(); + List windowTitles = new ArrayList<>(); for (List windowInfo : getWindowInfos(webDriver)) { windowTitles.add(windowInfo.get(2)); } @@ -143,7 +129,7 @@ public static List> getWindowInfos(WebDriver webDriver) { // Window of current WebDriver instance is already closed } - List> windowInfos = new ArrayList>(); + List> windowInfos = new ArrayList<>(); try { for (String handle : webDriver.getWindowHandles()) { webDriver.switchTo().window(handle); @@ -199,13 +185,10 @@ protected static List getCurrentWindowInfo(WebDriver webDriver) { } protected static class SelectCoordinates { - String criteria; } - protected static interface Matcher { - + protected interface Matcher { boolean match(List currentWindowInfo); - } } diff --git a/src/main/java/com/github/markusbernhardt/seleniumlibrary/utils/Python.java b/src/main/java/com/github/markusbernhardt/seleniumlibrary/utils/Python.java index 48605b3..14fcc03 100644 --- a/src/main/java/com/github/markusbernhardt/seleniumlibrary/utils/Python.java +++ b/src/main/java/com/github/markusbernhardt/seleniumlibrary/utils/Python.java @@ -33,7 +33,7 @@ public static Map zip(List keys, List values) { return null; } - Map map = new HashMap(); + Map map = new HashMap<>(); Iterator valueIterator = values.listIterator(); for (A key : keys) { map.put(key, valueIterator.next()); @@ -50,7 +50,7 @@ public static String osPathDirname(String path) { int index = path.lastIndexOf(File.separatorChar) + 1; String head = path.substring(0, index); if (head.length() != 0) { - String regex = ""; + String regex; if (File.separatorChar == '/') { regex = String.format("/{%d}", head.length()); } else { diff --git a/src/main/java/com/github/markusbernhardt/seleniumlibrary/utils/WebDriverCache.java b/src/main/java/com/github/markusbernhardt/seleniumlibrary/utils/WebDriverCache.java index f39d4a1..0668232 100644 --- a/src/main/java/com/github/markusbernhardt/seleniumlibrary/utils/WebDriverCache.java +++ b/src/main/java/com/github/markusbernhardt/seleniumlibrary/utils/WebDriverCache.java @@ -24,22 +24,22 @@ public class WebDriverCache { /** * Stack of currently open session ids to reuse */ - Stack openSessionIds = new Stack(); + Stack openSessionIds = new Stack<>(); /** * Stack of already closed session ids to reuse */ - Stack closedSessionIds = new Stack(); + Stack closedSessionIds = new Stack<>(); /** * Map session ids to webdrivers */ - Map tupleBySessionId = new TreeMap(); + Map tupleBySessionId = new TreeMap<>(); /** * Map aliases to webdrivers */ - Map tupleByAlias = new TreeMap(); + Map tupleByAlias = new TreeMap<>(); public String register(WebDriver webDriver, String alias) { // create the new tuple @@ -104,10 +104,10 @@ public void closeAll() { } maxAssignedSessionId = 0; currentSessionIdAliasWebDriverTuple = null; - openSessionIds = new Stack(); - closedSessionIds = new Stack(); - tupleBySessionId = new TreeMap(); - tupleByAlias = new TreeMap(); + openSessionIds = new Stack<>(); + closedSessionIds = new Stack<>(); + tupleBySessionId = new TreeMap<>(); + tupleByAlias = new TreeMap<>(); } public void switchBrowser(String sessionIdOrAlias) {