|
| 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 | +package org.openqa.selenium.safari; |
| 19 | + |
| 20 | +import com.google.common.collect.ImmutableList; |
| 21 | +import com.google.common.collect.ImmutableMap; |
| 22 | + |
| 23 | +import org.openqa.selenium.WebDriverException; |
| 24 | +import org.openqa.selenium.remote.service.DriverService; |
| 25 | + |
| 26 | +import java.io.File; |
| 27 | +import java.io.IOException; |
| 28 | + |
| 29 | +public class SafariDriverService extends DriverService { |
| 30 | + |
| 31 | + private static final File SAFARI_DRIVER_EXECUTABLE = new File("/usr/bin/safaridriver"); |
| 32 | + |
| 33 | + public SafariDriverService(File executable, int port, ImmutableList<String> args, |
| 34 | + ImmutableMap<String, String> environment) throws IOException { |
| 35 | + super(executable, port, args, environment); |
| 36 | + } |
| 37 | + |
| 38 | + public static SafariDriverService createDefaultService(SafariOptions options) { |
| 39 | + if (SAFARI_DRIVER_EXECUTABLE.exists()) { |
| 40 | + return new Builder().usingPort(options.getPort()).build(); |
| 41 | + } |
| 42 | + return null; |
| 43 | + } |
| 44 | + |
| 45 | + public static class Builder extends DriverService.Builder< |
| 46 | + SafariDriverService, SafariDriverService.Builder> { |
| 47 | + |
| 48 | + protected File findDefaultExecutable() { |
| 49 | + return SAFARI_DRIVER_EXECUTABLE; |
| 50 | + } |
| 51 | + |
| 52 | + protected ImmutableList<String> createArgs() { |
| 53 | + return ImmutableList.of("--port", String.valueOf(getPort())); |
| 54 | + } |
| 55 | + |
| 56 | + protected SafariDriverService createDriverService(File exe, int port, ImmutableList<String> args, |
| 57 | + ImmutableMap<String, String> environment) { |
| 58 | + try { |
| 59 | + return new SafariDriverService(exe, port, args, environment); |
| 60 | + } catch (IOException e) { |
| 61 | + throw new WebDriverException(e); |
| 62 | + } |
| 63 | + } |
| 64 | + } |
| 65 | +} |
0 commit comments