UNPKG

3.53 kBJavaScriptView Raw
1// Licensed to the Software Freedom Conservancy (SFC) under one
2// or more contributor license agreements. See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership. The SFC licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License. You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied. See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18'use strict';
19
20const webdriver = require('..'),
21 proxy = require('../proxy'),
22 safari = require('../safari'),
23 assert = require('../testing/assert'),
24 test = require('../lib/test');
25
26
27describe('safari.Options', function() {
28 describe('fromCapabilities', function() {
29 it('returns a new Options instance if none were defined', function() {
30 let options = safari.Options.fromCapabilities(
31 new webdriver.Capabilities());
32 assert(options).instanceOf(safari.Options);
33 });
34
35 it('returns the options instance if present', function() {
36 let options = new safari.Options().setCleanSession(true),
37 caps = options.toCapabilities();
38 assert(safari.Options.fromCapabilities(caps)).equalTo(options);
39 });
40
41 it('extracts supported WebDriver capabilities', function() {
42 let proxyPrefs = proxy.direct(),
43 logPrefs = {},
44 caps = webdriver.Capabilities.chrome()
45 .set(webdriver.Capability.PROXY, proxyPrefs)
46 .set(webdriver.Capability.LOGGING_PREFS, logPrefs);
47
48 let options = safari.Options.fromCapabilities(caps);
49 assert(options.proxy_).equalTo(proxyPrefs);
50 assert(options.logPrefs_).equalTo(logPrefs);
51 });
52 });
53
54 describe('toCapabilities', function() {
55 let options;
56
57 before(function() {
58 options = new safari.Options()
59 .setCleanSession(true);
60 });
61
62 it('returns a new capabilities object if one is not provided', function() {
63 let caps = options.toCapabilities();
64 assert(caps).instanceOf(webdriver.Capabilities);
65 assert(caps.get('browserName')).equalTo('safari');
66 assert(caps.get('safari.options')).equalTo(options);
67 });
68
69 it('adds to input capabilities object', function() {
70 let caps = webdriver.Capabilities.safari();
71 assert(options.toCapabilities(caps)).equalTo(caps);
72 assert(caps.get('safari.options')).equalTo(options);
73 });
74
75 it('sets generic driver capabilities', function() {
76 let proxyPrefs = proxy.direct(),
77 loggingPrefs = {};
78
79 options
80 .setLoggingPrefs(loggingPrefs)
81 .setProxy(proxyPrefs);
82
83 let caps = options.toCapabilities();
84 assert(caps.get('proxy')).equalTo(proxyPrefs);
85 assert(caps.get('loggingPrefs')).equalTo(loggingPrefs);
86 });
87 });
88});
89
90test.suite(function(env) {
91 describe('safaridriver', function() {
92 let service;
93
94 afterEach(function() {
95 if (service) {
96 return service.kill();
97 }
98 });
99
100 it('can start safaridriver', function() {
101 service = new safari.ServiceBuilder().build();
102
103 return service.start().then(function(url) {
104 assert(url).matches(/127\.0\.0\.1/);
105 });
106 });
107 });
108}, {browsers: ['safari']});