How to use waitUntilAvailable method of org.openqa.selenium.safari.SafariTechPreviewDriverService class

Best Selenium code snippet using org.openqa.selenium.safari.SafariTechPreviewDriverService.waitUntilAvailable

Run Selenium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

copy
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
18package org.openqa.selenium.safari;
19
20import static java.util.concurrent.TimeUnit.MILLISECONDS;
21
22import com.google.auto.service.AutoService;
23
24import org.openqa.selenium.Capabilities;
25import org.openqa.selenium.WebDriverException;
26import org.openqa.selenium.net.PortProber;
27import org.openqa.selenium.remote.service.DriverService;
28
29import java.io.File;
30import java.io.IOException;
31import java.time.Duration;
32import java.util.Arrays;
33import java.util.List;
34import java.util.Map;
35
36public class SafariTechPreviewDriverService extends DriverService {
37
38  /**
39   * System property that defines the location of the tech preview safaridriver executable that
40   * will be used by the {@link #createDefaultService() default service}.
41   */
42  public static final String TP_SAFARI_DRIVER_EXE_PROPERTY = "webdriver.tp.safari.driver";
43
44  private static final File TP_SAFARI_DRIVER_EXECUTABLE =
45    new File("/Applications/Safari Technology Preview.app/Contents/MacOS/safaridriver");
46
47  public SafariTechPreviewDriverService(
48    File executable,
49    int port,
50    List<String> args,
51    Map<String, String> environment) throws IOException {
52    super(executable, port, DEFAULT_TIMEOUT, args, environment);
53  }
54
55  public SafariTechPreviewDriverService(
56    File executable,
57    int port,
58    Duration timeout,
59    List<String> args,
60    Map<String, String> environment) throws IOException {
61    super(executable, port, timeout, args, environment);
62  }
63
64  public static SafariTechPreviewDriverService createDefaultService() {
65    return new Builder().build();
66  }
67
68  @Override
69  protected void waitUntilAvailable() {
70    try {
71      PortProber.waitForPortUp(getUrl().getPort(), (int) getTimeout().toMillis(), MILLISECONDS);
72    } catch (RuntimeException e) {
73      throw new WebDriverException(e);
74    }
75  }
76
77  @AutoService(DriverService.Builder.class)
78  public static class Builder extends DriverService.Builder<
79    SafariTechPreviewDriverService, SafariTechPreviewDriverService.Builder> {
80
81    @Override
82    public int score(Capabilities capabilities) {
83      int score = 0;
84
85      if (SafariOptions.SAFARI_TECH_PREVIEW.equals(capabilities.getBrowserName())) {
86        score++;
87      }
88
89      return score;
90    }
91
92    @Override
93    protected File findDefaultExecutable() {
94      File exe;
95      if (System.getProperty(TP_SAFARI_DRIVER_EXE_PROPERTY) != null) {
96        exe = new File(System.getProperty(TP_SAFARI_DRIVER_EXE_PROPERTY));
97      } else {
98        exe = TP_SAFARI_DRIVER_EXECUTABLE;
99      }
100
101      if (!exe.isFile()) {
102        throw new WebDriverException("Unable to find driver executable: " + exe);
103      }
104
105      return exe;
106    }
107
108    @Override
109    protected List<String> createArgs() {
110      return Arrays.asList("--port", String.valueOf(getPort()));
111    }
112
113    @Override
114    protected SafariTechPreviewDriverService createDriverService(
115      File exe,
116      int port,
117      Duration timeout,
118      List<String> args,
119      Map<String, String> environment) {
120      try {
121        return new SafariTechPreviewDriverService(exe, port, timeout, args, environment);
122      } catch (IOException e) {
123        throw new WebDriverException(e);
124      }
125    }
126  }
127}
128
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Most used method in SafariTechPreviewDriverService

Trigger waitUntilAvailable code on LambdaTest Cloud Grid

Execute automation tests with waitUntilAvailable on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie