Skip to content

Commit

Permalink
added window properties in the session window class
Browse files Browse the repository at this point in the history
  • Loading branch information
gedaiu committed Mar 6, 2016
1 parent 1e90fde commit 06d472d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 13 deletions.
15 changes: 13 additions & 2 deletions source/api.d
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,24 @@ struct LogEntry {
string message;
}

struct SeleniumApi {
class SeleniumApi {
string serverUrl;

Capabilities desiredCapabilities;
Capabilities requiredCapabilities;
Capabilities session;

this(string serverUrl,
Capabilities desiredCapabilities,
Capabilities requiredCapabilities = Capabilities(),
Capabilities session = Capabilities()) {

this.serverUrl = serverUrl;
this.desiredCapabilities = desiredCapabilities;
this.requiredCapabilities = requiredCapabilities;
this.session = session;
}

auto timeouts(TimeoutType type, long ms) {
POST("/timeouts", ["type": Json(type), "ms": Json(ms)]);
return this;
Expand Down Expand Up @@ -347,7 +358,7 @@ struct SeleniumApi {
return this;
}

auto closeCurrentWindow() {
auto windowClose() {
DELETE("/window");
return this;
}
Expand Down
34 changes: 27 additions & 7 deletions source/session.d
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module selenium.session;

import selenium.api;
import std.stdio;


class SeleniumSession {
Expand All @@ -11,27 +12,24 @@ class SeleniumSession {
Capabilities requiredCapabilities = Capabilities(),
Capabilities session = Capabilities()) {

api = SeleniumApi(serverUrl, desiredCapabilities, requiredCapabilities, session);
api = new SeleniumApi(serverUrl, desiredCapabilities, requiredCapabilities, session);
}

SeleniumWindow currentWindow() {
return new SeleniumWindow(api.windowHandle, api);
return new SeleniumWindow(api);
}
}

class SeleniumWindow {

protected {
string handle;
SeleniumApi api;
}

this(string handle, SeleniumApi api) {
this.handle = handle;
this(SeleniumApi api) {
this.api = api;
}

Size size() {
auto size() {
return api.windowSize;
}

Expand All @@ -42,6 +40,22 @@ class SeleniumWindow {
void maximize() {
api.windowMaximize;
}

auto screenshot() {
api.screenshot;
}

void close() {
api.windowClose;
}

auto source() {
api.source;
}

auto title() {
api.title;
}
}

unittest {
Expand All @@ -51,4 +65,10 @@ unittest {
assert(session.currentWindow.size == Size(400, 500));

session.currentWindow.maximize;

session.currentWindow.screenshot;
session.currentWindow.source;
session.currentWindow.title;

session.currentWindow.close;
}
8 changes: 4 additions & 4 deletions source/test.d
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import vibe.data.json;

import std.datetime;

unittest {
unittest {/+
auto url1 = "http://www.amazon.com/All-Light-We-Cannot-See/dp/1476746583/";
auto url2 = "http://www.amazon.com/The-Boys-Boat-Americans-Olympics/dp/0143125478/";
auto session = SeleniumApi("http://127.0.0.1:4444/wd/hub", Capabilities.chrome);
auto session = new SeleniumApi("http://127.0.0.1:4444/wd/hub", Capabilities.chrome);
session.timeouts(TimeoutType.script, 10_000);
session.timeouts(TimeoutType.implicit, 10_000);
Expand Down Expand Up @@ -48,7 +48,7 @@ unittest {
session.frame(1);
//session.frameParent;
//session.selectWindow("testOpen");
//session.closeCurrentWindow();
//session.windowClose();
assert(session.windowSize(Size(400, 500)).windowSize == Size(400, 500));
Expand Down Expand Up @@ -183,5 +183,5 @@ unittest {
//session.applicationCacheStatus();
session.disconnect;
session.disconnect;+/
}

0 comments on commit 06d472d

Please sign in to comment.