下面列出了org.openqa.selenium.Platform#valueOf ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private Object getValue( String clazz, String value )
{
Object rtn = null;
switch ( clazz )
{
case "BOOLEAN":
rtn = Boolean.parseBoolean( value );
break;
case "OBJECT":
rtn = value;
break;
case "STRING":
rtn = value;
break;
case "PLATFORM":
rtn = ((value != null) ? Platform.valueOf( value.toUpperCase() ) : null );
break;
}
return rtn;
}
/**
* Instantiates a new browser specs.
*
* @param jsonObject the json object
*/
public BrowserSpecs(JsonObject jsonObject){
this();
// Mandatory
this.version = jsonObject.getString("version", null);
String platform = jsonObject.getString("platform", "localhost").toUpperCase();
// appium requires device name, but any is fine
this.deviceName = jsonObject.getString("deviceName", "unknown");
this.browserName = jsonObject.getString("browserName", "Browser");
// if (this.deviceName.equals("unknown")) {
// // will throw exception in case the client is not an app
// this.browserName = jsonObject.getString("browserName");
// } else {
// this.browserName = platform.toLowerCase().contains("android") ? "APK" : "IPA";
// }
this.platformVersion = jsonObject.getString("platformVersion", null);
if (platform.equalsIgnoreCase("localhost")) {
platform = getSystemPlatform();
}
this.platform = Platform.valueOf(platform);
// Optional
this.pathToBinary = jsonObject.getString("pathToBinary", this.pathToBinary);
this.pathToDriver = jsonObject.getString("pathToDriver", this.pathToDriver);
this.profile = jsonObject.getString("profile", "");
this.extension = jsonObject.getString("extension", "");
}
/**
* Resolves a platform capability to a Platform instance.
*
* Taken from DefaultCapabilityMatcher with small modifications.
*
* @param o Object to resolve to a Platform
*
* @return Resolved Platform instance or <code>null</code>.
*/
Platform extractPlatform(Object o) {
if (o == null) {
return null;
}
if (o instanceof Platform) {
return (Platform) o;
} else if (o instanceof String) {
String name = o.toString();
try {
return Platform.valueOf(name.toUpperCase());
} catch (IllegalArgumentException e) {
// no exact match, continue to look for a partial match
}
for (Platform os : Platform.values()) {
for (String matcher : os.getPartOfOsName()) {
if ("".equals(matcher))
continue;
if (name.equalsIgnoreCase(matcher)) {
return os;
}
}
}
return null;
} else {
return null;
}
}
public Platform getPlatformType() {
return Platform.valueOf(getPlatform().toUpperCase());
}
/**
* {@link SeleniumManager} constructor managed by spring
*
* @param defaultDomain domain the whole selenium related SenBot will work from
* @param seleniumHubIP if running on a grid this is the hub ip to be used
* @param target The target environements to run the selenium tests on
* @param defaultWindowWidth browser window width to start the browser with
* @param defaultWindowHeight browser window height to start the browser with
* @param aTimeout implicit timeout to be used by selenium when performing a dom lookup or page refresh
* @throws IOException
*/
public SeleniumManager(
String defaultDomain,
String seleniumHubIP,
String target,
int defaultWindowWidth,
int defaultWindowHeight,
int aTimeout,
String implicitTimeout,
String webdriverCreationHookClassName)
throws IOException, ClassNotFoundException, IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchMethodException {
if(!StringUtils.isBlank(webdriverCreationHookClassName)) {
Constructor<?> constructor = Class.forName(webdriverCreationHookClassName).getConstructor();
webDriverCreationHook = (WebDriverCreationHook) constructor.newInstance();
}
if(defaultDomain != null) {
if(defaultDomain.toLowerCase().startsWith("http")) {
this.defaultDomain = defaultDomain;
}
else {
this.defaultDomain = "http://" + defaultDomain;
}
}
this.defaultWindowWidth = defaultWindowWidth;
this.defaultWindowHeight = defaultWindowHeight;
this.timeout = aTimeout;
if (!StringUtils.isBlank(implicitTimeout)) {
this.implicitTimeout = Integer.parseInt(implicitTimeout);
}
this.seleniumHub = (StringUtils.isBlank(seleniumHubIP)) ? null : new URL(seleniumHubIP);
if (StringUtils.isBlank(target)) {
throw new IllegalArgumentException("The selenium target environment property cannot be blank. Refer to senbot-runner.properties");
} else {
for (String ii : target.split(";")) {
String[] parts = ii.split(",");
String browserVersion = parts.length > 1 ? parts[1].trim() : "ANY";
Platform platform = Platform.valueOf(parts.length > 2 ? parts[2].trim() : "ANY");
String locale = parts.length > 3 ? parts[3].trim() : null;
TestEnvironment testEnvironment = new TestEnvironment(parts[0].trim(),
browserVersion,
platform,
locale);
seleniumTestEnvironments.add(testEnvironment);
}
}
}
/**
* Connects SeleniumHelper to a remote web driver.
* @param browser name of browser to connect to.
* @param version version of browser.
* @param platformName platform browser must run on.
* @param url url to connect to browser.
* @return true.
* @throws MalformedURLException if supplied url can not be transformed to URL.
*/
public boolean connectToDriverForVersionOnAt(String browser, String version, String platformName, String url)
throws MalformedURLException {
Platform platform = Platform.valueOf(platformName);
DesiredCapabilities desiredCapabilities = new DesiredCapabilities(browser, version, platform);
desiredCapabilities.setVersion(version);
return createAndSetRemoteDriver(url, desiredCapabilities);
}