Skip to content

Instantly share code, notes, and snippets.

@ajayk
Created September 6, 2011 16:58
Show Gist options
  • Save ajayk/1198169 to your computer and use it in GitHub Desktop.
Save ajayk/1198169 to your computer and use it in GitHub Desktop.
package org.openqa.selenium;
import static org.openqa.selenium.Ignore.Driver.OPERA;
@Ignore(OPERA)
public class ClearTest extends AbstractDriverTestCase {
public void testWritableTextInputShouldClear() {
driver.get(pages.readOnlyPage);
WebElement element = driver.findElement(By.id("writableTextInput"));
element.clear();
assertEquals("", element.getAttribute("value"));
}
public void testTextInputShouldNotClearWhenDisabled() {
driver.get(pages.readOnlyPage);
try {
WebElement element = driver.findElement(By.id("textInputnotenabled"));
assertEquals(false, element.isEnabled());
element.clear();
assertEquals("Test", element.getAttribute("value"));
} catch (ElementNotEditableException e) {
// This is expected
}
}
public void testTextInputShouldNotClearWhenReadOnly() {
try {
driver.get(pages.readOnlyPage);
WebElement element = driver.findElement(By.id("readOnlyTextInput"));
element.clear();
assertEquals("Test", element.getAttribute("value"));
} catch (ElementNotEditableException e) {
// This is expected
}
}
public void testWritableTextAreaShouldClear() {
driver.get(pages.readOnlyPage);
WebElement element = driver.findElement(By.id("writableTextArea"));
element.clear();
assertEquals("", element.getAttribute("value"));
}
public void testTextAreaShouldNotClearWhenDisabled() {
try {
driver.get(pages.readOnlyPage);
WebElement element = driver.findElement(By.id("textAreaNotenabled"));
element.clear();
assertEquals("text area which is not supposed to be cleared", element.getAttribute("value"));
} catch (ElementNotEditableException e) {
// This is expected
}
}
public void testTextAreaShouldNotClearWhenReadOnly() {
try {
driver.get(pages.readOnlyPage);
WebElement element = driver.findElement(By.id("textAreaReadOnly"));
element.clear();
assertEquals("text area which is not supposed to be cleared", element.getAttribute("value"));
} catch (ElementNotEditableException e) {
// This is expected
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment