diff --git a/source/api.d b/source/api.d index 34a91a8..4ec58bb 100755 --- a/source/api.d +++ b/source/api.d @@ -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; @@ -347,7 +358,7 @@ struct SeleniumApi { return this; } - auto closeCurrentWindow() { + auto windowClose() { DELETE("/window"); return this; } diff --git a/source/session.d b/source/session.d index 75e8c55..8680579 100644 --- a/source/session.d +++ b/source/session.d @@ -1,6 +1,7 @@ module selenium.session; import selenium.api; +import std.stdio; class SeleniumSession { @@ -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; } @@ -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 { @@ -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; } diff --git a/source/test.d b/source/test.d index 1d7d12f..1ceea25 100644 --- a/source/test.d +++ b/source/test.d @@ -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); @@ -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)); @@ -183,5 +183,5 @@ unittest { //session.applicationCacheStatus(); - session.disconnect; + session.disconnect;+/ }