本文整理汇总了Java中org.openqa.selenium.remote.DriverCommand类的典型用法代码示例。如果您正苦于以下问题:Java DriverCommand类的具体用法?Java DriverCommand怎么用?Java DriverCommand使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DriverCommand类属于org.openqa.selenium.remote包,在下文中一共展示了DriverCommand类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeAsyncScript
import org.openqa.selenium.remote.DriverCommand; //导入依赖的package包/类
@Override
public Object executeAsyncScript(String script, Object... args) {
if (!getCapabilities().isJavascriptEnabled()) {
throw new UnsupportedOperationException(
"You must be using an underlying instance of " + "WebDriver that supports executing javascript");
}
// Escape the quote marks
script = script.replaceAll("\"", "\\\"");
Iterable<Object> convertedArgs = Iterables.transform(Lists.newArrayList(args), new WebElementToJsonConverter());
Map<String, ?> params = ImmutableMap.of("script", script, "args", Lists.newArrayList(convertedArgs));
return execute(DriverCommand.EXECUTE_ASYNC_SCRIPT, params).getValue();
}
示例2: executeScript
import org.openqa.selenium.remote.DriverCommand; //导入依赖的package包/类
@Override
public Object executeScript(String script, Object... args) {
if (!getCapabilities().isJavascriptEnabled()) {
throw new UnsupportedOperationException(
"You must be using an underlying instance of WebDriver that supports executing javascript");
}
// Escape the quote marks
script = script.replaceAll("\"", "\\\"");
Iterable<Object> convertedArgs = Iterables.transform(Lists.newArrayList(args), new WebElementToJsonConverter());
Map<String, ?> params = ImmutableMap.of("script", script, "args", Lists.newArrayList(convertedArgs));
return execute(DriverCommand.EXECUTE_SCRIPT, params).getValue();
}
示例3: execute
import org.openqa.selenium.remote.DriverCommand; //导入依赖的package包/类
@Override
public Response execute(Command command) throws IOException {
Response response;
if (DriverCommand.QUIT.equals(command.getName())) {
response = grid.execute(command);
} else {
response = node.execute(command);
}
return response;
}
示例4: context
import org.openqa.selenium.remote.DriverCommand; //导入依赖的package包/类
public WebDriver context( String newContext )
{
setLastAction();
if ( !contextSwitchSupported )
return webDriver;
if ( newContext == null || newContext.equals( currentContext ) )
return webDriver;
if ( webDriver != null )
{
if ( webDriver instanceof RemoteWebDriver )
{
log.info( "Switching context to " + newContext );
RemoteExecuteMethod executeMethod = new RemoteExecuteMethod( (RemoteWebDriver) webDriver );
Map<String, String> params = new HashMap<String, String>( 5 );
params.put( "name", newContext );
executeMethod.execute( DriverCommand.SWITCH_TO_CONTEXT, params );
}
else if ( webDriver instanceof AppiumDriver )
{
log.info( "Switching context to " + newContext );
((AppiumDriver) webDriver).context( newContext );
}
else
return null;
if ( newContext.equals( _getContext() ) )
currentContext = newContext;
else
throw new IllegalStateException( "Could not change context to " + newContext + " against " + webDriver );
}
return webDriver;
}
示例5: _getContext
import org.openqa.selenium.remote.DriverCommand; //导入依赖的package包/类
/**
* _get context.
*
* @return the string
*/
private String _getContext()
{
if ( webDriver != null )
{
try
{
if ( webDriver instanceof RemoteWebDriver )
{
RemoteExecuteMethod executeMethod = new RemoteExecuteMethod( (RemoteWebDriver) webDriver );
return (String) executeMethod.execute( DriverCommand.GET_CURRENT_CONTEXT_HANDLE, null );
}
else if ( webDriver instanceof AppiumDriver )
{
return ((AppiumDriver) webDriver).getContext();
}
}
catch ( Exception e )
{
log.warn( "Context Switches are not supported - " + e.getMessage() );
contextSwitchSupported = false;
}
}
return null;
}
示例6: getContextHandles
import org.openqa.selenium.remote.DriverCommand; //导入依赖的package包/类
public Set<String> getContextHandles()
{
setLastAction();
if ( contextHandles != null )
return contextHandles;
RemoteExecuteMethod executeMethod = new RemoteExecuteMethod( (RemoteWebDriver) webDriver );
List<String> handleList = (List<String>) executeMethod.execute( DriverCommand.GET_CONTEXT_HANDLES, null );
contextHandles = new HashSet<String>( 10 );
contextHandles.addAll( handleList );
return contextHandles;
}
示例7: switchToContext
import org.openqa.selenium.remote.DriverCommand; //导入依赖的package包/类
private static void switchToContext(RemoteWebDriver driver, String context)
{
RemoteExecuteMethod executeMethod = new RemoteExecuteMethod(driver);
Map<String,String> params = new HashMap<>();
params.put("name", context);
executeMethod.execute(DriverCommand.SWITCH_TO_CONTEXT, params);
}
示例8: getCurrentContextHandle
import org.openqa.selenium.remote.DriverCommand; //导入依赖的package包/类
private static String getCurrentContextHandle(RemoteWebDriver driver)
{
RemoteExecuteMethod executeMethod = new RemoteExecuteMethod(driver);
String context = (String) executeMethod.execute(DriverCommand.GET_CURRENT_CONTEXT_HANDLE, null);
return context;
}
示例9: getContextHandles
import org.openqa.selenium.remote.DriverCommand; //导入依赖的package包/类
@Override public Set<String> getContextHandles() {
Response response = execute(DriverCommand.GET_CONTEXT_HANDLES);
Object value = response.getValue();
try {
List<String> returnedValues = (List<String>) value;
return new LinkedHashSet<>(returnedValues);
} catch (ClassCastException ex) {
throw new WebDriverException(
"Returned value cannot be converted to List<String>: " + value, ex);
}
}
示例10: getContext
import org.openqa.selenium.remote.DriverCommand; //导入依赖的package包/类
@Override public String getContext() {
String contextName =
String.valueOf(execute(DriverCommand.GET_CURRENT_CONTEXT_HANDLE).getValue());
if (contextName.equals("null")) {
return null;
}
return contextName;
}
示例11: getOrientation
import org.openqa.selenium.remote.DriverCommand; //导入依赖的package包/类
@Override public ScreenOrientation getOrientation() {
Response response = execute(DriverCommand.GET_SCREEN_ORIENTATION);
String orientation = response.getValue().toString().toLowerCase();
if (orientation.equals(ScreenOrientation.LANDSCAPE.value())) {
return ScreenOrientation.LANDSCAPE;
} else if (orientation.equals(ScreenOrientation.PORTRAIT.value())) {
return ScreenOrientation.PORTRAIT;
} else {
throw new WebDriverException("Unexpected orientation returned: " + orientation);
}
}
示例12: execute
import org.openqa.selenium.remote.DriverCommand; //导入依赖的package包/类
@Override public Response execute(Command command) throws IOException, WebDriverException {
if (DriverCommand.NEW_SESSION.equals(command.getName()) && service != null) {
service.start();
}
try {
return super.execute(command);
} catch (Throwable t) {
Throwable rootCause = Throwables.getRootCause(t);
if (rootCause instanceof ConnectException
&& rootCause.getMessage().contains("Connection refused")
&& service != null) {
if (service.isRunning()) {
throw new WebDriverException("The session is closed!", t);
}
if (!service.isRunning()) {
throw new WebDriverException("The appium server has accidentally died!", t);
}
}
Throwables.propagateIfPossible(t);
throw new WebDriverException(t);
} finally {
if (DriverCommand.QUIT.equals(command.getName()) && service != null) {
service.stop();
}
}
}
示例13: execute
import org.openqa.selenium.remote.DriverCommand; //导入依赖的package包/类
@Override
protected Response execute(String driverCommand, Map<String, ?> parameters) {
if (driverCommand.equalsIgnoreCase(DriverCommand.QUIT)) {
return new Response();
}
return super.execute(driverCommand, parameters);
}
示例14: getScreenshotAs
import org.openqa.selenium.remote.DriverCommand; //导入依赖的package包/类
@Override
public <X> X getScreenshotAs(OutputType<X> target) throws WebDriverException {
Object takeScreenshot =
getCapabilities().getCapability(CapabilityType.TAKES_SCREENSHOT);
if (null == takeScreenshot || (Boolean) takeScreenshot) {
String base64Str = execute(DriverCommand.SCREENSHOT).getValue().toString();
return target.convertFromBase64Png(base64Str);
}
return null;
}
示例15: getScreenshotAs
import org.openqa.selenium.remote.DriverCommand; //导入依赖的package包/类
public <X> X getScreenshotAs(final OutputType<X> target) throws WebDriverException {
if ((Boolean) getCapabilities().getCapability(CapabilityType.TAKES_SCREENSHOT)) {
String output = execute(DriverCommand.SCREENSHOT).getValue().toString();
return target.convertFromBase64Png(output);
}
return null;
}