Skip to content

Commit

Permalink
added some methods for cookies
Browse files Browse the repository at this point in the history
  • Loading branch information
charybdeide committed Jan 3, 2016
1 parent 4371142 commit e159af7
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 7 deletions.
2 changes: 1 addition & 1 deletion dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"authors": ["Szabo Bogdan"],

"dependencies": {
"vibe-d": "~>0.7.26"
"vibe-d": "~>0.7.27-alpha.2"
},

"versions": ["VibeCustomMain"]
Expand Down
49 changes: 46 additions & 3 deletions source/selenium.d
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import vibe.d;

import vibe.http.client;
import vibe.data.json;
import std.typecons;

//hack for development dub
alias Nint = Nullable!int;
Nint a;

/// https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/url

Expand All @@ -18,11 +23,11 @@ class SeleniumException : Exception {
* Create the exception
*/
this(string msg, string file = __FILE__, ulong line = cast(ulong)__LINE__, Throwable next = null) {
super(msg, file, line, next);
super(msg);
}

this(Json data, string file = __FILE__, ulong line = cast(ulong)__LINE__, Throwable next = null) {
super("Selenium server error: " ~ data.value.message.to!string, file, line, next);
super("Selenium server error: " ~ data.value.message.to!string);
}
}

Expand Down Expand Up @@ -160,6 +165,19 @@ struct Position {
long y;
}

struct Cookie {
string name;
string value;

@optional {
string path;
string domain;
bool secure;
bool httpOnly;
long expiry;
}
}

struct SeleniumSession {
string serverUrl;

Expand Down Expand Up @@ -290,8 +308,26 @@ struct SeleniumSession {
return this;
}

auto cookie() {
return GET!(Cookie[])("/cookie");
}

auto setCookie(Cookie cookie) {
struct Body {
Cookie cookie;
}

POST("/cookie", Body(cookie));
return this;
}

auto deleteAllCookies() {
DELETE("/cookie");
return this;
}


/*
/session/:sessionId/cookie
/session/:sessionId/cookie/:name
/session/:sessionId/source
/session/:sessionId/title
Expand Down Expand Up @@ -372,6 +408,13 @@ session/:sessionId/touch/flick
values);
}

void DELETE(string path) {
if(!isConnected) connect;

makeRequest(HTTPMethod.DELETE,
serverUrl ~ "/session/" ~ session.webdriver_remote_sessionid ~ path);
}

void POST(T)(string path, T values) {
if(!isConnected) connect;

Expand Down
11 changes: 8 additions & 3 deletions source/test.d
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module seleniumTests;
module test;

import selenium;
import std.stdio;
Expand Down Expand Up @@ -35,7 +35,7 @@ unittest {
assert(session.executeAsync!int("arguments[0](1+1)") == 2);
assert(session.executeAsync!int("arguments[2](arguments[0] + arguments[1])", params) == 3);

writeln("screenshot: ", session.screenshot);
session.screenshot;

/* not suported by chrome
writeln("available_engines: ", session.imeAvailableEngines);
Expand All @@ -57,6 +57,11 @@ unittest {
assert(session.windowSize(handle) != Size(400, 500));
assert(session.windowPosition(handle) != Position(100, 200));


assert(session.cookie.length > 0);

auto cookie = Cookie("test", "value");
session.setCookie(cookie);
session.deleteAllCookies;

session.disconnect;
}

0 comments on commit e159af7

Please sign in to comment.