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

displayed? *** NoMethodError Exception: undefined method `key' for #12

Closed
serhatbolsu opened this issue Dec 31, 2018 · 4 comments
Closed
Assignees

Comments

@serhatbolsu
Copy link

Hi,
During the usage of element I would like to use .displayed? . If the item is not displayed instead of getting

Example 1 will raise element not found exception if element not found on the page

I get
*** NoMethodError Exception: undefined method key' for [:css, ".bioinfo_personal .title"]:Array`

Example:
Definition:
element :details_broker_name, {css: ".bioinfo_personal .title"}
Usage:
expect(brokers.details_broker_name.displayed?).to be true

Not getting "element not found" exception is hardening the debug-ability of test cases.

@krupani krupani self-assigned this Jan 9, 2019
@krupani
Copy link
Owner

krupani commented Jan 9, 2019

Hello @serhatbolsu
Thanks.. This is selenium capability that while searching for element, if the element is not found, you cannot actually call .displayed? as it throws exception immediately..

web-object gem has a workaround to it.. while declaring the element, pass a false parameter..
eg:

element :details_broker_name, {css: ".bioinfo_personal .title"}, false 

This will return a false instead of throwing an error so it can be used as:
Usage:

# while checking its not visible
expect(brokers.details_broker_name).to be false

# while checking element is visible
expect(brokers.details_broker_name.displayed?).to be true

But your point is duly noted, it will be good to have a .displayed? for elements which are not present on page.

Let me know if you have more questions...

@serhatbolsu
Copy link
Author

workaround is ok , but still requires a lot of code change considering I have alot of tests.

wouldnt it be nice that somehow you override .displayed? so that method would respond,
element not found  exception

@krupani
Copy link
Owner

krupani commented Jan 13, 2019

I believe changing native behaviour of .displayed? method is not a good idea.. Main purpose of web-object gem is to provide all the native webdriver flavours but with a clean way of implementing page-objects..

But yes I have taken in your issue and a fix will be out..

I can think of something generic and implement a property in which u can set initially in your setup code that when elements are not found, do not raise an error instead return a boolean false..

Also feel free to fork and submit a pull-request..

@krupani krupani mentioned this issue Jun 3, 2019
Merged
@krupani
Copy link
Owner

krupani commented Jun 4, 2019

"NoMethodError Exception: undefined method `key' "
Issue has been fixed in release 0.5

@krupani krupani closed this as completed Jun 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants