Skip to content

Commit

Permalink
implemented some elements location functions
Browse files Browse the repository at this point in the history
  • Loading branch information
charybdeide committed Jan 3, 2016
1 parent e159af7 commit f982b28
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 8 deletions.
44 changes: 37 additions & 7 deletions source/selenium.d
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,15 @@ struct Cookie {
}
}

struct ElementLocator {
LocatorStrategy using;
string value;
}

struct WebElement {
string ELEMENT;
}

struct SeleniumSession {
string serverUrl;

Expand Down Expand Up @@ -326,14 +335,35 @@ struct SeleniumSession {
return this;
}

auto deleteCookie(string name) {
DELETE("/cookie/" ~ name);
return this;
}

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

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

auto element(ElementLocator elem) {
return POST!WebElement("/element", elem);
}

auto elements(ElementLocator elem) {
return POST!(WebElement[])("/elements", elem);
}

auto activeElement() {
return POST!WebElement("/element/active");
}

auto elementFromElement(string initialElem, ElementLocator elem) {
return POST!WebElement("/element/" ~ initialElem ~ "/element", elem);
}
/*
/session/:sessionId/cookie/:name
/session/:sessionId/source
/session/:sessionId/title
/session/:sessionId/element
/session/:sessionId/elements
/session/:sessionId/element/active
/session/:sessionId/element/:id
/session/:sessionId/element/:id/element
/session/:sessionId/element/:id/elements
Expand Down Expand Up @@ -470,7 +500,7 @@ private Json makeRequest(T)(HTTPMethod method, string path, T data) {
Json result;
bool done = false;

logInfo("REQUEST: %s %s %s", method, path, data.to!string);
logInfo("REQUEST: %s %s %s", method, path, data.serializeToJson.toPrettyString);

requestHTTP(path,
(scope req) {
Expand Down
18 changes: 17 additions & 1 deletion source/test.d
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ 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);
Expand Down Expand Up @@ -61,7 +61,23 @@ unittest {
auto cookie = Cookie("test", "value");
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);

auto elem3 = ElementLocator(LocatorStrategy.TagName, "li");
session.elementFromElement(session.element(elem2).ELEMENT, elem3);

session.activeElement;


session.disconnect;
}

0 comments on commit f982b28

Please sign in to comment.