-
Notifications
You must be signed in to change notification settings - Fork 16
Added setFocusToElement to replace the Focus keyword #78
Conversation
…ocus keyword. For backwards compatibilty the Focus keyword has been deprecated and just forwards all calls to the new SetFocusToElement keyword. Added the ElementShouldBeFocused keyword. This is the companion keyword to the SetFocusToElement. It retreives the element identified by the locator and the currently active element. Then does an equals to see if it's the same element.
@@ -977,6 +996,14 @@ protected boolean isEnabled(String locator) { | |||
return true; | |||
} | |||
|
|||
protected boolean isFocused(String locator) { | |||
List<WebElement> elements = elementFind(locator, true, true); | |||
WebElement element = elements.get(0); |
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.
What if there are no elements with a specified locator?
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.
Ah yes, good catch... I'll ad an if statement to catch that problem. I took this piece of code from one of the isEnabled though, so that same problem would be in there as well probably. I'll check that as well, see if the same problem exists elsewhere
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.
just did a little checking. This is handled in the elementFind by setting the required parameter to true. elementFind then does:
if (required && elements.size() == 0) {
throw new SeleniumLibraryNonFatalException(
String.format("Element locator '%s' did not match any elements.", locator));
}
so there is no need to do that again in my isFocused method.
@ArgumentNames({ "locator" }) | ||
public void elementShouldBeFocused(String locator) { | ||
if (!isFocused(locator)) { | ||
throw new SeleniumLibraryNonFatalException(String.format("Element %s is disabled.", locator)); |
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.
Should the message says "isn't focused" instead of "is disabled"?
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.
copy paste error...
Doint too many things at once, as usual...
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 fixed..
Added the new version of Get Element Attribute. This new version takes 2 parameters, one for hte locator and one for the actual attribute. I kept the old method, which is now almost empty and just forwards to the new method. I also marked the old method as deprecated. This new method is something we do need sooner rather then later as it is required to make our code work both on Python and on Java with the same script. |
For some reason, Travis is failing. This just happens on the FireFox profile. The error I see is: |
I tried to reproduce that error but wasn't successfull (so all tests were passing). I think this can be merged to develop. |
@Hi-Fi Keyword 'SeleniumLibrary.Get Element Attribute' expected 1 argument, got 2. Now I'm not quite sure how to keep this backwards compatible. But if the goal is to move everything towards being a 1-on-1 of the python version, We shouldn't need to keep the old one, as the python version also only has the two parameter version of the Get Element Attribute keyword. |
Added the new Set Focus To Element keyword which replaces the Focus keyword. For backwards compatibility, the old Focus keyword has been left in there but has been marked as deprecated.
Also added the companion keyword Element Should Be Focused to detect if a given element has focus.
This PR doesn not need an immediate release.