diff --git a/source/selenium.d b/source/selenium.d index ec83561..2eb5626 100755 --- a/source/selenium.d +++ b/source/selenium.d @@ -348,35 +348,85 @@ struct SeleniumSession { return GET!string("/title"); } - auto element(ElementLocator elem) { - return POST!WebElement("/element", elem); + auto element(ElementLocator locator) { + return POST!WebElement("/element", locator); } - auto elements(ElementLocator elem) { - return POST!(WebElement[])("/elements", elem); + auto elements(ElementLocator locator) { + return POST!(WebElement[])("/elements", locator); } auto activeElement() { return POST!WebElement("/element/active"); } - auto elementFromElement(string initialElem, ElementLocator elem) { - return POST!WebElement("/element/" ~ initialElem ~ "/element", elem); + auto elementFromElement(string initialElemId, ElementLocator locator) { + return POST!WebElement("/element/" ~ initialElemId ~ "/element", locator); } + + auto elementsFromElement(string initialElemId, ElementLocator locator) { + return POST!(WebElement[])("/element/" ~ initialElemId ~ "/elements", locator); + } + + auto clickElement(string elementId) { + POST("/element/" ~ elementId ~ "/click"); + return this; + } + + auto submitElement(string elementId) { + POST("/element/" ~ elementId ~ "/submit"); + return this; + } + + auto elementText(string elementId) { + return GET!string("/element/" ~ elementId ~ "/text"); + } + + auto sendKeys(string elementId, string[] value) { + struct Body { + string[] value; + } + + POST("/element/" ~ elementId ~ "/value", Body(value)); + return this; + } + + auto sendKeysToActiveElement(string[] value) { + struct Body { + string[] value; + } + + POST("/keys", Body(value)); + return this; + } + + auto elementName(string elementId) { + return GET!string("/element/" ~ elementId ~ "/name"); + } + + auto clearElementValue(string elementId) { + POST("/element/" ~ elementId ~ "/clear"); + return this; + } + + auto elementSelected(string elementId) { + return GET!bool("/element/" ~ elementId ~ "/selected"); + } + + auto elementEnabled(string elementId) { + return GET!bool("/element/" ~ elementId ~ "/enabled"); + } + + auto elementValue(string elementId, string attribute) { + return GET!string("/element/" ~ elementId ~ "/attribute/" ~ attribute); + } + + auto elementEqualsOther(string firstElementId, string secondElementId) { + return GET!bool("/element/" ~ firstElementId ~ "/equals/" ~ secondElementId); + } + /* /session/:sessionId/element/:id -/session/:sessionId/element/:id/element -/session/:sessionId/element/:id/elements -/session/:sessionId/element/:id/click -/session/:sessionId/element/:id/submit -/session/:sessionId/element/:id/text -/session/:sessionId/element/:id/value -/session/:sessionId/keys -/session/:sessionId/element/:id/name -/session/:sessionId/element/:id/clear -/session/:sessionId/element/:id/selected -/session/:sessionId/element/:id/enabled -/session/:sessionId/element/:id/attribute/:name /session/:sessionId/element/:id/equals/:other /session/:sessionId/element/:id/displayed /session/:sessionId/element/:id/location diff --git a/source/test.d b/source/test.d index 44751aa..86fecc0 100644 --- a/source/test.d +++ b/source/test.d @@ -74,10 +74,45 @@ unittest { session.element(elem2); auto elem3 = ElementLocator(LocatorStrategy.TagName, "li"); - session.elementFromElement(session.element(elem2).ELEMENT, elem3); + session.elementsFromElement(session.element(elem2).ELEMENT, elem3); session.activeElement; + auto elem4 = ElementLocator(LocatorStrategy.LinkText, "See the playlist"); + session.clickElement(session.element(elem4).ELEMENT); + assert(session.url == "http://wfmu.org/playlists/shows/64336"); - session.disconnect; + session.url("http://szabobogdan.com/ro.php"); +/+ auto elem5 = ElementLocator(LocatorStrategy.ClassName, "mailForm"); + session.submitElement(session.element(elem5).ELEMENT); ++/ + auto elem6 = ElementLocator(LocatorStrategy.CssSelector, "#contact h2"); + assert(session.elementText(session.element(elem6).ELEMENT) == "Contact"); + + auto elem7 = ElementLocator(LocatorStrategy.Id, "formName"); + auto idElem7 = session.element(elem7).ELEMENT; + session.sendKeys(idElem7, ["a", "l", "e"]); + + session.sendKeysToActiveElement(["2", "t"]); + + session.elementValue(idElem7, "value"); + + assert(session.elementName(idElem7) == "input"); + + session.clearElementValue(idElem7); + assert(session.elementValue(idElem7, "value") == ""); + + session.url(url1); + auto elem8 = ElementLocator(LocatorStrategy.CssSelector, "#quantity option"); + auto idElem8 = session.element(elem8).ELEMENT; + assert(session.elementSelected(idElem8)); + + assert(session.elementEnabled(idElem8)); + + auto elem9 = ElementLocator(LocatorStrategy.CssSelector, "#quantity"); + auto elem9bis = ElementLocator(LocatorStrategy.XPath, ".//*[@id='quantity']"); + auto idElem9 = session.element(elem9).ELEMENT; + auto idElem9bis = session.element(elem9bis).ELEMENT; + assert(session.elementEqualsOther(idElem9, idElem9bis)); + //session.disconnect; }