From bc274cb997adf43b2564e6dd7ef99b82d1b545fe Mon Sep 17 00:00:00 2001 From: Szabo Bogdan Date: Thu, 7 Jan 2016 22:21:52 +0200 Subject: [PATCH] Added alert, mouse, touch and location --- source/selenium.d | 152 ++++++++++++++++++++++++++++++++++++++++------ source/test.d | 39 ++++++++++-- 2 files changed, 168 insertions(+), 23 deletions(-) diff --git a/source/selenium.d b/source/selenium.d index a4f8be4..8ae9438 100755 --- a/source/selenium.d +++ b/source/selenium.d @@ -147,6 +147,12 @@ enum Orientation: string { portrait = "PORTRAIT" } +enum MouseButton: int { + left = 0, + middle = 1, + right = 2 +} + struct SessionResponse(T) { @optional { @@ -192,6 +198,12 @@ struct WebElement { string ELEMENT; } +struct GeoLocation(T) { + T latitude; + T longitude; + T altitude; +} + struct SeleniumSession { string serverUrl; @@ -476,29 +488,131 @@ struct SeleniumSession { return this; } + auto acceptAlert() { + POST("/accept_alert"); + return this; + } + + auto dismissAlert() { + POST("/dismiss_alert"); + return this; + } + auto moveTo(Position position) { + POST("/moveto", ["xoffset": position.x, "yoffset": position.y]); + return this; + } + + auto moveTo(string elementId) { + POST("/moveto", ["element": elementId]); + return this; + } + + auto moveTo(string elementId, Position position) { + struct Body { + string element; + long xoffset; + long yoffset; + } + + POST("/moveto", Body(elementId, position.x, position.y)); + return this; + } + + auto click(MouseButton button = MouseButton.left) { + POST("/click", ["button": button]); + return this; + } + + auto buttonDown(MouseButton button = MouseButton.left) { + POST("/buttondown", ["button": button]); + return this; + } + + auto buttonUp(MouseButton button = MouseButton.left) { + POST("/buttonup", ["button": button]); + return this; + } + + auto doubleClick() { + POST("/doubleclick"); + return this; + } + + auto touchClick(string elementId) { + POST("/touch/click", ["element": elementId]); + return this; + } + + auto touchDown(Position position) { + POST("/touch/down", ["x": position.x, "y": position.y]); + return this; + } + + auto touchUp(Position position) { + POST("/touch/up", ["x": position.x, "y": position.y]); + return this; + } + + auto touchMove(Position position) { + POST("/touch/move", ["x": position.x, "y": position.y]); + return this; + } + + auto touchScroll(string elementId, Position position) { + struct Body { + string element; + long xoffset; + long yoffset; + } + + POST("/touch/scroll", Body(elementId, position.x, position.y)); + return this; + } + + auto touchScroll(Position position) { + POST("/touch/scroll", ["xoffset": position.x, "yoffset": position.y]); + return this; + } + + auto touchDoubleClick(string elementId) { + POST("/touch/doubleclick", ["element": elementId]); + return this; + } + + auto touchLongClick(string elementId) { + POST("/touch/longclick", ["element": elementId]); + return this; + } + + auto touchFlick(string elementId, Position position, long speed) { + struct Body { + string element; + long xoffset; + long yoffset; + long speed; + } + + POST("/touch/flick", Body(elementId, position.x, position.y, speed)); + return this; + } + + auto touchFlick(long xSpeed, long ySpeed) { + POST("/touch/flick", [ "xspeed": xSpeed, "yspeed": ySpeed ]); + return this; + } + + auto geoLocation() { + return GET!(GeoLocation!double)("/location"); + } + + auto setGeoLocation(T)(T location) { + POST("/location", ["location": location]); + return this; + } /* /session/:sessionId/element/:id - not yet implemented in Selenium -/session/:sessionId/alert_text -/session/:sessionId/accept_alert -/session/:sessionId/dismiss_alert -/session/:sessionId/moveto -/session/:sessionId/click -/session/:sessionId/buttondown -/session/:sessionId/buttonup -/session/:sessionId/doubleclick -/session/:sessionId/touch/click -/session/:sessionId/touch/down -/session/:sessionId/touch/up -session/:sessionId/touch/move -session/:sessionId/touch/scroll -session/:sessionId/touch/scroll -session/:sessionId/touch/doubleclick -session/:sessionId/touch/longclick -session/:sessionId/touch/flick -session/:sessionId/touch/flick -/session/:sessionId/location /session/:sessionId/local_storage /session/:sessionId/local_storage/key/:key /session/:sessionId/local_storage/size diff --git a/source/test.d b/source/test.d index df758fc..ae4f911 100644 --- a/source/test.d +++ b/source/test.d @@ -107,7 +107,7 @@ unittest { session.clearElementValue(idElem7); assert(session.elementValue(idElem7, "value") == ""); - +*/ session.url(url1); auto elem8 = ElementLocator(LocatorStrategy.CssSelector, "#quantity option"); auto idElem8 = session.element(elem8).ELEMENT; @@ -127,14 +127,45 @@ unittest { session.elementLocationInView(idElem9); session.elementSize(idElem9); session.elementCssPropertyName(idElem9, "display"); -*/ + //session.setOrientation(Orientation.landscape); //assert(session.orientation == Orientation.landscape); - +/* + session.executeAsync!string(`prompt("Please enter your name");`); + session.wait(1000); + session.setPromptText("test").acceptAlert; session.executeAsync!string(`prompt("Please enter your name");`); session.wait(1000); - session.setPromptText("test"); + session.dismissAlert;*/ + + session.moveTo(Position(100, 100)); + session.moveTo(idElem9); + session.moveTo(idElem9, Position(100, 100)); + + session.click(MouseButton.right); + + session.buttonDown; + session.buttonUp; + session.doubleClick; + +/* It's not working with chrome driver. It's too advanced. + session.touchClick(idElem9); + session.touchDown(Position(100, 100)); + session.touchUp(Position(100, 100)); + session.touchMove(Position(200, 200)); + session.touchScroll(idElem9, Position(200, 200)); + session.touchScroll(Position(200, 200)); + session.touchDoubleClick(idElem9); + session.touchLongClick(idElem9); + session.touchFlick(idElem9, Position(200, 200), 10); + session.touchFlick(100, 100);*/ + + session.setGeoLocation(GeoLocation!double(12.3, 13.3, 34.4)) + + //Web driver bug. It does not work. + //session.geoLocation(); + //session.disconnect; }