|
| 1 | +/* |
| 2 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | + * you may not use this file except in compliance with the License. |
| 4 | + * See the NOTICE file distributed with this work for additional |
| 5 | + * information regarding copyright ownership. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package io.appium.java_client.chromium; |
| 18 | + |
| 19 | +import io.appium.java_client.AppiumClientConfig; |
| 20 | +import io.appium.java_client.AppiumDriver; |
| 21 | +import io.appium.java_client.remote.AutomationName; |
| 22 | +import io.appium.java_client.service.local.AppiumDriverLocalService; |
| 23 | +import io.appium.java_client.service.local.AppiumServiceBuilder; |
| 24 | +import org.openqa.selenium.Capabilities; |
| 25 | +import org.openqa.selenium.remote.HttpCommandExecutor; |
| 26 | +import org.openqa.selenium.remote.http.ClientConfig; |
| 27 | +import org.openqa.selenium.remote.http.HttpClient; |
| 28 | + |
| 29 | +import java.net.URL; |
| 30 | + |
| 31 | +/** |
| 32 | + * <p>ChromiumDriver is an officially supported Appium driver created to automate Mobile browsers |
| 33 | + * and web views based on the Chromium engine. The driver uses W3CWebDriver protocol and is built |
| 34 | + * on top of chromium driver server.</p> |
| 35 | + * <br> |
| 36 | + * <p>Read <a href='https://github.com/appium/appium-chromium-driver'>appium-chromium-driver</a> |
| 37 | + * for more details on how to configure and use it.</p> |
| 38 | + */ |
| 39 | +public class ChromiumDriver extends AppiumDriver { |
| 40 | + private static final String AUTOMATION_NAME = AutomationName.CHROMIUM; |
| 41 | + |
| 42 | + public ChromiumDriver(HttpCommandExecutor executor, Capabilities capabilities) { |
| 43 | + super(executor, ensureAutomationName(capabilities, AUTOMATION_NAME)); |
| 44 | + } |
| 45 | + |
| 46 | + public ChromiumDriver(URL remoteAddress, Capabilities capabilities) { |
| 47 | + super(remoteAddress, ensureAutomationName(capabilities, AUTOMATION_NAME)); |
| 48 | + } |
| 49 | + |
| 50 | + public ChromiumDriver(URL remoteAddress, HttpClient.Factory httpClientFactory, Capabilities capabilities) { |
| 51 | + super(remoteAddress, httpClientFactory, ensureAutomationName(capabilities, AUTOMATION_NAME)); |
| 52 | + } |
| 53 | + |
| 54 | + public ChromiumDriver(AppiumDriverLocalService service, Capabilities capabilities) { |
| 55 | + super(service, ensureAutomationName(capabilities, AUTOMATION_NAME)); |
| 56 | + } |
| 57 | + |
| 58 | + public ChromiumDriver(AppiumDriverLocalService service, HttpClient.Factory httpClientFactory, |
| 59 | + Capabilities capabilities) { |
| 60 | + super(service, httpClientFactory, ensureAutomationName(capabilities, AUTOMATION_NAME)); |
| 61 | + } |
| 62 | + |
| 63 | + public ChromiumDriver(AppiumServiceBuilder builder, Capabilities capabilities) { |
| 64 | + super(builder, ensureAutomationName(capabilities, AUTOMATION_NAME)); |
| 65 | + } |
| 66 | + |
| 67 | + public ChromiumDriver(AppiumServiceBuilder builder, HttpClient.Factory httpClientFactory, |
| 68 | + Capabilities capabilities) { |
| 69 | + super(builder, httpClientFactory, ensureAutomationName(capabilities, AUTOMATION_NAME)); |
| 70 | + } |
| 71 | + |
| 72 | + public ChromiumDriver(HttpClient.Factory httpClientFactory, Capabilities capabilities) { |
| 73 | + super(httpClientFactory, ensureAutomationName(capabilities, AUTOMATION_NAME)); |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * This is a special constructor used to connect to a running driver instance. |
| 78 | + * It does not do any necessary verifications, but rather assumes the given |
| 79 | + * driver session is already running at `remoteSessionAddress`. |
| 80 | + * The maintenance of driver state(s) is the caller's responsibility. |
| 81 | + * !!! This API is supposed to be used for **debugging purposes only**. |
| 82 | + * |
| 83 | + * @param remoteSessionAddress The address of the **running** session including the session identifier. |
| 84 | + * @param platformName The name of the target platform. |
| 85 | + */ |
| 86 | + public ChromiumDriver(URL remoteSessionAddress, String platformName) { |
| 87 | + super(remoteSessionAddress, platformName, AUTOMATION_NAME); |
| 88 | + } |
| 89 | + |
| 90 | + /** |
| 91 | + * Creates a new instance based on the given ClientConfig and {@code capabilities}. |
| 92 | + * The HTTP client is default client generated by {@link HttpCommandExecutor#getDefaultClientFactory}. |
| 93 | + * For example: |
| 94 | + * |
| 95 | + * <pre> |
| 96 | + * |
| 97 | + * ClientConfig clientConfig = ClientConfig.defaultConfig() |
| 98 | + * .baseUri(URI.create("WebDriver URL")) |
| 99 | + * .readTimeout(Duration.ofMinutes(5)); |
| 100 | + * ChromiumOptions options = new ChromiumOptions(); |
| 101 | + * ChromiumDriver driver = new ChromiumDriver(clientConfig, options); |
| 102 | + * |
| 103 | + * </pre> |
| 104 | + * |
| 105 | + * @param clientConfig take a look at {@link ClientConfig} |
| 106 | + * @param capabilities take a look at {@link Capabilities} |
| 107 | + * |
| 108 | + */ |
| 109 | + public ChromiumDriver(ClientConfig clientConfig, Capabilities capabilities) { |
| 110 | + super(AppiumClientConfig.fromClientConfig(clientConfig), ensureAutomationName(capabilities, AUTOMATION_NAME)); |
| 111 | + } |
| 112 | + |
| 113 | + /** |
| 114 | + * Creates a new instance based on the given ClientConfig and {@code capabilities}. |
| 115 | + * The HTTP client is default client generated by {@link HttpCommandExecutor#getDefaultClientFactory}. |
| 116 | + * For example: |
| 117 | + * |
| 118 | + * <pre> |
| 119 | + * |
| 120 | + * AppiumClientConfig appiumClientConfig = AppiumClientConfig.defaultConfig() |
| 121 | + * .directConnect(true) |
| 122 | + * .baseUri(URI.create("WebDriver URL")) |
| 123 | + * .readTimeout(Duration.ofMinutes(5)); |
| 124 | + * ChromiumOptions options = new ChromiumOptions(); |
| 125 | + * ChromiumDriver driver = new ChromiumDriver(options, appiumClientConfig); |
| 126 | + * |
| 127 | + * </pre> |
| 128 | + * |
| 129 | + * @param appiumClientConfig take a look at {@link AppiumClientConfig} |
| 130 | + * @param capabilities take a look at {@link Capabilities} |
| 131 | + * |
| 132 | + */ |
| 133 | + public ChromiumDriver(AppiumClientConfig appiumClientConfig, Capabilities capabilities) { |
| 134 | + super(appiumClientConfig, ensureAutomationName(capabilities, AUTOMATION_NAME)); |
| 135 | + } |
| 136 | + |
| 137 | + public ChromiumDriver(Capabilities capabilities) { |
| 138 | + super(ensureAutomationName(capabilities, AUTOMATION_NAME)); |
| 139 | + } |
| 140 | +} |
0 commit comments