Skip to content

Commit

Permalink
more bindings implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
charybdeide committed Jan 7, 2016
1 parent 159a8d2 commit 7b4a1e9
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 16 deletions.
64 changes: 55 additions & 9 deletions source/selenium.d
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ enum TimeoutType: string {
pageLoad = "page load"
}

enum Orientation: string {
landscape = "LANDSCAPE",
portrait = "PORTRAIT"
}

struct SessionResponse(T) {

@optional {
Expand Down Expand Up @@ -274,11 +279,16 @@ struct SeleniumSession {
return this;
}

auto frame(Json id = null) {
auto frame(string id) {
POST("/frame", ["id": id]);
return this;
}

auto frame(WebElement element) {
POST("/frame", element);
return this;
}

auto frameParent() {
POST("/frame/parent");
return this;
Expand Down Expand Up @@ -425,15 +435,51 @@ struct SeleniumSession {
return GET!bool("/element/" ~ firstElementId ~ "/equals/" ~ secondElementId);
}

auto elementDisplayed(string elementId) {
return GET!bool("/element/" ~ elementId ~ "/displayed");
}

auto elementLocation(string elementId) {
return GET!Position("/element/" ~ elementId ~ "/location");
}

auto elementLocationInView(string elementId) {
return GET!Position("/element/" ~ elementId ~ "/location_in_view");
}

auto elementSize(string elementId) {
return GET!Size("/element/" ~ elementId ~ "/size");
}

auto elementCssPropertyName(string elementId, string propertyName) {
return GET!string("/element/" ~ elementId ~ "/css/" ~ propertyName);
}

auto orientation() {
return GET!Orientation("/orientation");
}

auto setOrientation(Orientation orientation) {
struct Body {
Orientation orientation;
}

return POST("/orientation", Body(orientation));
}

auto alertText() {
return GET!string("/alert_text");
}

auto setPromptText(string text) {
POST("/alert_text", ["text": text]);
return this;
}


/*
/session/:sessionId/element/:id
/session/:sessionId/element/:id/equals/:other
/session/:sessionId/element/:id/displayed
/session/:sessionId/element/:id/location
/session/:sessionId/element/:id/location_in_view
/session/:sessionId/element/:id/size
/session/:sessionId/element/:id/css/:propertyName
/session/:sessionId/orientation
/session/:sessionId/element/:id - not yet implemented in Selenium
/session/:sessionId/alert_text
/session/:sessionId/accept_alert
/session/:sessionId/dismiss_alert
Expand Down
36 changes: 29 additions & 7 deletions source/test.d
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ unittest {
auto url2 = "http://www.amazon.com/The-Boys-Boat-Americans-Olympics/dp/0143125478/";

auto session = SeleniumSession("http://127.0.0.1:4444/wd/hub", Capabilities.chrome);
/+

session.timeouts(TimeoutType.script, 10_000);
session.timeouts(TimeoutType.implicit, 10_000);
session.timeouts(TimeoutType.pageLoad, 10_000);
/+
string handle = session.windowHandle;
writeln("windowHandle: ", handle);
writeln("windowHandles: ", session.windowHandles);
Expand Down Expand Up @@ -63,12 +63,15 @@ unittest {
session.setCookie(cookie);
session.deleteCookie("test");
session.deleteAllCookies;
+/
assert(session.source != "");
session.url("http://wfmu.org/playlists/LM");
assert(session.title == "WFMU: This Is The Modern World with Trouble: Playlists and Archives");
auto elem = ElementLocator(LocatorStrategy.ClassName, "ui-dialog");
session.element(elem);
auto elem2 = ElementLocator(LocatorStrategy.CssSelector, ".showList ul");
session.elements(elem2);
session.element(elem2);
Expand All @@ -78,14 +81,17 @@ unittest {
session.activeElement;
auto elem4 = ElementLocator(LocatorStrategy.LinkText, "See the playlist");
auto elem4 = ElementLocator(LocatorStrategy.LinkText, "View Trouble's profile");
session.clickElement(session.element(elem4).ELEMENT);
assert(session.url == "http://wfmu.org/playlists/shows/64336");
assert(session.url == "http://www.wfmu.org/profile/686399632/Trouble");
session.url("http://szabobogdan.com/ro.php");
/+ auto elem5 = ElementLocator(LocatorStrategy.ClassName, "mailForm");
session.submitElement(session.element(elem5).ELEMENT);
auto elem5 = ElementLocator(LocatorStrategy.ClassName, "mailForm");
// session.submitElement(session.element(elem5).ELEMENT);
// session.wait(1000);
// session.alertText();
+/
/*
auto elem6 = ElementLocator(LocatorStrategy.CssSelector, "#contact h2");
assert(session.elementText(session.element(elem6).ELEMENT) == "Contact");
Expand Down Expand Up @@ -114,5 +120,21 @@ unittest {
auto idElem9 = session.element(elem9).ELEMENT;
auto idElem9bis = session.element(elem9bis).ELEMENT;
assert(session.elementEqualsOther(idElem9, idElem9bis));
assert(session.elementDisplayed(idElem9) == true);
session.elementLocation(idElem9);
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");

//session.disconnect;
}

0 comments on commit 7b4a1e9

Please sign in to comment.