How to use Response class of org.openqa.selenium.remote package

Best Selenium code snippet using org.openqa.selenium.remote.Response

Source:JsonHttpCommandHandler.java Github

copy

Full Screen

...19import org.openqa.selenium.UnsupportedCommandException;20import org.openqa.selenium.remote.Command;21import org.openqa.selenium.remote.CommandCodec;22import org.openqa.selenium.remote.ErrorCodes;23import org.openqa.selenium.remote.Response;24import org.openqa.selenium.remote.ResponseCodec;25import org.openqa.selenium.remote.SessionId;26import org.openqa.selenium.remote.http.HttpRequest;27import org.openqa.selenium.remote.http.HttpResponse;28import org.openqa.selenium.remote.http.JsonHttpCommandCodec;29import org.openqa.selenium.remote.http.JsonHttpResponseCodec;30import org.openqa.selenium.remote.http.W3CHttpCommandCodec;31import org.openqa.selenium.remote.server.handler.AcceptAlert;32import org.openqa.selenium.remote.server.handler.AddCookie;33import org.openqa.selenium.remote.server.handler.CaptureScreenshot;34import org.openqa.selenium.remote.server.handler.ChangeUrl;35import org.openqa.selenium.remote.server.handler.ClearElement;36import org.openqa.selenium.remote.server.handler.ClickElement;37import org.openqa.selenium.remote.server.handler.CloseWindow;38import org.openqa.selenium.remote.server.handler.ConfigureTimeout;39import org.openqa.selenium.remote.server.handler.DeleteCookie;40import org.openqa.selenium.remote.server.handler.DeleteNamedCookie;41import org.openqa.selenium.remote.server.handler.DeleteSession;42import org.openqa.selenium.remote.server.handler.DismissAlert;43import org.openqa.selenium.remote.server.handler.ElementEquality;44import org.openqa.selenium.remote.server.handler.ExecuteAsyncScript;45import org.openqa.selenium.remote.server.handler.ExecuteScript;46import org.openqa.selenium.remote.server.handler.FindActiveElement;47import org.openqa.selenium.remote.server.handler.FindChildElement;48import org.openqa.selenium.remote.server.handler.FindChildElements;49import org.openqa.selenium.remote.server.handler.FindElement;50import org.openqa.selenium.remote.server.handler.FindElements;51import org.openqa.selenium.remote.server.handler.FullscreenWindow;52import org.openqa.selenium.remote.server.handler.GetAlertText;53import org.openqa.selenium.remote.server.handler.GetAllCookies;54import org.openqa.selenium.remote.server.handler.GetAllSessions;55import org.openqa.selenium.remote.server.handler.GetAllWindowHandles;56import org.openqa.selenium.remote.server.handler.GetAvailableLogTypesHandler;57import org.openqa.selenium.remote.server.handler.GetCookie;58import org.openqa.selenium.remote.server.handler.GetCssProperty;59import org.openqa.selenium.remote.server.handler.GetCurrentUrl;60import org.openqa.selenium.remote.server.handler.GetCurrentWindowHandle;61import org.openqa.selenium.remote.server.handler.GetElementAttribute;62import org.openqa.selenium.remote.server.handler.GetElementDisplayed;63import org.openqa.selenium.remote.server.handler.GetElementEnabled;64import org.openqa.selenium.remote.server.handler.GetElementLocation;65import org.openqa.selenium.remote.server.handler.GetElementLocationInView;66import org.openqa.selenium.remote.server.handler.GetElementRect;67import org.openqa.selenium.remote.server.handler.GetElementSelected;68import org.openqa.selenium.remote.server.handler.GetElementSize;69import org.openqa.selenium.remote.server.handler.GetElementText;70import org.openqa.selenium.remote.server.handler.GetLogHandler;71import org.openqa.selenium.remote.server.handler.GetPageSource;72import org.openqa.selenium.remote.server.handler.GetScreenOrientation;73import org.openqa.selenium.remote.server.handler.GetSessionCapabilities;74import org.openqa.selenium.remote.server.handler.GetSessionLogsHandler;75import org.openqa.selenium.remote.server.handler.GetTagName;76import org.openqa.selenium.remote.server.handler.GetTitle;77import org.openqa.selenium.remote.server.handler.GetWindowPosition;78import org.openqa.selenium.remote.server.handler.GetWindowSize;79import org.openqa.selenium.remote.server.handler.GoBack;80import org.openqa.selenium.remote.server.handler.GoForward;81import org.openqa.selenium.remote.server.handler.ImeActivateEngine;82import org.openqa.selenium.remote.server.handler.ImeDeactivate;83import org.openqa.selenium.remote.server.handler.ImeGetActiveEngine;84import org.openqa.selenium.remote.server.handler.ImeGetAvailableEngines;85import org.openqa.selenium.remote.server.handler.ImeIsActivated;86import org.openqa.selenium.remote.server.handler.ImplicitlyWait;87import org.openqa.selenium.remote.server.handler.MaximizeWindow;88import org.openqa.selenium.remote.server.handler.RefreshPage;89import org.openqa.selenium.remote.server.handler.Rotate;90import org.openqa.selenium.remote.server.handler.SendKeys;91import org.openqa.selenium.remote.server.handler.SetAlertText;92import org.openqa.selenium.remote.server.handler.SetScriptTimeout;93import org.openqa.selenium.remote.server.handler.SetWindowPosition;94import org.openqa.selenium.remote.server.handler.SetWindowSize;95import org.openqa.selenium.remote.server.handler.Status;96import org.openqa.selenium.remote.server.handler.SubmitElement;97import org.openqa.selenium.remote.server.handler.SwitchToFrame;98import org.openqa.selenium.remote.server.handler.SwitchToParentFrame;99import org.openqa.selenium.remote.server.handler.SwitchToWindow;100import org.openqa.selenium.remote.server.handler.UploadFile;101import org.openqa.selenium.remote.server.handler.W3CActions;102import org.openqa.selenium.remote.server.handler.html5.ClearLocalStorage;103import org.openqa.selenium.remote.server.handler.html5.ClearSessionStorage;104import org.openqa.selenium.remote.server.handler.html5.GetAppCacheStatus;105import org.openqa.selenium.remote.server.handler.html5.GetLocalStorageItem;106import org.openqa.selenium.remote.server.handler.html5.GetLocalStorageKeys;107import org.openqa.selenium.remote.server.handler.html5.GetLocalStorageSize;108import org.openqa.selenium.remote.server.handler.html5.GetLocationContext;109import org.openqa.selenium.remote.server.handler.html5.GetSessionStorageItem;110import org.openqa.selenium.remote.server.handler.html5.GetSessionStorageKeys;111import org.openqa.selenium.remote.server.handler.html5.GetSessionStorageSize;112import org.openqa.selenium.remote.server.handler.html5.RemoveLocalStorageItem;113import org.openqa.selenium.remote.server.handler.html5.RemoveSessionStorageItem;114import org.openqa.selenium.remote.server.handler.html5.SetLocalStorageItem;115import org.openqa.selenium.remote.server.handler.html5.SetLocationContext;116import org.openqa.selenium.remote.server.handler.html5.SetSessionStorageItem;117import org.openqa.selenium.remote.server.handler.interactions.ClickInSession;118import org.openqa.selenium.remote.server.handler.interactions.DoubleClickInSession;119import org.openqa.selenium.remote.server.handler.interactions.MouseDown;120import org.openqa.selenium.remote.server.handler.interactions.MouseMoveToLocation;121import org.openqa.selenium.remote.server.handler.interactions.MouseUp;122import org.openqa.selenium.remote.server.handler.interactions.SendKeyToActiveElement;123import org.openqa.selenium.remote.server.handler.interactions.touch.DoubleTapOnElement;124import org.openqa.selenium.remote.server.handler.interactions.touch.Down;125import org.openqa.selenium.remote.server.handler.interactions.touch.Flick;126import org.openqa.selenium.remote.server.handler.interactions.touch.LongPressOnElement;127import org.openqa.selenium.remote.server.handler.interactions.touch.Move;128import org.openqa.selenium.remote.server.handler.interactions.touch.Scroll;129import org.openqa.selenium.remote.server.handler.interactions.touch.SingleTapOnElement;130import org.openqa.selenium.remote.server.handler.interactions.touch.Up;131import org.openqa.selenium.remote.server.handler.mobile.GetNetworkConnection;132import org.openqa.selenium.remote.server.handler.mobile.SetNetworkConnection;133import org.openqa.selenium.remote.server.log.LoggingManager;134import org.openqa.selenium.remote.server.log.PerSessionLogHandler;135import org.openqa.selenium.remote.server.rest.RestishHandler;136import org.openqa.selenium.remote.server.rest.ResultConfig;137import java.io.IOException;138import java.util.LinkedHashMap;139import java.util.LinkedHashSet;140import java.util.Map;141import java.util.Set;142import java.util.logging.Logger;143public class JsonHttpCommandHandler {144 private final DriverSessions sessions;145 private final Logger log;146 private final Set<CommandCodec<HttpRequest>> commandCodecs;147 private final ResponseCodec<HttpResponse> responseCodec;148 private final Map<String, ResultConfig> configs = new LinkedHashMap<>();149 private final ErrorCodes errorCodes = new ErrorCodes();150 public JsonHttpCommandHandler(DriverSessions sessions, Logger log) {151 this.sessions = sessions;152 this.log = log;153 this.commandCodecs = new LinkedHashSet<>();154 this.commandCodecs.add(new JsonHttpCommandCodec());155 this.commandCodecs.add(new W3CHttpCommandCodec());156 this.responseCodec = new JsonHttpResponseCodec();157 setUpMappings();158 }159 public void addNewMapping(160 String commandName,161 Class<? extends RestishHandler<?>> implementationClass) {162 ResultConfig config = new ResultConfig(commandName, implementationClass, sessions, log);163 configs.put(commandName, config);164 }165 public void handleRequest(HttpRequest request, HttpResponse resp) throws IOException {166 LoggingManager.perSessionLogHandler().clearThreadTempLogs();167 log.fine(String.format("Handling: %s %s", request.getMethod(), request.getUri()));168 Command command = null;169 Response response;170 try {171 command = decode(request);172 ResultConfig config = configs.get(command.getName());173 if (config == null) {174 throw new UnsupportedCommandException();175 }176 response = config.handle(command);177 log.fine(String.format("Finished: %s %s", request.getMethod(), request.getUri()));178 } catch (Exception e) {179 log.fine(String.format("Error on: %s %s", request.getMethod(), request.getUri()));180 response = new Response();181 response.setStatus(errorCodes.toStatusCode(e));182 response.setState(errorCodes.toState(response.getStatus()));183 response.setValue(e);184 if (command != null && command.getSessionId() != null) {185 response.setSessionId(command.getSessionId().toString());186 }187 }188 PerSessionLogHandler handler = LoggingManager.perSessionLogHandler();189 if (response.getSessionId() != null) {190 handler.attachToCurrentThread(new SessionId(response.getSessionId()));191 }192 try {193 responseCodec.encode(() -> resp, response);194 } finally {...

Full Screen

Full Screen

Source:CommandHandler.java Github

copy

Full Screen

1package ru.stqa.selenium.zkgrid.node;2import org.openqa.selenium.UnsupportedCommandException;3import org.openqa.selenium.remote.Command;4import org.openqa.selenium.remote.ErrorCodes;5import org.openqa.selenium.remote.Response;6import shaded.org.openqa.selenium.remote.server.DriverSessions;7import shaded.org.openqa.selenium.remote.server.rest.RestishHandler;8import shaded.org.openqa.selenium.remote.server.rest.ResultConfig;9import org.slf4j.Logger;10import org.slf4j.LoggerFactory;11import java.util.HashMap;12import java.util.Map;13import static org.openqa.selenium.remote.DriverCommand.*;14public class CommandHandler {15 private static Logger log = LoggerFactory.getLogger(Node.class);16 private final DriverSessions sessions;17 private final Map<String, ResultConfig> configs = new HashMap<String, ResultConfig>();18 private final ErrorCodes errorCodes = new ErrorCodes();19 public CommandHandler(DriverSessions sessions) {20 this.sessions = sessions;21 setUpMappings();22 }23 public Response handleCommand(Command command) {24 log.info("Handling command " + command);25 Response response;26 try {27 ResultConfig config = configs.get(command.getName());28 if (config == null) {29 throw new UnsupportedCommandException();30 }31 response = config.handle(command);32 log.info("Finished " + command);33 } catch (Exception e) {34 log.info(String.format("Error on " + command));35 e.printStackTrace();36 response = new Response();37 response.setStatus(errorCodes.toStatusCode(e));38 response.setState(errorCodes.toState(response.getStatus()));39 response.setValue(e);40 if (command != null && command.getSessionId() != null) {41 response.setSessionId(command.getSessionId().toString());42 }43 }44 return response;45 }46 public void addNewMapping(String commandName, Class<? extends RestishHandler<?>> implementationClass) {47 ResultConfig config = new ResultConfig(commandName, implementationClass, sessions, java.util.logging.Logger.getAnonymousLogger());48 configs.put(commandName, config);49 }50 private void setUpMappings() {...

Full Screen

Full Screen

Source:SeleneseCommandExecutor.java Github

copy

Full Screen

...79import org.openqa.selenium.remote.CommandExecutor;80import org.openqa.selenium.remote.DesiredCapabilities;81import org.openqa.selenium.remote.ErrorCodes;82import org.openqa.selenium.remote.JsonToBeanConverter;83import org.openqa.selenium.remote.Response;84import java.io.File;85import java.net.URL;86import java.util.Map;87public class SeleneseCommandExecutor implements CommandExecutor {88 private final ErrorCodes errorCodes;89 private final Selenium instance;90 private Map<String, SeleneseFunction<?>> functions = Maps.newHashMap();91 public SeleneseCommandExecutor(URL seleniumServer, URL remoteAddress, Capabilities capabilities) {92 this(new HttpCommandProcessor(93 seleniumServer.getHost(), seleniumServer.getPort(),94 startCommand(capabilities), remoteAddress.toString()));95 }96 public SeleneseCommandExecutor(CommandProcessor processor) {97 this(new DefaultSelenium(processor));98 }99 public SeleneseCommandExecutor(Selenium instance) {100 this.instance = instance;101 errorCodes = new ErrorCodes();102 prepareCommands();103 }104 public Selenium getWrappedSelenium() {105 return instance;106 }107 public Response execute(Command command) {108 SeleneseFunction<?> function = functions.get(command.getName());109 if (function == null) {110 throw new UnsupportedOperationException("cannot execute: " + command.getName());111 }112 try {113 Response response = new Response();114 response.setValue(function.apply(instance, command.getParameters()));115 return response;116 } catch (Exception e) {117 return prepareExceptionResponse(e);118 }119 }120 private Response prepareExceptionResponse(Exception e) {121 Response response = new Response();122 Exception toUse = e;123 if (e instanceof SeleniumException) {124 // World of fragility. *sigh*125 if (e.getMessage().matches("ERROR: (Threw an exception: )?Element .+ not found")) {126 toUse = new StaleElementReferenceException(e.getMessage(), e);127 }128 }129 response.setStatus(errorCodes.toStatusCode(toUse));130 // It's like a lesson in inefficiency131 Object raw =132 new JsonToBeanConverter().convert(Map.class, new BeanToJsonConverter().convert(toUse));133 response.setValue(raw);134 return response;135 }...

Full Screen

Full Screen

Source:ProtocolConverter.java Github

copy

Full Screen

...25import org.openqa.selenium.remote.CommandCodec;26import org.openqa.selenium.remote.Dialect;27import org.openqa.selenium.remote.DriverCommand;28import org.openqa.selenium.remote.JsonToWebElementConverter;29import org.openqa.selenium.remote.Response;30import org.openqa.selenium.remote.ResponseCodec;31import org.openqa.selenium.remote.SessionId;32import org.openqa.selenium.remote.codec.jwp.JsonHttpCommandCodec;33import org.openqa.selenium.remote.codec.jwp.JsonHttpResponseCodec;34import org.openqa.selenium.remote.codec.w3c.W3CHttpCommandCodec;35import org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec;36import org.openqa.selenium.remote.http.HttpClient;37import org.openqa.selenium.remote.http.HttpHandler;38import org.openqa.selenium.remote.http.HttpRequest;39import org.openqa.selenium.remote.http.HttpResponse;40import org.openqa.selenium.remote.tracing.AttributeKey;41import org.openqa.selenium.remote.tracing.EventAttribute;42import org.openqa.selenium.remote.tracing.EventAttributeValue;43import org.openqa.selenium.remote.tracing.HttpTracing;44import org.openqa.selenium.remote.tracing.Span;45import org.openqa.selenium.remote.tracing.Status;46import org.openqa.selenium.remote.tracing.Tracer;47import java.io.UncheckedIOException;48import java.util.HashMap;49import java.util.Map;50import java.util.Objects;51import java.util.function.Function;52import static java.net.HttpURLConnection.HTTP_OK;53import static java.nio.charset.StandardCharsets.UTF_8;54import static org.openqa.selenium.json.Json.MAP_TYPE;55import static org.openqa.selenium.remote.Dialect.W3C;56import static org.openqa.selenium.remote.RemoteTags.SESSION_ID;57import static org.openqa.selenium.remote.RemoteTags.SESSION_ID_EVENT;58import static org.openqa.selenium.remote.http.Contents.bytes;59import static org.openqa.selenium.remote.http.Contents.string;60import static org.openqa.selenium.remote.tracing.HttpTracing.newSpanAsChildOf;61import static org.openqa.selenium.remote.tracing.Tags.HTTP_REQUEST;62import static org.openqa.selenium.remote.tracing.Tags.HTTP_REQUEST_EVENT;63import static org.openqa.selenium.remote.tracing.Tags.HTTP_RESPONSE;64import static org.openqa.selenium.remote.tracing.Tags.HTTP_RESPONSE_EVENT;65import static org.openqa.selenium.remote.tracing.Tags.KIND;66public class ProtocolConverter implements HttpHandler {67 private static final Json JSON = new Json();68 private static final ImmutableSet<String> IGNORED_REQ_HEADERS = ImmutableSet.<String>builder()69 .add("connection")70 .add("content-length")71 .add("content-type")72 .add("keep-alive")73 .add("proxy-authorization")74 .add("proxy-authenticate")75 .add("proxy-connection")76 .add("te")77 .add("trailer")78 .add("transfer-encoding")79 .add("upgrade")80 .build();81 private final Tracer tracer;82 private final HttpClient client;83 private final CommandCodec<HttpRequest> downstream;84 private final CommandCodec<HttpRequest> upstream;85 private final ResponseCodec<HttpResponse> downstreamResponse;86 private final ResponseCodec<HttpResponse> upstreamResponse;87 private final JsonToWebElementConverter converter;88 private final Function<HttpResponse, HttpResponse> newSessionConverter;89 public ProtocolConverter(90 Tracer tracer,91 HttpClient client,92 Dialect downstream,93 Dialect upstream) {94 this.tracer = Require.nonNull("Tracer", tracer);95 this.client = Require.nonNull("HTTP client", client);96 this.downstream = getCommandCodec(Require.nonNull("Downstream dialect", downstream));97 this.downstreamResponse = getResponseCodec(downstream);98 this.upstream = getCommandCodec(Require.nonNull("Upstream dialect", upstream));99 this.upstreamResponse = getResponseCodec(upstream);100 converter = new JsonToWebElementConverter(null);101 newSessionConverter = downstream == W3C ? this::createW3CNewSessionResponse : this::createJwpNewSessionResponse;102 }103 @Override104 public HttpResponse execute(HttpRequest req) throws UncheckedIOException {105 try (Span span = newSpanAsChildOf(tracer, req, "protocol_converter")) {106 Map<String, EventAttributeValue> attributeMap = new HashMap<>();107 attributeMap.put(AttributeKey.HTTP_HANDLER_CLASS.getKey(),108 EventAttribute.setValue(getClass().getName()));109 Command command = downstream.decode(req);110 KIND.accept(span, Span.Kind.SERVER);111 HTTP_REQUEST.accept(span, req);112 HTTP_REQUEST_EVENT.accept(attributeMap, req);113 SessionId sessionId = command.getSessionId();114 SESSION_ID.accept(span, sessionId);115 SESSION_ID_EVENT.accept(attributeMap, sessionId);116 String commandName = command.getName();117 span.setAttribute("command.name", commandName);118 attributeMap.put("command.name", EventAttribute.setValue(commandName));119 attributeMap.put("downstream.command.parameters", EventAttribute.setValue(command.getParameters().toString()));120 // Massage the webelements121 @SuppressWarnings("unchecked")122 Map<String, ?> parameters = (Map<String, ?>) converter.apply(command.getParameters());123 command = new Command(124 command.getSessionId(),125 command.getName(),126 parameters);127 attributeMap.put("upstream.command.parameters", EventAttribute.setValue(command.getParameters().toString()));128 HttpRequest request = upstream.encode(command);129 HttpTracing.inject(tracer, span, request);130 HttpResponse res = makeRequest(request);131 if(!res.isSuccessful()) {132 span.setAttribute("error", true);133 span.setStatus(Status.UNKNOWN);134 }135 HTTP_RESPONSE.accept(span, res);136 HTTP_RESPONSE_EVENT.accept(attributeMap, res);137 HttpResponse toReturn;138 if (DriverCommand.NEW_SESSION.equals(command.getName()) && res.getStatus() == HTTP_OK) {139 toReturn = newSessionConverter.apply(res);140 } else {141 Response decoded = upstreamResponse.decode(res);142 toReturn = downstreamResponse.encode(HttpResponse::new, decoded);143 }144 res.getHeaderNames().forEach(name -> {145 if (!IGNORED_REQ_HEADERS.contains(name)) {146 res.getHeaders(name).forEach(value -> toReturn.addHeader(name, value));147 }148 });149 span.addEvent("Protocol conversion completed", attributeMap);150 return toReturn;151 }152 }153 @VisibleForTesting154 HttpResponse makeRequest(HttpRequest request) {155 return client.execute(request);156 }157 private CommandCodec<HttpRequest> getCommandCodec(Dialect dialect) {158 switch (dialect) {159 case OSS:160 return new JsonHttpCommandCodec();161 case W3C:162 return new W3CHttpCommandCodec();163 default:164 throw new IllegalStateException("Unknown dialect: " + dialect);165 }166 }167 private ResponseCodec<HttpResponse> getResponseCodec(Dialect dialect) {168 switch (dialect) {169 case OSS:170 return new JsonHttpResponseCodec();171 case W3C:172 return new W3CHttpResponseCodec();173 default:174 throw new IllegalStateException("Unknown dialect: " + dialect);175 }176 }177 private HttpResponse createW3CNewSessionResponse(HttpResponse response) {178 Map<String, Object> value = JSON.toType(string(response), MAP_TYPE);179 Require.state("Session id", value.get("sessionId")).nonNull();180 Require.state("Response payload", value.get("value")).instanceOf(Map.class);181 return createResponse(ImmutableMap.of(182 "value", ImmutableMap.of(183 "sessionId", value.get("sessionId"),184 "capabilities", value.get("value"))));185 }186 private HttpResponse createJwpNewSessionResponse(HttpResponse response) {187 Map<String, Object> value = Objects.requireNonNull(Values.get(response, MAP_TYPE));188 // Check to see if the values we need are set189 Require.state("Session id", value.get("sessionId")).nonNull();190 Require.state("Response payload", value.get("capabilities")).instanceOf(Map.class);191 return createResponse(ImmutableMap.of(192 "status", 0,193 "sessionId", value.get("sessionId"),194 "value", value.get("capabilities")));195 }196 private HttpResponse createResponse(ImmutableMap<String, Object> toSend) {197 byte[] bytes = JSON.toJson(toSend).getBytes(UTF_8);198 return new HttpResponse()199 .setHeader("Content-Type", MediaType.JSON_UTF_8.toString())200 .setHeader("Content-Length", String.valueOf(bytes.length))201 .setContent(bytes(bytes));202 }203}...

Full Screen

Full Screen

Source:RemoteSession.java Github

copy

Full Screen

...30import org.openqa.selenium.remote.Dialect;31import org.openqa.selenium.remote.DriverCommand;32import org.openqa.selenium.remote.ProtocolHandshake;33import org.openqa.selenium.remote.RemoteWebDriver;34import org.openqa.selenium.remote.Response;35import org.openqa.selenium.remote.ResponseCodec;36import org.openqa.selenium.remote.SessionId;37import org.openqa.selenium.remote.http.HttpClient;38import org.openqa.selenium.remote.http.HttpRequest;39import org.openqa.selenium.remote.http.HttpResponse;40import org.openqa.selenium.remote.http.JsonHttpCommandCodec;41import org.openqa.selenium.remote.http.JsonHttpResponseCodec;42import org.openqa.selenium.remote.http.W3CHttpCommandCodec;43import org.openqa.selenium.remote.http.W3CHttpResponseCodec;44import java.io.File;45import java.io.IOException;46import java.net.URL;47import java.util.Map;48import java.util.Optional;49import java.util.Set;50import java.util.logging.Level;51import java.util.logging.Logger;52/**53 * Abstract class designed to do things like protocol conversion.54 */55public abstract class RemoteSession implements ActiveSession {56 protected static Logger log = Logger.getLogger(ActiveSession.class.getName());57 private final SessionId id;58 private final Dialect downstream;59 private final Dialect upstream;60 private final SessionCodec codec;61 private final Map<String, Object> capabilities;62 private final TemporaryFilesystem filesystem;63 private final WebDriver driver;64 protected RemoteSession(65 Dialect downstream,66 Dialect upstream,67 SessionCodec codec,68 SessionId id,69 Map<String, Object> capabilities) {70 this.downstream = downstream;71 this.upstream = upstream;72 this.codec = codec;73 this.id = id;74 this.capabilities = capabilities;75 File tempRoot = new File(StandardSystemProperty.JAVA_IO_TMPDIR.value(), id.toString());76 Preconditions.checkState(tempRoot.mkdirs());77 this.filesystem = TemporaryFilesystem.getTmpFsBasedOn(tempRoot);78 CommandExecutor executor = new ActiveSessionCommandExecutor(this);79 this.driver = new Augmenter().augment(new RemoteWebDriver(80 executor,81 new ImmutableCapabilities(getCapabilities())));82 }83 @Override84 public SessionId getId() {85 return id;86 }87 @Override88 public Dialect getUpstreamDialect() {89 return upstream;90 }91 @Override92 public Dialect getDownstreamDialect() {93 return downstream;94 }95 @Override96 public Map<String, Object> getCapabilities() {97 return capabilities;98 }99 @Override100 public TemporaryFilesystem getFileSystem() {101 return filesystem;102 }103 @Override104 public WebDriver getWrappedDriver() {105 return driver;106 }107 @Override108 public void execute(HttpRequest req, HttpResponse resp) throws IOException {109 codec.handle(req, resp);110 }111 public abstract static class Factory<X> implements SessionFactory {112 protected Optional<ActiveSession> performHandshake(113 X additionalData,114 URL url,115 Set<Dialect> downstreamDialects,116 Capabilities capabilities) {117 try {118 HttpClient client = HttpClient.Factory.createDefault().createClient(url);119 Command command = new Command(120 null,121 DriverCommand.NEW_SESSION,122 ImmutableMap.of("desiredCapabilities", capabilities));123 ProtocolHandshake.Result result = new ProtocolHandshake().createSession(client, command);124 SessionCodec codec;125 Dialect upstream = result.getDialect();126 Dialect downstream;127 if (downstreamDialects.contains(result.getDialect())) {128 codec = new Passthrough(url);129 downstream = upstream;130 } else {131 downstream = downstreamDialects.isEmpty() ? OSS : downstreamDialects.iterator().next();132 codec = new ProtocolConverter(133 url,134 getCommandCodec(downstream),135 getResponseCodec(downstream),136 getCommandCodec(upstream),137 getResponseCodec(upstream));138 }139 Response response = result.createResponse();140 //noinspection unchecked141 Optional<ActiveSession> activeSession = Optional.of(newActiveSession(142 additionalData,143 downstream,144 upstream,145 codec,146 new SessionId(response.getSessionId()),147 (Map<String, Object>) response.getValue()));148 activeSession.ifPresent(session -> log.info("Started new session " + session));149 return activeSession;150 } catch (IOException | IllegalStateException | NullPointerException e) {151 log.log(Level.WARNING, e.getMessage(), e);152 return Optional.empty();153 }154 }155 protected abstract ActiveSession newActiveSession(156 X additionalData,157 Dialect downstream,158 Dialect upstream,159 SessionCodec codec,160 SessionId id,161 Map<String, Object> capabilities);162 private CommandCodec<HttpRequest> getCommandCodec(Dialect dialect) {163 switch (dialect) {164 case OSS:165 return new JsonHttpCommandCodec();166 case W3C:167 return new W3CHttpCommandCodec();168 default:169 throw new IllegalStateException("Unknown dialect: " + dialect);170 }171 }172 private ResponseCodec<HttpResponse> getResponseCodec(Dialect dialect) {173 switch (dialect) {174 case OSS:175 return new JsonHttpResponseCodec();176 case W3C:177 return new W3CHttpResponseCodec();178 default:179 throw new IllegalStateException("Unknown dialect: " + dialect);180 }181 }182 }183}...

Full Screen

Full Screen

Source:NewSession.java Github

copy

Full Screen

...3import java.util.Map;4import org.openqa.selenium.Capabilities;5import org.openqa.selenium.logging.LoggingPreferences;6import org.openqa.selenium.remote.DesiredCapabilities;7import org.openqa.selenium.remote.Response;8import org.openqa.selenium.remote.SessionId;9import org.openqa.selenium.remote.server.DriverSessions;10import org.openqa.selenium.remote.server.JsonParametersAware;11import org.openqa.selenium.remote.server.Session;12import org.openqa.selenium.remote.server.log.LoggingManager;13import org.openqa.selenium.remote.server.log.PerSessionLogHandler;14import org.openqa.selenium.remote.server.rest.RestishHandler;15public class NewSession16 implements RestishHandler<Response>, JsonParametersAware17{18 private volatile DriverSessions allSessions;19 private volatile Capabilities desiredCapabilities;20 private volatile SessionId sessionId;21 22 public NewSession(DriverSessions allSession)23 {24 allSessions = allSession;25 }26 27 public Capabilities getCapabilities() {28 return desiredCapabilities;29 }30 31 public void setJsonParameters(Map<String, Object> allParameters)32 throws Exception33 {34 desiredCapabilities = new DesiredCapabilities((Map)allParameters.get("desiredCapabilities"));35 }36 37 public Response handle()38 throws Exception39 {40 sessionId = allSessions.newSession(desiredCapabilities != null ? desiredCapabilities : new DesiredCapabilities());41 42 Map<String, Object> capabilities = Maps.newHashMap(allSessions.get(sessionId).getCapabilities().asMap());43 44 capabilities.put("webdriver.remote.sessionid", sessionId.toString());45 46 if (desiredCapabilities != null) {47 LoggingManager.perSessionLogHandler().configureLogging(48 (LoggingPreferences)desiredCapabilities.getCapability("loggingPrefs"));49 }50 LoggingManager.perSessionLogHandler().attachToCurrentThread(sessionId);51 52 Response response = new Response();53 response.setSessionId(sessionId.toString());54 response.setValue(capabilities);55 56 response.setStatus(Integer.valueOf(0));57 return response;58 }59 60 public String getSessionId() {61 return sessionId.toString();62 }63 64 public String toString()65 {66 return String.format("[new session: %s]", new Object[] { desiredCapabilities });...

Full Screen

Full Screen

Source:W3CActions.java Github

copy

Full Screen

...19import org.openqa.selenium.remote.Command;20import org.openqa.selenium.remote.CommandExecutor;21import org.openqa.selenium.remote.ErrorHandler;22import org.openqa.selenium.remote.RemoteWebDriver;23import org.openqa.selenium.remote.Response;24import org.openqa.selenium.remote.server.JsonParametersAware;25import org.openqa.selenium.remote.server.Session;26import java.util.Map;27public class W3CActions extends WebDriverHandler<Void> implements JsonParametersAware {28 private Map<String, Object> allParameters;29 public W3CActions(Session session) {30 super(session);31 }32 @Override33 public void setJsonParameters(Map<String, Object> allParameters) throws Exception {34 this.allParameters = allParameters;35 }36 @Override37 public Void call() throws Exception {38 RemoteWebDriver driver = (RemoteWebDriver) getUnwrappedDriver();39 CommandExecutor executor = (driver).getCommandExecutor();40 long start = System.currentTimeMillis();41 Command command = new Command(driver.getSessionId(), ACTIONS, allParameters);42 Response response = executor.execute(command);43 new ErrorHandler(true)44 .throwIfResponseFailed(response, System.currentTimeMillis() - start);45 return null;46 }47}...

Full Screen

Full Screen

Source:Dialect.java Github

copy

Full Screen

1package org.openqa.selenium.remote;2import org.openqa.selenium.remote.http.HttpRequest;3import org.openqa.selenium.remote.http.HttpResponse;4import org.openqa.selenium.remote.http.JsonHttpCommandCodec;5import org.openqa.selenium.remote.http.JsonHttpResponseCodec;6import org.openqa.selenium.remote.http.W3CHttpCommandCodec;7import org.openqa.selenium.remote.http.W3CHttpResponseCodec;8public enum Dialect9{10 OSS, W3C;11 12 private Dialect() {}13 14 public abstract CommandCodec<HttpRequest> getCommandCodec();15 16 public abstract ResponseCodec<HttpResponse> getResponseCodec();17 18 public abstract String getEncodedElementKey();19}...

Full Screen

Full Screen

Response

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.remote.Response;2import org.openqa.selenium.remote.DesiredCapabilities;3import org.openqa.selenium.remote.RemoteWebDriver;4import java.net.URL;5import java.io.IOException;6import java.io.File;7import java.io.FileInputStream;8import java.io.FileOutputStream;9import java.util.zip.ZipOutputStream;10import java.util.zip.ZipEntry;11import java.io.IOException;12import java.io.File;13import java.io.FileInputStream;14import java.io.FileOutputStream;15import java.util.zip.ZipOutputStream;16import java.util.zip.ZipEntry;17import java.io.IOException;18import java.io.File;19import java.io.FileInputStream;20import java.io.FileOutputStream;21import java.util.zip.ZipOutputStream;22import java.util.zip.ZipEntry;23import java.io.IOException;24import java.io.File;25import java.io.FileInputStream;26import java.io.FileOutputStream;27import java.util.zip.ZipOutputStream;28import java.util.zip.ZipEntry;29import java.io

Full Screen

Full Screen

Response

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.remote.Response;2import org.openqa.selenium.remote.DesiredCapabilities;3import org.openqa.selenium.remote.RemoteWebDriver;4import java.net.URL;5import java.io.IOException;6import java.io.File;7import java.io.FileInputStream;8import java.util.Properties;9import org.openqa.selenium.By;10import org.openqa.selenium.WebElement;11import org.openqa.selenium.support.ui.WebDriverWait;12import org.openqa.selenium.support.ui.ExpectedConditions;13import java.util.concurrent.TimeUnit;14import org.openqa.selenium.Alert;15import org.openqa.selenium.interactions.Actions;16public class Sample {17 public static void main(String[] args) throws IOException {18 Properties prop = new Properties();19 File file = new File("C:\\Users\\username\\Desktop\\config.properties");20 FileInputStream fileInput = new FileInputStream(file);21 prop.load(fileInput);22 System.out.println(prop.getProperty("browser"));23 DesiredCapabilities capabilities = new DesiredCapabilities();24 capabilities.setBrowserName("chrome");25 capabilities.setPlatform(Platform.WINDOWS);26 driver.manage().window().maximize();

Full Screen

Full Screen

Response

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.remote.Response;2import org.openqa.selenium.remote.DesiredCapabilities;3import org.openqa.selenium.remote.RemoteWebDriver;4import java.net.URL;5import java.io.IOException;6import java.io.File;7import java.io.FileInputStream;8import java.io.FileOutputStream;9import java.util.zip.ZipOutputStream;10import java.util.zip.ZipEntry;11import java.io.IOException;12import java.io.File;13import java.io.FileInputStream;14import java.io.FileOutputStream;15import java.util.zip.ZipOutputStream;16import java.util.zip.ZipEntry;17import java.io.IOException;18import java.io.File;19import java.io.FileInputStream;20import java.io.FileOutputStream;21import java.util.zip.ZipOutputStream;22import java.util.zip.ZipEntry;23import java.io.IOException;24import java.io.File;25import java.io.FileInputStream;26import java.io.FileOutputStream;27import java.util.zip.ZipOutputStream;28import java.util.zip.ZipEntry;29import java.io

Full Screen

Full Screen

Response

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.remote.Response;2import org.openqa.selenium.remote.SessionId;3import org.openqa.selenium.remote.Response;4import org.openqa.selenium.remote.SessionId;5import org.openqa.selenium.remote.Response;6import org.openqa.selenium.remote.SessionId;7import org.openqa.selenium.remote.Response;8import org.openqa.selenium.remote.SessionId;9import org.openqa.selenium.remote.Response;10import org.openqa.selenium.remote.SessionId;11import org.openqa.selenium.remote.Response;12import org.openqa.selenium.remote.SessionId;13import org.openqa.selenium.remote.Response;14import org.openqa.selenium.remote.SessionId;15import org.openqa.selenium.remote.Response;16import org.openqa.selenium.remote.SessionId;17import org.openqa.selenium.remote.Response;18import org.openqa.selenium.remote.SessionId;19import org.openqa.selenium.remote.Response;20import org.openqa.selenium.remote.SessionId;21import org.openqa.selenium.remote.Response;22import org.openqa.selenium.remote.SessionId;

Full Screen

Full Screen

Response

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.remote.DesiredCapabilities;2import org.openqa.selenium.remote.Response;3DesiredCapabilities capabilities = DesiredCapabilities.firefox();4Response response = new Response();5response.setSessionId("1234");6response.setStatus(0);7response.setValue(capabilities);8import org.openqa.selenium.remote.DesiredCapabilities;9import org.openqa.selenium.remote.Response;10DesiredCapabilities capabilities = DesiredCapabilities.firefox();11Response response = new Response();12response.setSessionId("1234");13response.setStatus(0);14response.setValue(capabilities);15import org.openqa.selenium.remote.DesiredCapabilities;16import org.openqa.selenium.remote.Response;17DesiredCapabilities capabilities = DesiredCapabilities.firefox();18Response response = new Response();19response.setSessionId("1234");20response.setStatus(0);21response.setValue(capabilities);22import org.openqa.selenium.remote.DesiredCapabilities;23import org.openqa.selenium.remote.Response;24DesiredCapabilities capabilities = DesiredCapabilities.firefox();25Response response = new Response();26response.setSessionId("1234");27response.setStatus(0);28response.setValue(capabilities);29import org.openqa.selenium.remote.DesiredCapabilities;30import org.openqa.selenium.remote.Response;31DesiredCapabilities capabilities = DesiredCapabilities.firefox();32Response response = new Response();33response.setSessionId("1234");34response.setStatus(0);35response.setValue(capabilities);36import org.openqa.selenium.remote.DesiredCapabilities;37import org.openqa.selenium.remote.Response;38DesiredCapabilities capabilities = DesiredCapabilities.firefox();39Response response = new Response();40response.setSessionId("1234");41response.setStatus(0);42response.setValue(capabilities);43import org.openqa.selenium.remote.DesiredCapabilities;44import org.openqa.selenium.remote.Response;45DesiredCapabilities capabilities = DesiredCapabilities.firefox();46Response response = new Response();47response.setSessionId("1234");48response.setStatus(0);49response.setValue(capabilities);50import org.openqa.selenium.remote.DesiredCapabilities;51import org.openqa.selenium.remote.Response;52DesiredCapabilities capabilities = DesiredCapabilities.firefox();53Response response = new Response();54response.setSessionId("1234");55response.setStatus(0);56response.setValue(capabilities);57import org.openqa.selenium.remote.DesiredCapabilities;58import org.openqa.selenium.remote.Response;59DesiredCapabilities capabilities = DesiredCapabilities.firefox();60import org.openqa.selenium.remote.Response;61import org.openqa.selenium.remote.SessionId;

Full Screen

Full Screen

Response

Using AI Code Generation

copy

Full Screen

1Response response = new Response();2response.setSessionId("1234");3response.setStatus(0);4response.setValue("Hello World!");5io.appium.java_client.remote.Response response = new io.appium.java_client.remote.Response();6response.setSessionId("1234");7response.setStatus(0);8response.setValue("Hello World!");9io.appium.java_client.remote.Response response = new io.appium.java_client.remote.Response();10response.setSessionId("1234");11response.setStatus(0);12response.setValue("Hello World!");13io.appium.java_client.remote.Response response = new io.appium.java_client.remote.Response();14response.setSessionId("1234");15response.setStatus(0);16response.setValue("Hello World!");

Full Screen

Full Screen

Response

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.remote.Response;2Response response = new Response();3response.setStatus(0);4response.setValue("Hello World");5System.out.println(response);6import io.appium.java_client.remote.Response;7Response response = new Response();8response.setStatus(0);9response.setValue("Hello World");10System.out.println(response);11Response{sessionId='null', status=0, value='Hello World'}

Full Screen

Full Screen

Response

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.remote.DesiredCapabilities;2import org.openqa.selenium.remote.Response;3DesiredCapabilities capabilities = DesiredCapabilities.firefox();4Response response = new Response();5response.setSessionId("1234");6response.setStatus(0);7response.setValue(capabilities);8import org.openqa.selenium.remote.DesiredCapabilities;9import org.openqa.selenium.remote.Response;10DesiredCapabilities capabilities = DesiredCapabilities.firefox();11Response response = new Response();12response.setSessionId("1234");13response.setStatus(0);14response.setValue(capabilities);15import org.openqa.selenium.remote.DesiredCapabilities;16import org.openqa.selenium.remote.Response;17DesiredCapabilities capabilities = DesiredCapabilities.firefox();18Response response = new Response();19response.setSessionId("1234");20response.setStatus(0);21response.setValue(capabilities);22import org.openqa.selenium.remote.DesiredCapabilities;23import org.openqa.selenium.remote.Response;24DesiredCapabilities capabilities = DesiredCapabilities.firefox();25Response response = new Response();26response.setSessionId("1234");27response.setStatus(0);28response.setValue(capabilities);29import org.openqa.selenium.remote.DesiredCapabilities;30import org.openqa.selenium.remote.Response;31DesiredCapabilities capabilities = DesiredCapabilities.firefox();32Response response = new Response();33response.setSessionId("1234");34response.setStatus(0);35response.setValue(capabilities);36import org.openqa.selenium.remote.DesiredCapabilities;37import org.openqa.selenium.remote.Response;38DesiredCapabilities capabilities = DesiredCapabilities.firefox();39Response response = new Response();40response.setSessionId("1234");41response.setStatus(0);42response.setValue(capabilities);43import org.openqa.selenium.remote.DesiredCapabilities;44import org.openqa.selenium.remote.Response;45DesiredCapabilities capabilities = DesiredCapabilities.firefox();46Response response = new Response();47response.setSessionId("1234");48response.setStatus(0);49response.setValue(capabilities);50import org.openqa.selenium.remote.DesiredCapabilities;51import org.openqa.selenium.remote.Response;52DesiredCapabilities capabilities = DesiredCapabilities.firefox();53Response response = new Response();54response.setSessionId("1234");55response.setStatus(0);56response.setValue(capabilities);57import org.openqa.selenium.remote.DesiredCapabilities;58import org.openqa.selenium.remote.Response;59DesiredCapabilities capabilities = DesiredCapabilities.firefox();

Full Screen

Full Screen
copy
1...2for (SocketHolder liveSocket : liveSockets) {3 Socket socket = liveSocket.getSocket();4...5
Full Screen

Selenium 4 Tutorial:

LambdaTest’s Selenium 4 tutorial is covering every aspects of Selenium 4 testing with examples and best practices. Here you will learn basics, such as how to upgrade from Selenium 3 to Selenium 4, to some advanced concepts, such as Relative locators and Selenium Grid 4 for Distributed testing. Also will learn new features of Selenium 4, such as capturing screenshots of specific elements, opening a new tab or window on the browser, and new protocol adoptions.

Chapters:

  1. Upgrading From Selenium 3 To Selenium 4?: In this chapter, learn in detail how to update Selenium 3 to Selenium 4 for Java binding. Also, learn how to upgrade while using different build tools such as Maven or Gradle and get comprehensive guidance for upgrading Selenium.

  2. What’s New In Selenium 4 & What’s Being Deprecated? : Get all information about new implementations in Selenium 4, such as W3S protocol adaption, Optimized Selenium Grid, and Enhanced Selenium IDE. Also, learn what is deprecated for Selenium 4, such as DesiredCapabilites and FindsBy methods, etc.

  3. Selenium 4 With Python: Selenium supports all major languages, such as Python, C#, Ruby, and JavaScript. In this chapter, learn how to install Selenium 4 for Python and the features of Python in Selenium 4, such as Relative locators, Browser manipulation, and Chrom DevTool protocol.

  4. Selenium 4 Is Now W3C Compliant: JSON Wireframe protocol is retiring from Selenium 4, and they are adopting W3C protocol to learn in detail about the advantages and impact of these changes.

  5. How To Use Selenium 4 Relative Locator? : Selenium 4 came with new features such as Relative Locators that allow constructing locators with reference and easily located constructors nearby. Get to know its different use cases with examples.

  6. Selenium Grid 4 Tutorial For Distributed Testing: Selenium Grid 4 allows you to perform tests over different browsers, OS, and device combinations. It also enables parallel execution browser testing, reads up on various features of Selenium Grid 4 and how to download it, and runs a test on Selenium Grid 4 with best practices.

  7. Selenium Video Tutorials: Binge on video tutorials on Selenium by industry experts to get step-by-step direction from automating basic to complex test scenarios with Selenium.

Selenium 101 certifications:

LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.

Run Selenium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

...Most popular Stackoverflow questions on Response

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful