
org.sitoolkit.tester.domain.appium.AndroidDriverFactory Maven / Gradle / Ivy
/*
* Copyright 2013 Monocrea Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.sitoolkit.tester.domain.appium;
import java.io.FileNotFoundException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
import java.util.Map.Entry;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.UnreachableBrowserException;
import org.sitoolkit.tester.infra.TestException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.ResourceUtils;
import io.appium.java_client.android.AndroidDriver;
/**
* {@link AndroidDriver}インスタンスを生成するためのFacotryです。
*
* @author yuichi.kuwahara
*
*/
public class AndroidDriverFactory {
private static final Logger LOG = LoggerFactory.getLogger(AndroidDriverFactory.class);
private String remoteAddress;
private String apkPath;
private Map capabilityParams;
/**
* {@link AndroidDriver}インスタンスを生成します。
*
* @return {@link AndroidDriver}インスタンス
* @throws FileNotFoundException apkPathで指定されるファイルが存在しない場合に送出します。
* @throws MalformedURLException remoteAddressで指定されるURLの書式が不正な場合に送出します。
*/
public WebDriver create() throws MalformedURLException, FileNotFoundException {
DesiredCapabilities capabilities = new DesiredCapabilities();
if (apkPath != null) {
capabilities.setCapability("app", ResourceUtils.getFile(apkPath).getAbsolutePath());
}
for (Entry entry : capabilityParams.entrySet()) {
capabilities.setCapability(entry.getKey(), entry.getValue());
}
LOG.info("Androidドライバを起動します。");
AndroidDriver> driver = new AndroidDriver<>(new URL(remoteAddress), capabilities);
return driver;
}
public String getRemoteAddress() {
return remoteAddress;
}
public void setRemoteAddress(String remoteAddress) {
this.remoteAddress = remoteAddress;
}
public Map getCapabilityParams() {
return capabilityParams;
}
public void setCapabilityParams(Map capabilityParams) {
this.capabilityParams = capabilityParams;
}
public String getApkPath() {
return apkPath;
}
public void setApkPath(String apkPath) {
this.apkPath = apkPath;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy