-
Notifications
You must be signed in to change notification settings - Fork 16
Feature/code refactoring #81
Feature/code refactoring #81
Conversation
Update fork branch
.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()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about
-.append("=")
+.append('=')
? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -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", ""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use .replace('\n', '')
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is not working. only alert.getText().replace("\n", "");
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I see it now. Thanks for correcting me!
@@ -222,7 +222,6 @@ public void selectFromList(String locator, String... items) { | |||
} catch (NoSuchElementException e2) { | |||
nonExistingItems.add(item); | |||
lastItemFound = false; | |||
continue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather keep it. IMHO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Roll back
for (String index : indexes) { | ||
tmp.add(index); | ||
} | ||
List<String> tmp = new ArrayList<>(Arrays.asList(indexes)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about using Collections.addAll()
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
} | ||
}); | ||
waitUntil(timeout, message, () -> Boolean.TRUE.equals(((JavascriptExecutor) browserManagement.getCurrentWebDriver()) | ||
.executeScript(condition))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you, please, put waitUntil()
argument to the separate lines to make code a little bit easier to read?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
} | ||
} | ||
} | ||
|
||
protected static interface WaitUntilFunction { | ||
protected interface WaitUntilFunction { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method look like a candidate for having FunctionalInterface
annotation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep) fixed
constraints.put("type", "file"); | ||
} | ||
Map<String, String> constraints = new TreeMap<>(); | ||
switch (tag) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is something wrong with indentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
for (String value : values) { | ||
list.add(value); | ||
} | ||
List<String> list = new ArrayList<>(Arrays.asList(values)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Collections.addAll()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you explain to me why this is better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Arrays.asList()
creates a new ArrayList under the hood. After that, we pass it to a ArrayList() constructor where we create an array (see toArray()
there), and after that we copy this array to a destination array. So, here we've copied elements 2 times and produced unnecessary temporary objects (more work to GC). We can avoid this by using Collections.addAll()
. That was my point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, thanks a lot!
|
||
}, "Unable to locate window with title '" + selectCoordinates.criteria + "'"); | ||
selectMatching(webDriver, currentWindowInfo -> currentWindowInfo.get(WINDOW_INFO_INDEX_DOCUMENT_TITLE).trim().toLowerCase() | ||
.equals(selectCoordinates.criteria.toLowerCase()), "Unable to locate window with title '" + selectCoordinates.criteria + "'"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you split the arguments and make it more readable, please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And for the text 2 methods also...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Thank you, refactoring has been long time on the list (and I think there's still plenty of it left). |
No description provided.