-
Notifications
You must be signed in to change notification settings - Fork 116
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
update default method to check if element displayed to always return … #83
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,9 +91,15 @@ public String toString() { | |
* @return Whether or not the element is displayed | ||
*/ | ||
public boolean isDisplayed() { | ||
return getWrappedElement().isDisplayed(); | ||
try{ | ||
return getWrappedElement().isDisplayed(); | ||
} catch (Exception e) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
//ignore and return false to indicate element is not visible. | ||
} | ||
return false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here you're presuming that if element isn't found (this is when exception is thrown), then it's invisible. But this is hiding that fact (that element wasn't found) from the developer who runs the tests and therefore I think it's not the right way to handle this. Instead you should be catching that exception in place where you call |
||
} | ||
|
||
|
||
/** | ||
* Is the element currently enabled or not? This will generally return true for everything but | ||
* disabled input elements. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package ru.yandex.qatools.htmlelements; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExternalResource; | ||
import org.openqa.selenium.WebDriver; | ||
import org.openqa.selenium.WebElement; | ||
import org.openqa.selenium.phantomjs.PhantomJSDriver; | ||
|
||
import ru.yandex.qatools.htmlelements.element.HtmlElement; | ||
import ru.yandex.qatools.htmlelements.element.TypifiedElement; | ||
import ru.yandex.qatools.htmlelements.loader.HtmlElementLoader; | ||
import ru.yandex.qatools.htmlelements.testelements.DummyBlock; | ||
|
||
/** | ||
* Test that validates the {@link TypifiedElement} isDisplayed method always | ||
* returns a boolean. | ||
* @author Michael Suzuki | ||
*/ | ||
public class ElementDisplayedTest { | ||
|
||
private WebDriver driver; | ||
|
||
@Rule | ||
public ExternalResource manage = new ExternalResource() { | ||
@Override | ||
protected void before() throws Throwable { | ||
driver = new PhantomJSDriver(); | ||
} | ||
|
||
@Override | ||
protected void after() { | ||
driver.quit(); | ||
} | ||
}; | ||
|
||
@Test | ||
public void shouldReturnFalseAndNotAnException() throws Exception { | ||
Assert.assertFalse(HtmlElementLoader.create(DummyBlock.class, driver).isDisplayed()); | ||
} | ||
|
||
@Test | ||
public void shouldReturnTrueForVisibleElements() throws Exception { | ||
WebElement element = mock(WebElement.class); | ||
when(element.isDisplayed()).thenReturn(true); | ||
HtmlElement elementVisble = new HtmlElement(); | ||
elementVisble.setWrappedElement(element); | ||
Assert.assertTrue(elementVisble.isDisplayed()); | ||
|
||
when(element.isDisplayed()).thenReturn(false); | ||
Assert.assertFalse(elementVisble.isDisplayed()); | ||
} | ||
|
||
} |
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.
Either log or rethrow this exception.