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

Added setFocusToElement to replace the Focus keyword #78

Merged
merged 3 commits into from
Jul 25, 2019
Merged

Added setFocusToElement to replace the Focus keyword #78

merged 3 commits into from
Jul 25, 2019

Conversation

ractoc
Copy link
Contributor

@ractoc ractoc commented Jul 16, 2019

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.

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

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?

Copy link
Contributor Author

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

Copy link
Contributor Author

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

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"?

Copy link
Contributor Author

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

and fixed..

@ractoc ractoc changed the title Added setFocusToElement. This keyword should eventually replace the F… Added setFocusToElement to replace the Focus keyword Jul 22, 2019
@ractoc
Copy link
Contributor Author

ractoc commented Jul 22, 2019

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.

@ractoc
Copy link
Contributor Author

ractoc commented Jul 22, 2019

For some reason, Travis is failing. This just happens on the FireFox profile. The error I see is:
Element is not clickable at point (311,447) because another element obscures it. No real idea what could be causing this though. My changes shouldn't have this effect as far as I can determine. @YauheniPo, @Hi-Fi Maybe one of you guys could take a look at it? I'm guessing this is holding back any new release I might want

@Hi-Fi
Copy link
Collaborator

Hi-Fi commented Jul 25, 2019

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 Hi-Fi merged commit aaf73e6 into MarketSquare:develop Jul 25, 2019
@ractoc
Copy link
Contributor Author

ractoc commented Jul 30, 2019

@Hi-Fi
After some more testing on our end, we found a little problem with the getElementAttribute changes. It turns out RobotFramework can't handle overloading in the Java library, or we're doing something wrong. I had to remove the old method completely to get the new method to be excepted. Having them both in there gives some strange error.

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.

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