diff --git a/pom.xml b/pom.xml
index 7dbb92ba..ac6d98bf 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
candybean
jar
candybean
- 2.0.1-SNAPSHOT
+ 2.0.3-SNAPSHOT
A highly configurable testing framework that seeks to automate across web and mobile while encapsulating common testing features.
http://sugarcrm.github.io/candybean/
diff --git a/resources/html/test/elements.html b/resources/html/test/elements.html
new file mode 100644
index 00000000..49ceafcc
--- /dev/null
+++ b/resources/html/test/elements.html
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/java/com/sugarcrm/candybean/automation/webdriver/WebDriverElement.java b/src/main/java/com/sugarcrm/candybean/automation/webdriver/WebDriverElement.java
index 9d38c24f..f7608c5c 100644
--- a/src/main/java/com/sugarcrm/candybean/automation/webdriver/WebDriverElement.java
+++ b/src/main/java/com/sugarcrm/candybean/automation/webdriver/WebDriverElement.java
@@ -40,7 +40,6 @@
* @author Conrad Warmbold
*/
public class WebDriverElement extends Element {
-
protected WebDriver wd;
protected WebElement we;
@@ -109,7 +108,7 @@ public String getText() throws CandybeanException {
String type = this.we.getAttribute("type");
if (type != null
&& (type.equalsIgnoreCase("button") || type
- .equalsIgnoreCase("input"))) {
+ .equalsIgnoreCase("text"))) {
return this.we.getAttribute("value");
}
return this.we.getText();
@@ -354,47 +353,42 @@ public void scroll(Location loc) throws CandybeanException {
}
/**
- * Clears the element and sends a string to it.
+ * Selects all text in this element if it is a textfield. Note that this method does not
+ * currently support textareas or any type of element apart from a textfield. It clicks on the
+ * element, so links will be activated, radio buttons will be selected, drop boxes will be
+ * opened, etc. Use of this method on any non-textfield element is not currently supported.
+ */
+ public void selectAll() {
+ we.click();
+ we.sendKeys(Keys.END,Keys.chord(Keys.SHIFT,Keys.HOME));
+ }
+
+ /**
+ * Clear the element and send a string to it.
*
- * @param input
- * string to send
+ * @param input string to send
*/
public void sendString(String input) throws CandybeanException {
- logger.info("Sending string: " + input + " to element: "
- + this.toString());
- this.we.clear();
-
- // Re-find the element to avoid the stale element problem.
- // Re-finding this *still* causes problems in getControl.getControl
- // situations; a
- // universal solution should be found to resolve this inconsistency
- // since this
- // is the only method that does it and it violates the general
- // architecture
- this.we = this.wd.findElements(Hook.getBy(this.hook)).get(this.index);
- this.we.sendKeys(input);
+ sendString(input, false);
}
/**
* Send a string to this element.
*
- * @param input
- * string to send
- * @param append
- * if append is true, the element will be cleared first
- * @throws CandybeanException
+ * @param input string to send
+ * @param append if append is false, the element will be cleared first
+ * @throws CandybeanException
*/
- public void sendString(String input, boolean append)
- throws CandybeanException {
- logger.info("Clear first?: " + append + "; sending string: " + input
- + " to element: " + this.toString());
- if (!append)
- this.sendString(input);
- else {
- // Re-find the element to avoid the stale element problem.
- this.we = this.wd.findElements(Hook.getBy(this.hook)).get(this.index);
- this.we.sendKeys(input);
+ public void sendString(String input, boolean append) throws CandybeanException {
+ logger.info((append ? "Clearing field and s" : "S") + "ending string: " + input +
+ " to element: " + toString());
+
+ if(!append) {
+ selectAll();
+ we.sendKeys(Keys.DELETE);
}
+
+ we.sendKeys(input);
}
/**
diff --git a/src/test/java/com/sugarcrm/candybean/automation/webdriver/WebDriverElementSystemTest.java b/src/test/java/com/sugarcrm/candybean/automation/webdriver/WebDriverElementSystemTest.java
index 1de3dec6..7c59546a 100644
--- a/src/test/java/com/sugarcrm/candybean/automation/webdriver/WebDriverElementSystemTest.java
+++ b/src/test/java/com/sugarcrm/candybean/automation/webdriver/WebDriverElementSystemTest.java
@@ -40,12 +40,14 @@
import com.sugarcrm.candybean.automation.element.Hook.Strategy;
import com.sugarcrm.candybean.exceptions.CandybeanException;
import com.sugarcrm.candybean.runner.VRunner;
+import org.openqa.selenium.Keys;
@RunWith(VRunner.class)
public class WebDriverElementSystemTest {
-
private WebDriverInterface iface;
-
+ String elementsPage = "file://"+ System.getProperty("user.dir")+"/resources/html/test/elements.html";
+
+
@Before
public void setUp() throws Exception {
Configuration config = TestConfiguration.getTestConfiguration("systemtest.webdriver.config");
@@ -124,10 +126,10 @@ public void getTextTest() throws Exception {
@Test
public void getSelectTest() throws Exception {
- iface.go("http://sfbay.craigslist.org/");
- WebDriverElement formElement = iface.getWebDriverElement(Strategy.ID, "search");
+ iface.go(elementsPage);
+ WebDriverElement formElement = iface.getWebDriverElement(Strategy.ID, "form");
WebDriverSelector actualSelectElement = (WebDriverSelector) formElement.getSelect(new Hook(Strategy.TAG, "select"), 0);
- Assert.assertEquals("for sale", actualSelectElement.getFirstSelectedOption());
+ Assert.assertEquals("Option 1", actualSelectElement.getFirstSelectedOption());
}
@Test
@@ -158,13 +160,15 @@ public void doubleClickTest() throws Exception {
@Test
public void dragNDropTest() throws Exception {
- String url = "http://demos.telerik.com/kendo-ui/dragdrop/index";
+ String url = "http://demos111.mootools.net/DragDrop";
iface.go(url);
-
- WebDriverElement dragElement = iface.getWebDriverElement(new Hook(Strategy.ID, "draggable"));
- WebDriverElement dropElement = iface.getWebDriverElement(new Hook(Strategy.ID, "droptarget"));
+
+ WebDriverElement dragElement = iface.getWebDriverElement(new Hook(Strategy.CSS, ".drag"));
+ WebDriverElement dropElement = iface.getWebDriverElement(new Hook(Strategy.CSS, ".drop"));
+ Assert.assertTrue("100px".equals(dropElement.getCssValue("height")));
dragElement.dragNDrop(dropElement);
- Assert.assertEquals("You did great!", dropElement.getText());
+ iface.pause(1000);
+ Assert.assertTrue("130px".equals(dropElement.getCssValue("height")));
}
@Test
@@ -296,9 +300,9 @@ public void checkBoxSelectTest() throws Exception {
select.select("I have a bike");
Assert.assertEquals("Control should be selected -- selected: " + select.isSelected(0), select.isSelected(0), true);
- // Exception should throw for non-checkbox element
-// VHook nonCheckboxHook = new VHook(Strategy.XPATH, "/html/body/div[1]/div/div[4]/div[2]/form[3]/input[1]"); // a radio box
-// candybean.select(nonCheckboxHook, true); // yes, verified exception was thrown
+ // Exception should throw for non-checkbox element
+ // VHook nonCheckboxHook = new VHook(Strategy.XPATH, "/html/body/div[1]/div/div[4]/div[2]/form[3]/input[1]"); // a radio box
+ // candybean.select(nonCheckboxHook, true); // yes, verified exception was thrown
// Checking getAttributeValue()
WebDriverElement element = iface.getWebDriverElement(new Hook(Strategy.XPATH, "/html/body/div[1]/div/div[4]/div[2]/form[1]/input[1]"));
@@ -317,21 +321,28 @@ public void checkBoxSelectTest() throws Exception {
@Test
public void sendStringTest() throws Exception {
+ String garbageString = "This string is garbage that needs to be cleared.";
String searchString = "sugarcrm";
-
- // clear and send scenario
- iface.go("http://www.duckduckgo.com/");
- iface.getWebDriverElement(Strategy.ID, "search_form_input_homepage").sendString(searchString);
- iface.getWebDriverElement(Strategy.ID, "search_button_homepage").click();
- Assert.assertTrue(iface.getWebDriverElement(Strategy.PLINK, "SugarCRM").isDisplayed());
+ iface.go(elementsPage);
+
+ WebDriverElement textField = iface.getWebDriverElement(Strategy.ID, "textfield");
+
+ // clear and set scenario
+ textField.sendString(garbageString);
+ textField.sendString(searchString);
+ Assert.assertEquals(searchString, textField.getText());
// append scenario -- base test and append assert
- iface.go("http://www.duckduckgo.com/");
- iface.getWebDriverElement(Strategy.ID, "search_form_input_homepage").sendString("crm", false);
- iface.getWebDriverElement(Strategy.ID, "search_button_homepage").click();
- iface.getWebDriverElement(Strategy.ID, "search_form_input").sendString("sugar", true);
- iface.getWebDriverElement(Strategy.ID, "search_button").click();
- Assert.assertTrue(iface.getWebDriverElement(Strategy.PLINK, "Sugar CRM").isDisplayed());
+ String searchString1 = "sugar";
+ String searchString2 = "con";
+ textField.sendString(searchString1);
+ textField.sendString(searchString2, true);
+ Assert.assertEquals(searchString1 + searchString2, textField.getText());
+
+ // clear and set to empty string scenario
+ String emptyString = "";
+ textField.sendString(emptyString);
+ Assert.assertEquals(emptyString, textField.getText());
}
@Test
@@ -348,25 +359,23 @@ public void executeJavascriptTest() throws CandybeanException {
@Test
public void getWidthTest() throws CandybeanException {
- iface.go("https://www.google.com/");
- WebDriverElement searchBox = iface.getWebDriverElement(new Hook(Strategy.ID, "gbqfq"));
- int searchBoxWidth = searchBox.getWidth();
- Assert.assertTrue(searchBoxWidth > 0);
+ iface.go(elementsPage);
+ WebDriverElement textField = iface.getWebDriverElement(Strategy.ID, "textfield");
+ Assert.assertTrue(textField.getWidth() > 0);
}
@Test
public void getHeightTest() throws CandybeanException {
- iface.go("https://www.google.com/");
- WebDriverElement searchBox = iface.getWebDriverElement(new Hook(Strategy.ID, "gbqfq"));
- int searchBoxHeight = searchBox.getHeight();
- Assert.assertTrue(searchBoxHeight > 0);
+ iface.go(elementsPage);
+ WebDriverElement textField = iface.getWebDriverElement(Strategy.ID, "textfield");
+ Assert.assertTrue(textField.getHeight() > 0);
}
@Test
public void getCssValueTest() throws CandybeanException {
- iface.go("https://www.google.com/");
- WebDriverElement searchBox = iface.getWebDriverElement(new Hook(Strategy.ID, "gbqfq"));
- Assert.assertEquals(searchBox.getCssValue("display"), "block");
+ iface.go(elementsPage);
+ WebDriverElement textField = iface.getWebDriverElement(Strategy.ID, "textfield");
+ Assert.assertEquals("inline-block", textField.getCssValue("display"));
}
@Test