/** * _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; }
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; }
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; }
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); }
private static String getCurrentContextHandle(RemoteWebDriver driver) { RemoteExecuteMethod executeMethod = new RemoteExecuteMethod(driver); String context = (String) executeMethod.execute(DriverCommand.GET_CURRENT_CONTEXT_HANDLE, null); return context; }
private SelendroidDriver(CommandExecutor executor, Capabilities caps) throws Exception { super(executor, caps); RemoteExecuteMethod executeMethod = new RemoteExecuteMethod(this); touchScreen = new RemoteTouchScreen(executeMethod); multiTouchScreen = new MultiTouchScreen(executeMethod); adbConnection = new RemoteAdbConnection(executeMethod); trackBall = new TrackBall(executeMethod); }
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); }
/** * @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); }