io.github.bonigarcia.wdm.OperaDriverManager Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of webdrivermanager Show documentation
Show all versions of webdrivermanager Show documentation
Automated driver management and other helper features for Selenium
WebDriver in Java
/*
* (C) Copyright 2015 Boni Garcia (http://bonigarcia.github.io/)
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser General Public License
* (LGPL) version 2.1 which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-2.1.html
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
*/
package io.github.bonigarcia.wdm;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.internal.LinkedTreeMap;
/**
* Manager for Opera.
*
* @author Boni Garcia ([email protected])
* @since 1.0.0
*/
public class OperaDriverManager extends BrowserManager {
@Override
protected List getDrivers(Architecture arch, String version) throws IOException {
URL driverUrl = WdmConfig.getUrl("wdm.operaDriverUrl");
String driverVersion = (version == null) ? WdmConfig
.getString("wdm.operaDriverVersion") : version;
BufferedReader reader = new BufferedReader(new InputStreamReader(
driverUrl.openStream()));
GsonBuilder gsonBuilder = new GsonBuilder();
Gson gson = gsonBuilder.create();
GitHubApi[] releaseArray = gson.fromJson(reader, GitHubApi[].class);
GitHubApi release;
if (driverVersion == null || driverVersion.isEmpty()
|| driverVersion.equalsIgnoreCase(LATEST)) {
log.info("Connecting to {} to check lastest OperaDriver release",
driverUrl);
version = releaseArray[0].getName();
log.info("Latest driver version: {}", version);
release = releaseArray[0];
} else {
version = driverVersion;
release = getVersion(releaseArray, version);
}
if (release == null) {
throw new RuntimeException("Version " + driverVersion
+ " is not available for OperaDriver");
}
List> assets = release.getAssets();
List urls = new ArrayList();
for (LinkedTreeMap asset : assets) {
urls.add(new URL(asset.get("browser_download_url").toString()));
}
if (WdmConfig.getBoolean("wdm.downloadJustForMySystem")) {
urls = filter(arch, urls);
}
reader.close();
return urls;
}
@Override
protected String getExportParameter() {
return WdmConfig.getString("wdm.operaDriverExport");
}
private GitHubApi getVersion(GitHubApi[] releaseArray, String version) {
GitHubApi out = null;
for (GitHubApi release : releaseArray) {
if (release.getName().equalsIgnoreCase(version)) {
out = release;
break;
}
}
return out;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy