1// Licensed to the Software Freedom Conservancy (SFC) under one2// or more contributor license agreements. See the NOTICE file3// distributed with this work for additional information4// regarding copyright ownership. The SFC licenses this file5// to you under the Apache License, Version 2.0 (the6// "License"); you may not use this file except in compliance7// with the License. You may obtain a copy of the License at8//9// http://www.apache.org/licenses/LICENSE-2.010//11// Unless required by applicable law or agreed to in writing,12// software distributed under the License is distributed on an13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY14// KIND, either express or implied. See the License for the15// specific language governing permissions and limitations16// under the License.17package org.openqa.selenium.safari;18import com.google.common.collect.ImmutableMap;19import org.openqa.selenium.Beta;20import org.openqa.selenium.Capabilities;21import org.openqa.selenium.WebDriverException;22import org.openqa.selenium.remote.FileDetector;23import org.openqa.selenium.remote.RemoteWebDriver;24import org.openqa.selenium.remote.Response;25/**26 * A WebDriver implementation that controls Safari using a browser extension27 * (consequently, only Safari 5.1+ is supported).28 *29 * This driver can be configured using the {@link SafariOptions} class.30 */31public class SafariDriver extends RemoteWebDriver {32 /**33 * Initializes a new SafariDriver} class with default {@link SafariOptions}.34 */35 public SafariDriver() {36 this(new SafariOptions());37 }38 /**39 * Converts the specified {@link Capabilities} to a {@link SafariOptions}40 * instance and initializes a new SafariDriver using these options.41 * @see SafariOptions#fromCapabilities(Capabilities)42 *43 * @param desiredCapabilities capabilities requested of the driver44 * @deprecated Use {@link SafariDriver(SafariOptions)} instead.45 */46 @Deprecated47 public SafariDriver(Capabilities desiredCapabilities) {48 this(SafariOptions.fromCapabilities(desiredCapabilities));49 }50 /**51 * Initializes a new SafariDriver using the specified {@link SafariOptions}.52 *53 * @param safariOptions safari specific options / capabilities for the driver54 */55 public SafariDriver(SafariOptions safariOptions) {56 this(SafariDriverService.createDefaultService(safariOptions), safariOptions);57 }58 /**59 * Initializes a new SafariDriver backed by the specified {@link SafariDriverService}.60 *61 * @param safariService preconfigured safari service62 */63 public SafariDriver(SafariDriverService safariService) {64 this(safariService, new SafariOptions());65 }66 /**67 * Initializes a new SafariDriver using the specified {@link SafariOptions}.68 *69 * @param safariOptions safari specific options / capabilities for the driver70 */71 public SafariDriver(SafariDriverService safariServer, SafariOptions safariOptions) {72 super(new SafariDriverCommandExecutor(safariServer), safariOptions);73 }74 @Override75 public void setFileDetector(FileDetector detector) {76 throw new WebDriverException(77 "Setting the file detector only works on remote webdriver instances obtained " +78 "via RemoteWebDriver");79 }80 /**81 * Open either a new tab or window, depending on what is requested, and return the window handle82 * without switching to it.83 *84 * @return The handle of the new window.85 */86 @Beta87 public String newWindow(WindowType type) {88 Response response = execute(89 "SAFARI_NEW_WINDOW",90 ImmutableMap.of("newTab", type == WindowType.TAB));91 return (String) response.getValue();92 }93 public enum WindowType {94 TAB,95 WINDOW,96 }97}...