Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package com.testfabrik.webmate.javasdk.testUtils;
import com.testfabrik.webmate.javasdk.Browser;
import com.testfabrik.webmate.javasdk.ProjectId;
import com.testfabrik.webmate.javasdk.selenium.SeleniumCapability;
import com.testfabrik.webmate.javasdk.selenium.SeleniumServiceClient;
import java.util.*;
public class browserUtils {
/**
* Get the newest browsers of a project as List of Selenium capabilities
* @param seleniumServiceClient an API Client for Selenium specific methods
* @param projectId id of the project of which the newest browsers should be retrieved
* @return List of the newest browsers in the project (Actual type: ArrayList)
*/
public static List getNewestBrowsersForAnyPlatform(SeleniumServiceClient seleniumServiceClient, ProjectId projectId) {
return getNewestBrowsersForPlatform(seleniumServiceClient, projectId, null);
}
/**
* Get the newest browsers of a project for a specific OS as List of Selenium capabilities
* @param seleniumServiceClient an API Client for Selenium specific methods
* @param projectId id of the project of which the newest browsers should be retrieved
* @param platform operating system which the browsers should be compatible with
* @return List of the newest browsers compatible with the given OS (Actual type: ArrayList)
*/
public static List getNewestBrowsersForPlatform(SeleniumServiceClient seleniumServiceClient, ProjectId projectId, String platform) {
ArrayList browsers = new ArrayList<>();
List capabilities = (List)seleniumServiceClient.getSeleniumCapabilitiesForProject(projectId);
if(platform != null) {
capabilities = filterCapabilitiesByPlatform(capabilities, platform);
}
List chromes = filterCapabilitiesByBrowserType(capabilities, "CHROME");
List firefoxes = filterCapabilitiesByBrowserType(capabilities, "FIREFOX");
List iexplores = filterCapabilitiesByBrowserType(capabilities, "IE");
List edges = filterCapabilitiesByBrowserType(capabilities, "EDGE");
List safaris = filterCapabilitiesByBrowserType(capabilities, "SAFARI");
if (!chromes.isEmpty()) {
Collections.sort(chromes, new SortByVersionDescending());
SeleniumCapability chrome = chromes.get(0);
browsers.add(new Browser(chrome.getBrowserName(), chrome.getVersion(), chrome.getPlatform()));
}
if (!firefoxes.isEmpty()) {
Collections.sort(firefoxes, new SortByVersionDescending());
SeleniumCapability firefox = firefoxes.get(0);
browsers.add(new Browser(firefox.getBrowserName(), firefox.getVersion(), firefox.getPlatform()));
}
if (!iexplores.isEmpty()) {
Collections.sort(iexplores, new SortByVersionDescending());
SeleniumCapability iexplore = iexplores.get(0);
browsers.add(new Browser(iexplore.getBrowserName(), iexplore.getVersion(), iexplore.getPlatform()));
}
if (!edges.isEmpty()) {
Collections.sort(edges, new SortByVersionDescending());
SeleniumCapability edge = edges.get(0);
browsers.add(new Browser(edge.getBrowserName(), edge.getVersion(), edge.getPlatform()));
}
if (!safaris.isEmpty()) {
Collections.sort(safaris, new SortByVersionDescending());
SeleniumCapability safari = safaris.get(0);
browsers.add(new Browser(safari.getBrowserName(), safari.getVersion(), safari.getPlatform()));
}
return browsers;
}
/**
* Search in a project for the newest browser of a specific browser Type (e.g. FIREFOX, CHROME, ...) for any OS
* @param seleniumServiceClient an API Client for Selenium specific methods
* @param projectId id of the project of which the newest browser should be retrieved
* @param browserType type of the browser to be retrieved
* @return requested Browser OR null if no capabilities are fitting
*/
public static Browser getNewestBrowserByTypeForAnyPlatform(SeleniumServiceClient seleniumServiceClient, ProjectId projectId, String browserType) {
return getNewestBrowserByTypeForPlatform(seleniumServiceClient, projectId, browserType, null);
}
/**
* Search in a project for the newest browser of a specific browser Type for a given OS
* @param seleniumServiceClient an API Client for Selenium specific methods
* @param projectId id of the project of which the newest browser should be retrieved
* @param browserType type of the browser to be retrieved
* @param platform operating system which the browser should be compatible with
* @return requested Browser OR null if no capabilities are fitting
*/
public static Browser getNewestBrowserByTypeForPlatform(SeleniumServiceClient seleniumServiceClient, ProjectId projectId, String browserType, String platform) {
List capabilities = (List)seleniumServiceClient.getSeleniumCapabilitiesForProject(projectId);
if(platform != null) {
capabilities = filterCapabilitiesByPlatform(capabilities, platform);
}
capabilities = filterCapabilitiesByBrowserType(capabilities, browserType);
Collections.sort(capabilities, new SortByVersionDescending());
if (!capabilities.isEmpty()) {
SeleniumCapability browserCapability = capabilities.get(0);
return new Browser(browserCapability.getBrowserName(), browserCapability.getVersion(), browserCapability.getPlatform());
}
else{
return null;
}
}
private static List filterCapabilitiesByBrowserType(Collection capabilities, String browserType) {
ArrayList matches = new ArrayList<>();
for (SeleniumCapability capability : capabilities) {
if (capability.getBrowserName().equals(browserType)) {
matches.add(capability);
}
}
return matches;
}
private static List filterCapabilitiesByPlatform(Collection capabilities, String platform) {
ArrayList matches = new ArrayList<>();
for (SeleniumCapability capability : capabilities) {
if (capability.getPlatform().equals(platform)) {
matches.add(capability);
}
}
return matches;
}
private static class SortByVersionAscending implements Comparator {
@Override
public int compare(SeleniumCapability o1, SeleniumCapability o2) {
return Integer.parseInt(o1.getVersion()) - Integer.parseInt(o2.getVersion());
}
}
private static class SortByVersionDescending implements Comparator {
@Override
public int compare(SeleniumCapability o1, SeleniumCapability o2) {
return Integer.parseInt(o2.getVersion()) - Integer.parseInt(o1.getVersion());
}
}
}