List of usage examples for org.openqa.selenium.remote Command getName
public String getName()
From source file:com.jobaline.uiautomation.framework.selenium.phantomJsThreeHourTimeoutFix.HttpCommandExecutor.java
License:Apache License
public Response execute(Command command) throws IOException { HttpContext context = new BasicHttpContext(); if (command.getSessionId() == null) { if (QUIT.equals(command.getName())) { return new Response(); }/* w w w .jav a 2s . c o m*/ if (!GET_ALL_SESSIONS.equals(command.getName()) && !NEW_SESSION.equals(command.getName())) { throw new SessionNotFoundException("Session ID is null. Using WebDriver after calling quit()?"); } } CommandInfo info = nameToUrl.get(command.getName()); try { HttpUriRequest httpMethod = info.getMethod(remoteServer, command); setAcceptHeader(httpMethod); if (httpMethod instanceof HttpPost) { String payload = new BeanToJsonConverter().convert(command.getParameters()); ((HttpPost) httpMethod).setEntity(new StringEntity(payload, "utf-8")); httpMethod.addHeader("Content-Type", "application/json; charset=utf-8"); } // Do not allow web proxy caches to cache responses to "get" commands if (httpMethod instanceof HttpGet) { httpMethod.addHeader("Cache-Control", "no-cache"); } log(LogType.PROFILER, new HttpProfilerLogEntry(command.getName(), true)); HttpResponse response = fallBackExecute(context, httpMethod); log(LogType.PROFILER, new HttpProfilerLogEntry(command.getName(), false)); response = followRedirects(client, context, response, /* redirect count */0); final EntityWithEncoding entityWithEncoding = new EntityWithEncoding(response.getEntity()); return createResponse(response, context, entityWithEncoding); } catch (UnsupportedCommandException e) { if (e.getMessage() == null || "".equals(e.getMessage())) { throw new UnsupportedOperationException( "No information from server. Command name was: " + command.getName(), e.getCause()); } throw e; } }
From source file:com.mengge.remote.AppiumCommandExecutor.java
License:Apache License
@Override public Response execute(Command command) throws IOException, WebDriverException { if (DriverCommand.NEW_SESSION.equals(command.getName()) && service != null) { service.start();//from w w w . j ava 2s .c o m } 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(); } } }
From source file:com.mycompany.myproject.sample.simple.DemoEventFiringListener.java
License:Apache License
public void beforeEvent(Command command) { if (command.getName().equalsIgnoreCase(DriverCommand.CLICK)) { System.out.println("Before click"); }//from w ww. j av a 2 s. c o m }
From source file:com.mycompany.myproject.sample.simple.DemoEventFiringListener.java
License:Apache License
public void afterEvent(Command command) { if (command.getName().equalsIgnoreCase(DriverCommand.CLICK)) { System.out.println("After click"); }//from w ww. j a v a 2 s . com }
From source file:io.appium.java_client.remote.AppiumCommandExecutor.java
License:Apache License
@Override public Response execute(Command command) throws IOException, WebDriverException { if (DriverCommand.NEW_SESSION.equals(command.getName()) && service != null) { service.start();// ww w .ja va 2s .co m } 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(); } } }
From source file:org.aludratest.service.gui.web.selenium.selenium2.AludraSeleniumHttpCommandExecutor.java
License:Apache License
@Override public Response execute(Command command) throws IOException { HttpContext context = new BasicHttpContext(); if (command.getSessionId() == null) { if (QUIT.equals(command.getName())) { return new Response(); }//from w w w . j a v a 2 s . co m if (!GET_ALL_SESSIONS.equals(command.getName()) && !NEW_SESSION.equals(command.getName())) { throw new SessionNotFoundException("Session ID is null. Using WebDriver after calling quit()?"); } } HttpRequest request = commandCodec.encode(command); String requestUrl = remoteServer.toExternalForm().replaceAll("/$", "") + request.getUri(); HttpUriRequest httpMethod = createHttpUriRequest(request.getMethod(), requestUrl); for (String name : request.getHeaderNames()) { // Skip content length as it is implicitly set when the message entity is set below. if (!"Content-Length".equalsIgnoreCase(name)) { for (String value : request.getHeaders(name)) { httpMethod.addHeader(name, value); } } } if (httpMethod instanceof HttpPost) { ((HttpPost) httpMethod).setEntity(new ByteArrayEntity(request.getContent())); } if (requestTimeout > 0 && (httpMethod instanceof HttpRequestBase)) { RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(15000) .setConnectTimeout(15000).setSocketTimeout(requestTimeout).build(); ((HttpRequestBase) httpMethod).setConfig(requestConfig); } else if (httpMethod instanceof HttpRequestBase) { // ensure Selenium Standard is set RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(60000) .setConnectTimeout(60000).setSocketTimeout(THREE_HOURS).build(); ((HttpRequestBase) httpMethod).setConfig(requestConfig); } try { log(LogType.PROFILER, new HttpProfilerLogEntry(command.getName(), true)); HttpResponse response = fallBackExecute(context, httpMethod); log(LogType.PROFILER, new HttpProfilerLogEntry(command.getName(), false)); lastResponse = response; response = followRedirects(client, context, response, /* redirect count */0); lastResponse = response; return createResponse(response, context); } catch (UnsupportedCommandException e) { if (e.getMessage() == null || "".equals(e.getMessage())) { throw new UnsupportedOperationException( "No information from server. Command name was: " + command.getName(), e.getCause()); } throw e; } catch (SocketTimeoutException e) { LoggerFactory.getLogger(AludraSeleniumHttpCommandExecutor.class) .warn("Timeout in HTTP Command Executor. Timeout was " + ((HttpRequestBase) httpMethod).getConfig().getSocketTimeout()); throw e; } }