safari_test.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. 'use strict';
  18. const webdriver = require('..'),
  19. proxy = require('../proxy'),
  20. safari = require('../safari'),
  21. assert = require('../testing/assert'),
  22. test = require('../lib/test');
  23. describe('safari.Options', function() {
  24. describe('fromCapabilities', function() {
  25. it('returns a new Options instance if none were defined', function() {
  26. let options = safari.Options.fromCapabilities(
  27. new webdriver.Capabilities());
  28. assert(options).instanceOf(safari.Options);
  29. });
  30. it('returns the options instance if present', function() {
  31. let options = new safari.Options().setCleanSession(true),
  32. caps = options.toCapabilities();
  33. assert(safari.Options.fromCapabilities(caps)).equalTo(options);
  34. });
  35. it('extracts supported WebDriver capabilities', function() {
  36. let proxyPrefs = proxy.direct(),
  37. logPrefs = {},
  38. caps = webdriver.Capabilities.chrome()
  39. .set(webdriver.Capability.PROXY, proxyPrefs)
  40. .set(webdriver.Capability.LOGGING_PREFS, logPrefs);
  41. let options = safari.Options.fromCapabilities(caps);
  42. assert(options.proxy_).equalTo(proxyPrefs);
  43. assert(options.logPrefs_).equalTo(logPrefs);
  44. });
  45. });
  46. describe('toCapabilities', function() {
  47. let options;
  48. before(function() {
  49. options = new safari.Options()
  50. .setCleanSession(true);
  51. });
  52. it('returns a new capabilities object if one is not provided', function() {
  53. let caps = options.toCapabilities();
  54. assert(caps).instanceOf(webdriver.Capabilities);
  55. assert(caps.get('browserName')).equalTo('safari');
  56. assert(caps.get('safari.options')).equalTo(options);
  57. });
  58. it('adds to input capabilities object', function() {
  59. let caps = webdriver.Capabilities.safari();
  60. assert(options.toCapabilities(caps)).equalTo(caps);
  61. assert(caps.get('safari.options')).equalTo(options);
  62. });
  63. it('sets generic driver capabilities', function() {
  64. let proxyPrefs = proxy.direct(),
  65. loggingPrefs = {};
  66. options
  67. .setLoggingPrefs(loggingPrefs)
  68. .setProxy(proxyPrefs);
  69. let caps = options.toCapabilities();
  70. assert(caps.get('proxy')).equalTo(proxyPrefs);
  71. assert(caps.get('loggingPrefs')).equalTo(loggingPrefs);
  72. });
  73. });
  74. });
  75. test.suite(function(env) {
  76. describe('safaridriver', function() {
  77. let service;
  78. afterEach(function() {
  79. if (service) {
  80. return service.kill();
  81. }
  82. });
  83. it('can start safaridriver', function() {
  84. service = new safari.ServiceBuilder().build();
  85. return service.start().then(function(url) {
  86. assert(url).matches(/127\.0\.0\.1/);
  87. });
  88. });
  89. });
  90. }, {browsers: ['safari']});