Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add keyword that checks focus #851

Closed
jsevern55 opened this issue Jul 17, 2017 · 17 comments
Closed

Add keyword that checks focus #851

jsevern55 opened this issue Jul 17, 2017 · 17 comments

Comments

@jsevern55
Copy link

This was reported and closed on :

Add a keyword to check focus #351

Adding a keyword such as Element Should be focused would be very useful.

Is there a way to check this currently in RobotFramework?

Thank you for your time

@aaltat
Copy link
Contributor

aaltat commented Jul 19, 2017

That was closed because of inactivity in the issue, which usually means that need for the request has ended. Could you describe your need or requirements why you want to check a focus? Also could you describe what a focus means in your case?

@jsevern55
Copy link
Author

Thanks for the reply

I test div modals for w3c compliance (accessibility testing), and one of the many requirements is to verify visual/operational focus on forms is placed on the first available user modifiable element within the form.

When an element gains visual and operational focus (usually they go hand in hand), the user should be able to begin typing immediately for text fields, use up or down arrows for drop-down menus, or press the space bar for check boxes/radio buttons.

@aaltat
Copy link
Contributor

aaltat commented Jul 30, 2017

Sorry for the long delay but I am holidays and I have limited access to the internet.

I am unfamiliar with the topic, but I generally understand the topic. As far I recall the selenium API, the are not any direct support for this in the selenium API. Is the focus generally visible somehow in the DOM or how does it work?

@jsevern55
Copy link
Author

No worries at all. I just got back from a vacation myself.

If you reference this stack overflow help topic, you'll see that selenium webdriver has a solution for this. I'm aware that robot framework utilizes selenium2library, but there is a solution in the selenium world.

Essentially, this function will return a boolean value if the expected element focused is the actual element focused: element.equals(driver.switchTo().activeElement())

@aaltat
Copy link
Contributor

aaltat commented Aug 2, 2017

I see your point. I think this would be good addition to the library. Few things to consider, from implementation point of view:

  1. Now you are suggesting assert type of keyword, should there be also wait type of keyword?
  2. Returning boolean is not necessary a good idea. If focus is not in the right element, raising error is better.

Would you be willing to submit a PR? If you are remember to write tests too?

@aaltat
Copy link
Contributor

aaltat commented Aug 2, 2017

Keyword should not returning a boolean (True/False) value. Instead keyword should fail (raise an error/exception) if the element does not have a focus and keyword should pass if the element has a focus.

PR is a pull request, it's a way to contribute code to the github repository. More details in here: https://help.github.com/articles/about-pull-requests/

@aaltat
Copy link
Contributor

aaltat commented Aug 2, 2017

And creating PR explained in here: https://help.github.com/articles/creating-a-pull-request/

@jsevern55
Copy link
Author

jsevern55 commented Aug 2, 2017

Creating a pull request would imply that I am contributing code. I do not have code to contribute. I was under the impression that I could request a change, and that a contributor could code the solution.

I do not have sufficient understanding of robot framework to code this solution.

@HelioGuilherme66 HelioGuilherme66 self-assigned this Aug 2, 2017
@HelioGuilherme66
Copy link
Member

Thanks @WinterSoldier55
I'll investigate and propose the code and tests.

@jsevern55
Copy link
Author

@HelioGuilherme66, thank you very much!

@aaltat
Copy link
Contributor

aaltat commented Aug 2, 2017

Yes, me requesting a PR from you, means that you would also provide the code. But it's not mandatory, submitting issues and providing ideas how to enhance the library is great too.

If you don't want to provide the implementation, then it waits for someone else to provide the implementation. Currently I am focused to fix the final things for the next release [1] and I not taking anything else for development in the near future. Then the other option is you to find someone else to provide the implementation. You can either try find someone, who is facing the same problem and ask him to provide the implementation or you can pay someone to provide the implementation.

But if you know basics of Python and selenium then making the implementation should be relatively easy. The Robot Framework library API is explained in the user guide[2] and there are plenty of keywords where you can take an examples. The Selenium2Library uses the the dynamic library API[3], but it's invisible when creating new keywords (only thing which is needed, is to use @keyword decorator before the method definition).

[1] https://github.com/robotframework/Selenium2Library/milestone/17
[2] http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#creating-test-libraries
[3] http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#dynamic-library-api

@aaltat
Copy link
Contributor

aaltat commented Aug 2, 2017

@HelioGuilherme66 Selenium documentation shows an example how to compare elements: http://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webelement.WebElement.id

HelioGuilherme66 added a commit to HelioGuilherme66/robotframework-seleniumlibrary that referenced this issue Aug 3, 2017
HelioGuilherme66 added a commit to HelioGuilherme66/robotframework-seleniumlibrary that referenced this issue Aug 4, 2017
HelioGuilherme66 added a commit to HelioGuilherme66/robotframework-seleniumlibrary that referenced this issue Aug 4, 2017
@aaltat
Copy link
Contributor

aaltat commented Aug 4, 2017

@WinterSoldier55 please take a look #855 and is it what you expected.

@jsevern55
Copy link
Author

@aaltat, the code seems to work as expected!

@pekkaklarck
Copy link
Member

Somehow "Should Have Focus" would sound better to me than "Should Be Focused". Probably better to ask an opinion from some native English speaker, though.

Is there also a negative version of the kw like "Should Not Have Focus"?

@aaltat
Copy link
Contributor

aaltat commented Aug 12, 2017

The current keyword name is element should be focused which is similar than other keyword names.

There is not negative version.

aaltat pushed a commit that referenced this issue Aug 12, 2017
 New keyword `Should Be Focused`.

See issue #851.
@aaltat
Copy link
Contributor

aaltat commented Aug 12, 2017

Done is #855

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

No branches or pull requests

4 participants