Skip to content
This repository was archived by the owner on Feb 2, 2025. It is now read-only.

Feature/code refactoring #81

Merged
merged 4 commits into from
Jul 29, 2019

Conversation

YauheniPo
Copy link
Contributor

No description provided.

.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());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about

-.append("=")
+.append('=')

? :)

Copy link
Contributor Author

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", "");

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?

Copy link
Contributor Author

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", "");

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;

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.

Copy link
Contributor Author

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));

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?

Copy link
Contributor Author

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)));

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?

Copy link
Contributor Author

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 {

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.

Copy link
Contributor Author

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) {

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.

Copy link
Contributor Author

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));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Collections.addAll()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor Author

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?

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.

Copy link
Contributor Author

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 + "'");

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?

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...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@Hi-Fi Hi-Fi merged commit 6b85626 into MarketSquare:develop Jul 29, 2019
@Hi-Fi
Copy link
Collaborator

Hi-Fi commented Jul 29, 2019

Thank you, refactoring has been long time on the list (and I think there's still plenty of it left).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants