Java 类org.openqa.selenium.remote.DriverCommand 实例源码
项目:xframium-java
文件:DeviceWebDriver.java
/**
* _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;
}
项目:qaf
文件:QAFExtendedWebDriver.java
@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();
}
项目:qaf
文件:QAFExtendedWebDriver.java
@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();
}
项目:talk2grid
文件:CustomCommandExecutor.java
@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;
}
项目:xframium-java
文件:DeviceWebDriver.java
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;
}
项目:xframium-java
文件:DeviceWebDriver.java
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;
}
项目:xframium-java
文件:BrowserCacheLogic.java
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);
}
项目:xframium-java
文件:BrowserCacheLogic.java
private static String getCurrentContextHandle(RemoteWebDriver driver)
{
RemoteExecuteMethod executeMethod = new RemoteExecuteMethod(driver);
String context = (String) executeMethod.execute(DriverCommand.GET_CURRENT_CONTEXT_HANDLE, null);
return context;
}
项目:menggeqa
文件:AppiumDriver.java
@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);
}
}
项目:menggeqa
文件:AppiumDriver.java
@Override public String getContext() {
String contextName =
String.valueOf(execute(DriverCommand.GET_CURRENT_CONTEXT_HANDLE).getValue());
if (contextName.equals("null")) {
return null;
}
return contextName;
}
项目:menggeqa
文件:AppiumDriver.java
@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);
}
}
项目:menggeqa
文件:AppiumCommandExecutor.java
@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();
}
}
}
项目:qaf
文件:LiveIsExtendedWebDriver.java
@Override
protected Response execute(String driverCommand, Map<String, ?> parameters) {
if (driverCommand.equalsIgnoreCase(DriverCommand.QUIT)) {
return new Response();
}
return super.execute(driverCommand, parameters);
}
项目:qaf
文件:QAFExtendedWebDriver.java
@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;
}
项目:seleniumtestsframework
文件:ScreenShotRemoteWebDriver.java
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;
}
项目:AndroidRobot
文件:ChromeDriverClient.java
public boolean tapById(String id) {
try{
Map<String, ?> params = ImmutableMap.of("element", ((RemoteWebElement)driver.findElement(By.id(id))).getId());
((RobotRemoteWebDriver)this.driver).execute(DriverCommand.TOUCH_SINGLE_TAP, params);
}catch(Exception ex) {
return false;
}
return true;
}
项目:AndroidRobot
文件:ChromeDriverClient.java
public boolean tapByXPath(String xpath) {
try {
Map<String, ?> params = ImmutableMap.of("element", ((RemoteWebElement)driver.findElement(By.xpath(xpath))).getId());
((RobotRemoteWebDriver)this.driver).execute(DriverCommand.TOUCH_SINGLE_TAP, params);
}catch(Exception ex) {
return false;
}
return true;
}
项目:AndroidRobot
文件:ChromeDriverClient.java
public boolean tap(By by) {
try {
Map<String, ?> params = ImmutableMap.of("element", ((RemoteWebElement)driver.findElement(by)).getId());
((RobotRemoteWebDriver)this.driver).execute(DriverCommand.TOUCH_SINGLE_TAP, params);
}catch(Exception ex) {
return false;
}
return true;
}
项目:selenium-lxc
文件:RemoteWebDriver.java
@Override
public <X> X getScreenshotAs(OutputType<X> target) throws WebDriverException {
try {
if ((Boolean) getCapabilities().getCapability(CapabilityType.TAKES_SCREENSHOT)) {
String base64Str = execute(DriverCommand.SCREENSHOT).getValue().toString();
return target.convertFromBase64Png(base64Str);
}
return null;
} catch (Exception e) {
return null;
}
}
项目:jspider
文件:WebDriverEx.java
public Response sendGet(String url) {
return execute(DriverCommand.GET, ImmutableMap.of("url", url));
}
项目:marathonv5
文件:JavaDriver.java
@Override public <X> X getScreenshotAs(OutputType<X> target) throws WebDriverException {
// Get the screenshot as base64.
String base64 = (String) execute(DriverCommand.SCREENSHOT).getValue();
// ... and convert it.
return target.convertFromBase64Png(base64);
}
项目:Quantum
文件:DeviceUtils.java
public static void switchToContext(String context) {
RemoteExecuteMethod executeMethod = new RemoteExecuteMethod(getQAFDriver());
Map<String, String> params = new HashMap<String, String>();
params.put("name", context);
executeMethod.execute(DriverCommand.SWITCH_TO_CONTEXT, params);
}
项目:Quantum
文件:DeviceUtils.java
/**
* @return the current context - "NATIVE_APP", "WEBVIEW", "VISUAL"
*/
public static String getCurrentContext() {
RemoteExecuteMethod executeMethod = new RemoteExecuteMethod(getQAFDriver());
return (String) executeMethod.execute(DriverCommand.GET_CURRENT_CONTEXT_HANDLE,
null);
}
项目:menggeqa
文件:AppiumDriver.java
@Override public WebDriver context(String name) {
checkNotNull(name, "Must supply a context name");
execute(DriverCommand.SWITCH_TO_CONTEXT, ImmutableMap.of("name", name));
return this;
}
项目:menggeqa
文件:AppiumDriver.java
@Override public void rotate(ScreenOrientation orientation) {
execute(DriverCommand.SET_SCREEN_ORIENTATION,
ImmutableMap.of("orientation", orientation.value().toUpperCase()));
}
项目:oscon-aus-2016
文件:DemoEventFiringListener.java
public void beforeEvent(Command command) {
if (command.getName().equalsIgnoreCase(DriverCommand.CLICK)) {
System.out.println("Before click");
}
}
项目:oscon-aus-2016
文件:DemoEventFiringListener.java
public void afterEvent(Command command) {
if (command.getName().equalsIgnoreCase(DriverCommand.CLICK)) {
System.out.println("After click");
}
}
项目:AppCenter-Test-Appium-Java-Extensions
文件:EnhancedIOSDriver.java
/**
* Get screenshot from device. Will store a copy of the screenshot in parent working directory and in test-cloud
* it will be inserted into test report.
* @param outputType output format of screenshot
* @param <X> output format of screenshot
* @return screenshot
* @throws WebDriverException if an error occurs
* @see #label(String) for the perfered way to insert screenshots in test reports.
*/
@Override
public <X> X getScreenshotAs(OutputType<X> outputType) throws WebDriverException {
Object value = execute(DriverCommand.SCREENSHOT).getValue();
return DriverHelper.getScreenshotToWorkspace(value, outputType, path ->
eventReporter.reportScreenshot(path.toAbsolutePath().toString(), 0, false));
}
项目:test-cloud-appium-java-extensions
文件:EnhancedIOSDriver.java
/**
* Get screenshot from device. Will store a copy of the screenshot in parent working directory and in test-cloud
* it will be inserted into test report.
* @param outputType output format of screenshot
* @param <X> output format of screenshot
* @return screenshot
* @throws WebDriverException if an error occurs
* @see #label(String) for the perfered way to insert screenshots in test reports.
*/
@Override
public <X> X getScreenshotAs(OutputType<X> outputType) throws WebDriverException {
Object value = execute(DriverCommand.SCREENSHOT).getValue();
return DriverHelper.getScreenshotToWorkspace(value, outputType, path ->
eventReporter.reportScreenshot(path.toAbsolutePath().toString(), 0, false));
}
项目:AppCenter-Test-Appium-Java-Extensions
文件:EnhancedAndroidDriver.java
/**
* Get screenshot from device. Will store a copy of the screenshot in parent working directory and in test-cloud
* it will be inserted into test report.
* @param outputType output format of screenshot
* @param <X> output format of screenshot
* @return screenshot
* @throws WebDriverException if an error occurs
* @see #label(String) for the perfered way to insert screenshots in test reports.
*/
@Override
public <X> X getScreenshotAs(OutputType<X> outputType) throws WebDriverException {
return DriverHelper.getScreenshotToWorkspace(execute(DriverCommand.SCREENSHOT).getValue(), outputType, path ->
eventReporter.reportScreenshot(path.toAbsolutePath().toString(), 0, false));
}
项目:test-cloud-appium-java-extensions
文件:EnhancedAndroidDriver.java
/**
* Get screenshot from device. Will store a copy of the screenshot in parent working directory and in test-cloud
* it will be inserted into test report.
* @param outputType output format of screenshot
* @param <X> output format of screenshot
* @return screenshot
* @throws WebDriverException if an error occurs
* @see #label(String) for the perfered way to insert screenshots in test reports.
*/
@Override
public <X> X getScreenshotAs(OutputType<X> outputType) throws WebDriverException {
return DriverHelper.getScreenshotToWorkspace(execute(DriverCommand.SCREENSHOT).getValue(), outputType, path ->
eventReporter.reportScreenshot(path.toAbsolutePath().toString(), 0, false));
}