Skip to content

Commit 8c7e9b8

Browse files
author
Alex Helfet
committed
Update to new session capabilities API.
1 parent a4d56ab commit 8c7e9b8

File tree

2 files changed

+49
-47
lines changed

2 files changed

+49
-47
lines changed

src/messages.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -244,29 +244,29 @@ mod tests {
244244
#[test]
245245
fn capability_extend() {
246246
let mut session = NewSessionCmd::default();
247-
session.always_match("cap", Some(json!({"a": true})));
247+
session.always_match("cap", json!({"a": true}));
248248
assert_eq!(session.capabilities.alwaysMatch.get("cap").unwrap(), &json!({"a": true}));
249249

250-
session.extend_always_match("cap", json!({"b": false}));
250+
session.always_match("cap", json!({"b": false}));
251251
assert_eq!(session.capabilities.alwaysMatch.get("cap").unwrap(), &json!({"a": true, "b": false}));
252252

253-
session.extend_always_match("cap", json!({"a": false}));
253+
session.always_match("cap", json!({"a": false}));
254254
assert_eq!(session.capabilities.alwaysMatch.get("cap").unwrap(), &json!({"a": false, "b": false}));
255255
}
256256
#[test]
257257
fn capability_extend_replaces_non_obj() {
258258
let mut session = NewSessionCmd::default();
259-
session.always_match("cap", Some(json!("value")));
259+
session.always_match("cap", json!("value"));
260260
assert_eq!(session.capabilities.alwaysMatch.get("cap").unwrap(), &json!("value"));
261261

262-
session.extend_always_match("cap", json!({"a": false}));
262+
session.always_match("cap", json!({"a": false}));
263263
assert_eq!(session.capabilities.alwaysMatch.get("cap").unwrap(), &json!({"a": false}));
264264
}
265265
#[test]
266266
fn capability_extend_replaces_obj_with_non_obj() {
267267
let mut session = NewSessionCmd::default();
268-
session.always_match("cap", Some(json!({"value": true})))
269-
.extend_always_match("cap", json!("new"));
268+
session.always_match("cap", json!({"value": true}))
269+
.always_match("cap", json!("new"));
270270
assert_eq!(session.capabilities.alwaysMatch.get("cap").unwrap(), &json!("new"));
271271
}
272272
}

tests/webdriver_client_integration.rs

+42-40
Original file line numberDiff line numberDiff line change
@@ -29,43 +29,59 @@ enum TestBrowser {
2929

3030
impl TestBrowser {
3131
fn session(&self) -> DriverSession {
32-
match self {
33-
&TestBrowser::Firefox => {
34-
let gecko = GeckoDriver::build()
35-
.spawn().expect("Error starting geckodriver");
36-
let mut session_params = NewSessionCmd::default();
37-
session_params.extend_always_match(
38-
"moz:firefoxOptions", json!({
39-
"args": ["-headless"]
40-
}));
41-
gecko.session(&session_params).expect("Error starting session")
32+
match *self {
33+
TestBrowser::Firefox => {
34+
GeckoDriver::build()
35+
.spawn()
36+
.expect("Error starting geckodriver")
37+
.session(&self.new_session_cmd())
38+
.expect("Error starting session")
4239
}
43-
&TestBrowser::Chrome => {
44-
let chrome = ChromeDriver::build()
45-
.spawn().expect("Error starting chromedriver");
46-
47-
// Make sure tests run in headless mode without a sandbox (Travis CI)
48-
let mut session_params: NewSessionCmd = Default::default();
49-
session_params.extend_always_match(
50-
"goog:chromeOptions", json!({
51-
"args": ["--no-sandbox", "--headless"],
52-
}));
53-
chrome.session(&session_params).expect("Error starting session")
40+
TestBrowser::Chrome => {
41+
ChromeDriver::build()
42+
.spawn()
43+
.expect("Error starting chromedriver")
44+
.session(&self.new_session_cmd())
45+
.expect("Error starting session")
5446
}
5547
}
5648
}
49+
5750
fn driver(&self) -> Box<Driver> {
58-
match self {
59-
&TestBrowser::Firefox => {
51+
match *self {
52+
TestBrowser::Firefox => {
6053
Box::new(GeckoDriver::build()
6154
.spawn().expect("Error starting geckodriver"))
6255
}
63-
&TestBrowser::Chrome => {
56+
TestBrowser::Chrome => {
6457
Box::new(ChromeDriver::build()
6558
.spawn().expect("Error starting chromedriver"))
6659
}
6760
}
6861
}
62+
63+
fn new_session_cmd(&self) -> NewSessionCmd {
64+
let mut new = NewSessionCmd::default();
65+
66+
match *self {
67+
TestBrowser::Firefox => {
68+
new.always_match(
69+
"moz:firefoxOptions", json!({
70+
"args": ["-headless"]
71+
}))
72+
}
73+
TestBrowser::Chrome => {
74+
// Tests must run in headless mode without a
75+
// sandbox (required for Travis CI).
76+
new.always_match(
77+
"goog:chromeOptions", json!({
78+
"args": ["--no-sandbox", "--headless"],
79+
}))
80+
}
81+
};
82+
83+
new
84+
}
6985
}
7086

7187
/// Tests defined in this macro are run once per browser. See the macro invocations below.
@@ -422,22 +438,8 @@ macro_rules! browser_tests {
422438
.url(driver.url())
423439
.build().unwrap();
424440

425-
// TODO: Add these common settings to a method on
426-
// NewSessionCmd in lib, or somewhere similar.
427-
let mut session_params: NewSessionCmd = Default::default();
428-
session_params.extend_always_match(
429-
// Run Chrome in headless mode without sandbox
430-
// (required for Travis CI).
431-
"goog:chromeOptions", json!({
432-
"args": ["--no-sandbox", "--headless"],
433-
}));
434-
session_params.extend_always_match(
435-
// Run Firefox in headless mode.
436-
"moz:firefoxOptions", json!({
437-
"args": ["-headless"]
438-
}));
439-
440-
let sess = http_driver.session(&session_params).unwrap();
441+
let sess = http_driver.session(&test_browser().new_session_cmd())
442+
.unwrap();
441443

442444
let server = FileServer::new();
443445
let test_url = server.url("/page1.html");

0 commit comments

Comments
 (0)