How to use toString method of org.openqa.selenium.docker.ContainerConfig class

Best Selenium code snippet using org.openqa.selenium.docker.ContainerConfig.toString

Source:SauceDockerSessionFactory.java Github

copy

Full Screen

...128 return Either.left(new SessionNotCreatedException(message));129 }130 @SuppressWarnings("OptionalGetWithoutIsPresent")131 UsernameAndPassword usernameAndPassword =132 new UsernameAndPassword(userName.get().toString(), accessKey.get().toString());133 Optional<Object> dc =134 getSauceCapability(sessionRequest.getDesiredCapabilities(), "dataCenter");135 DataCenter dataCenter = DataCenter.US_WEST;136 if (dc.isPresent()) {137 dataCenter = DataCenter.fromString(String.valueOf(dc.get()));138 }139 Capabilities sessionReqCaps = removeSauceKey(sessionRequest.getDesiredCapabilities());140 LOG.info("Starting session for " + sessionReqCaps);141 int port = runningInDocker ? 4444 : PortProber.findFreePort();142 try (Span span = tracer.getCurrentContext().createSpan("docker_session_factory.apply")) {143 Map<String, EventAttributeValue> attributeMap = new HashMap<>();144 attributeMap.put(AttributeKey.LOGGER_CLASS.getKey(),145 EventAttribute.setValue(this.getClass().getName()));146 String logMessage = runningInDocker ? "Creating container..." :147 "Creating container, mapping container port 4444 to " + port;148 LOG.info(logMessage);149 Container container = createBrowserContainer(port, sessionReqCaps);150 container.start();151 ContainerInfo containerInfo = container.inspect();152 String containerIp = containerInfo.getIp();153 URL remoteAddress = getUrl(port, containerIp);154 HttpClient client = clientFactory.createClient(remoteAddress);155 attributeMap.put("docker.browser.image", EventAttribute.setValue(browserImage.toString()));156 attributeMap.put("container.port", EventAttribute.setValue(port));157 attributeMap.put("container.id", EventAttribute.setValue(container.getId().toString()));158 attributeMap.put("container.ip", EventAttribute.setValue(containerInfo.getIp()));159 attributeMap.put("docker.server.url", EventAttribute.setValue(remoteAddress.toString()));160 LOG.info(161 String.format("Waiting for server to start (container id: %s, url %s)",162 container.getId(),163 remoteAddress));164 try {165 waitForServerToStart(client, Duration.ofMinutes(1));166 } catch (TimeoutException e) {167 span.setAttribute("error", true);168 span.setStatus(Status.CANCELLED);169 EXCEPTION.accept(attributeMap, e);170 attributeMap.put(AttributeKey.EXCEPTION_MESSAGE.getKey(),171 EventAttribute.setValue(172 "Unable to connect to docker server. Stopping container: " +173 e.getMessage()));174 span.addEvent(AttributeKey.EXCEPTION_EVENT.getKey(), attributeMap);175 container.stop(Duration.ofMinutes(1));176 String message = String.format(177 "Unable to connect to docker server (container id: %s)", container.getId());178 LOG.warning(message);179 return Either.left(new RetrySessionRequestException(message));180 }181 LOG.info(String.format("Server is ready (container id: %s)", container.getId()));182 Command command = new Command(183 null,184 DriverCommand.NEW_SESSION(sessionReqCaps));185 ProtocolHandshake.Result result;186 Response response;187 try {188 result = new ProtocolHandshake().createSession(client, command);189 response = result.createResponse();190 attributeMap.put(191 AttributeKey.DRIVER_RESPONSE.getKey(),192 EventAttribute.setValue(response.toString()));193 } catch (IOException | RuntimeException e) {194 span.setAttribute("error", true);195 span.setStatus(Status.CANCELLED);196 EXCEPTION.accept(attributeMap, e);197 attributeMap.put(198 AttributeKey.EXCEPTION_MESSAGE.getKey(),199 EventAttribute200 .setValue("Unable to create session. Stopping and container: " + e.getMessage()));201 span.addEvent(AttributeKey.EXCEPTION_EVENT.getKey(), attributeMap);202 container.stop(Duration.ofMinutes(1));203 String message = "Unable to create session: " + e.getMessage();204 LOG.log(Level.WARNING, message);205 return Either.left(new SessionNotCreatedException(message));206 }207 SessionId id = new SessionId(response.getSessionId());208 Capabilities capabilities = new ImmutableCapabilities((Map<?, ?>) response.getValue());209 Capabilities mergedCapabilities = capabilities.merge(sessionReqCaps);210 Container videoContainer = null;211 Optional<DockerAssetsPath> path = ofNullable(this.assetsPath);212 if (path.isPresent()) {213 // Seems we can store session assets214 String containerPath = path.get().getContainerPath(id);215 saveSessionCapabilities(mergedCapabilities, containerPath);216 String hostPath = path.get().getHostPath(id);217 videoContainer = startVideoContainer(mergedCapabilities, containerInfo.getIp(), hostPath);218 }219 Instant startTime = Instant.now();220 Instant videoStartTime = Instant.now();221 Dialect downstream = sessionRequest.getDownstreamDialects().contains(result.getDialect()) ?222 result.getDialect() :223 W3C;224 attributeMap.put(225 AttributeKey.DOWNSTREAM_DIALECT.getKey(),226 EventAttribute.setValue(downstream.toString()));227 attributeMap.put(228 AttributeKey.DRIVER_RESPONSE.getKey(),229 EventAttribute.setValue(response.toString()));230 SauceCommandInfo commandInfo = new SauceCommandInfo.Builder()231 .setStartTime(startTime.toEpochMilli())232 .setVideoStartTime(videoStartTime.toEpochMilli())233 .setEndTime(Instant.now().toEpochMilli())234 .setRequest(sessionReqCaps)235 .setResult(mergedCapabilities)236 .setPath("/session")237 .setHttpStatus(response.getStatus())238 .setHttpMethod(POST.name())239 .setStatusCode(0)240 .setScreenshotId(-1)241 .build();242 span.addEvent("Docker driver service created session", attributeMap);243 LOG.fine(String.format(244 "Created session: %s - %s (container id: %s)",245 id,246 capabilities,247 container.getId()));248 return Either.right(new SauceDockerSession(249 container,250 videoContainer,251 tracer,252 client,253 id,254 remoteAddress,255 stereotype,256 mergedCapabilities,257 downstream,258 result.getDialect(),259 startTime,260 assetsPath,261 usernameAndPassword,262 dataCenter,263 assetsUploaderImage,264 commandInfo,265 docker));266 }267 }268 private Container createBrowserContainer(int port, Capabilities sessionCapabilities) {269 Map<String, String> browserContainerEnvVars = getBrowserContainerEnvVars(sessionCapabilities);270 long browserContainerShmMemorySize = 2147483648L; //2GB271 ContainerConfig containerConfig = image(browserImage)272 .env(browserContainerEnvVars)273 .shmMemorySize(browserContainerShmMemorySize)274 .network(networkName);275 if (!runningInDocker) {276 containerConfig = containerConfig.map(Port.tcp(4444), Port.tcp(port));277 }278 return docker.create(containerConfig);279 }280 private Map<String, String> getBrowserContainerEnvVars(Capabilities sessionRequestCapabilities) {281 Optional<Dimension> screenResolution =282 ofNullable(getScreenResolution(sessionRequestCapabilities));283 Map<String, String> envVars = new HashMap<>();284 if (screenResolution.isPresent()) {285 envVars.put("SCREEN_WIDTH", String.valueOf(screenResolution.get().getWidth()));286 envVars.put("SCREEN_HEIGHT", String.valueOf(screenResolution.get().getHeight()));287 }288 Optional<TimeZone> timeZone = ofNullable(getTimeZone(sessionRequestCapabilities));289 timeZone.ifPresent(zone -> envVars.put("TZ", zone.getID()));290 return envVars;291 }292 private Container startVideoContainer(Capabilities sessionCapabilities,293 String browserContainerIp, String hostPath) {294 if (!recordVideoForSession(sessionCapabilities)) {295 return null;296 }297 int videoPort = 9000;298 Map<String, String> envVars = getVideoContainerEnvVars(299 sessionCapabilities,300 browserContainerIp);301 Map<String, String> volumeBinds = Collections.singletonMap(hostPath, "/videos");302 ContainerConfig containerConfig = image(videoImage)303 .env(envVars)304 .bind(volumeBinds)305 .network(networkName);306 if (!runningInDocker) {307 videoPort = PortProber.findFreePort();308 containerConfig = containerConfig.map(Port.tcp(9000), Port.tcp(videoPort));309 }310 Container videoContainer = docker.create(containerConfig);311 videoContainer.start();312 String videoContainerIp = runningInDocker ? videoContainer.inspect().getIp() : "localhost";313 try {314 URL videoContainerUrl = new URL(String.format("http://%s:%s", videoContainerIp, videoPort));315 HttpClient videoClient = clientFactory.createClient(videoContainerUrl);316 LOG.fine(String.format("Waiting for video recording... (id: %s)", videoContainer.getId()));317 waitForServerToStart(videoClient, Duration.ofMinutes(1));318 } catch (Exception e) {319 videoContainer.stop(Duration.ofSeconds(10));320 String message = String.format(321 "Unable to verify video recording started (container id: %s), %s", videoContainer.getId(),322 e.getMessage());323 LOG.warning(message);324 }325 LOG.info(String.format("Video container started (id: %s)", videoContainer.getId()));326 return videoContainer;327 }328 private Map<String, String> getVideoContainerEnvVars(Capabilities sessionRequestCapabilities,329 String containerIp) {330 Map<String, String> envVars = new HashMap<>();331 envVars.put("DISPLAY_CONTAINER_NAME", containerIp);332 Optional<Dimension> screenResolution =333 ofNullable(getScreenResolution(sessionRequestCapabilities));334 screenResolution.ifPresent(dimension -> envVars335 .put("VIDEO_SIZE", String.format("%sx%s", dimension.getWidth(), dimension.getHeight())));336 return envVars;337 }338 private TimeZone getTimeZone(Capabilities sessionRequestCapabilities) {339 Optional<Object> timeZone =340 getSauceCapability(sessionRequestCapabilities, "timeZone");341 if (timeZone.isPresent()) {342 String tz = timeZone.get().toString();343 if (Arrays.asList(TimeZone.getAvailableIDs()).contains(tz)) {344 return TimeZone.getTimeZone(tz);345 }346 }347 return null;348 }349 private Dimension getScreenResolution(Capabilities sessionRequestCapabilities) {350 Optional<Object> screenResolution =351 getSauceCapability(sessionRequestCapabilities, "screenResolution");352 if (!screenResolution.isPresent()) {353 return null;354 }355 try {356 String[] resolution = screenResolution.get().toString().split("x");357 int screenWidth = Integer.parseInt(resolution[0]);358 int screenHeight = Integer.parseInt(resolution[1]);359 if (screenWidth > 0 && screenHeight > 0) {360 return new Dimension(screenWidth, screenHeight);361 } else {362 LOG.warning("One of the values provided for screenResolution is negative, " +363 "defaults will be used. Received value: " + screenResolution);364 }365 } catch (Exception e) {366 LOG.warning("Values provided for screenResolution are not valid integers or " +367 "either width or height are missing, defaults will be used." +368 "Received value: " + screenResolution);369 }370 return null;371 }372 private boolean recordVideoForSession(Capabilities sessionRequestCapabilities) {373 boolean recordVideo = true;374 Optional<Object> recordVideoCapability =375 getSauceCapability(sessionRequestCapabilities, "recordVideo");376 if (recordVideoCapability.isPresent()) {377 recordVideo = Boolean.parseBoolean(recordVideoCapability.get().toString());378 }379 return recordVideo;380 }381 private void saveSessionCapabilities(Capabilities sessionRequestCapabilities, String path) {382 String capsToJson = JSON.toJson(sessionRequestCapabilities);383 try {384 Files.createDirectories(Paths.get(path));385 Files.write(386 Paths.get(path, "sessionCapabilities.json"),387 capsToJson.getBytes(Charset.defaultCharset()));388 } catch (IOException e) {389 LOG.log(Level.WARNING,390 "Failed to save session capabilities", e);391 }...

Full Screen

Full Screen

Source:DockerSessionFactory.java Github

copy

Full Screen

...137 ContainerInfo containerInfo = container.inspect();138 String containerIp = containerInfo.getIp();139 URL remoteAddress = getUrl(port, containerIp);140 HttpClient client = clientFactory.createClient(remoteAddress);141 attributeMap.put("docker.browser.image", EventAttribute.setValue(browserImage.toString()));142 attributeMap.put("container.port", EventAttribute.setValue(port));143 attributeMap.put("container.id", EventAttribute.setValue(container.getId().toString()));144 attributeMap.put("container.ip", EventAttribute.setValue(containerIp));145 attributeMap.put("docker.server.url", EventAttribute.setValue(remoteAddress.toString()));146 LOG.info(147 String.format("Waiting for server to start (container id: %s, url %s)",148 container.getId(),149 remoteAddress));150 try {151 waitForServerToStart(client, Duration.ofMinutes(1));152 } catch (TimeoutException e) {153 span.setAttribute("error", true);154 span.setStatus(Status.CANCELLED);155 EXCEPTION.accept(attributeMap, e);156 attributeMap.put(AttributeKey.EXCEPTION_MESSAGE.getKey(),157 EventAttribute.setValue(158 "Unable to connect to docker server. Stopping container: " +159 e.getMessage()));160 span.addEvent(AttributeKey.EXCEPTION_EVENT.getKey(), attributeMap);161 container.stop(Duration.ofMinutes(1));162 String message = String.format(163 "Unable to connect to docker server (container id: %s)", container.getId());164 LOG.warning(message);165 return Either.left(new RetrySessionRequestException(message));166 }167 LOG.info(String.format("Server is ready (container id: %s)", container.getId()));168 Command command = new Command(169 null,170 DriverCommand.NEW_SESSION(sessionRequest.getDesiredCapabilities()));171 ProtocolHandshake.Result result;172 Response response;173 try {174 result = new ProtocolHandshake().createSession(client, command);175 response = result.createResponse();176 attributeMap.put(AttributeKey.DRIVER_RESPONSE.getKey(),177 EventAttribute.setValue(response.toString()));178 } catch (IOException | RuntimeException e) {179 span.setAttribute("error", true);180 span.setStatus(Status.CANCELLED);181 EXCEPTION.accept(attributeMap, e);182 attributeMap.put(183 AttributeKey.EXCEPTION_MESSAGE.getKey(),184 EventAttribute185 .setValue("Unable to create session. Stopping and container: " + e.getMessage()));186 span.addEvent(AttributeKey.EXCEPTION_EVENT.getKey(), attributeMap);187 container.stop(Duration.ofMinutes(1));188 String message = "Unable to create session: " + e.getMessage();189 LOG.log(Level.WARNING, message, e);190 return Either.left(new SessionNotCreatedException(message));191 }192 SessionId id = new SessionId(response.getSessionId());193 Capabilities capabilities = new ImmutableCapabilities((Map<?, ?>) response.getValue());194 Capabilities mergedCapabilities = capabilities.merge(sessionRequest.getDesiredCapabilities());195 Container videoContainer = null;196 Optional<DockerAssetsPath> path = ofNullable(this.assetsPath);197 if (path.isPresent()) {198 // Seems we can store session assets199 String containerPath = path.get().getContainerPath(id);200 saveSessionCapabilities(mergedCapabilities, containerPath);201 String hostPath = path.get().getHostPath(id);202 videoContainer = startVideoContainer(mergedCapabilities, containerIp, hostPath);203 }204 Dialect downstream = sessionRequest.getDownstreamDialects().contains(result.getDialect()) ?205 result.getDialect() :206 W3C;207 attributeMap.put(208 AttributeKey.DOWNSTREAM_DIALECT.getKey(),209 EventAttribute.setValue(downstream.toString()));210 attributeMap.put(211 AttributeKey.DRIVER_RESPONSE.getKey(),212 EventAttribute.setValue(response.toString()));213 span.addEvent("Docker driver service created session", attributeMap);214 LOG.fine(String.format(215 "Created session: %s - %s (container id: %s)",216 id,217 capabilities,218 container.getId()));219 return Either.right(new DockerSession(220 container,221 videoContainer,222 tracer,223 client,224 id,225 remoteAddress,226 stereotype,227 mergedCapabilities,228 downstream,229 result.getDialect(),230 Instant.now()));231 }232 }233 private Container createBrowserContainer(int port, Capabilities sessionCapabilities) {234 Map<String, String> browserContainerEnvVars = getBrowserContainerEnvVars(sessionCapabilities);235 Map<String, String> devShmMount = Collections.singletonMap("/dev/shm", "/dev/shm");236 ContainerConfig containerConfig = image(browserImage)237 .env(browserContainerEnvVars)238 .bind(devShmMount)239 .network(networkName);240 if (!runningInDocker) {241 containerConfig = containerConfig.map(Port.tcp(4444), Port.tcp(port));242 }243 return docker.create(containerConfig);244 }245 private Map<String, String> getBrowserContainerEnvVars(Capabilities sessionRequestCapabilities) {246 Optional<Dimension> screenResolution =247 ofNullable(getScreenResolution(sessionRequestCapabilities));248 Map<String, String> envVars = new HashMap<>();249 if (screenResolution.isPresent()) {250 envVars.put("SCREEN_WIDTH", String.valueOf(screenResolution.get().getWidth()));251 envVars.put("SCREEN_HEIGHT", String.valueOf(screenResolution.get().getHeight()));252 }253 Optional<TimeZone> timeZone = ofNullable(getTimeZone(sessionRequestCapabilities));254 timeZone.ifPresent(zone -> envVars.put("TZ", zone.getID()));255 return envVars;256 }257 private Container startVideoContainer(Capabilities sessionCapabilities,258 String browserContainerIp, String hostPath) {259 if (!recordVideoForSession(sessionCapabilities)) {260 return null;261 }262 int videoPort = 9000;263 Map<String, String> envVars = getVideoContainerEnvVars(264 sessionCapabilities,265 browserContainerIp);266 Map<String, String> volumeBinds = Collections.singletonMap(hostPath, "/videos");267 ContainerConfig containerConfig = image(videoImage)268 .env(envVars)269 .bind(volumeBinds)270 .network(networkName);271 if (!runningInDocker) {272 videoPort = PortProber.findFreePort();273 containerConfig = containerConfig.map(Port.tcp(9000), Port.tcp(videoPort));274 }275 Container videoContainer = docker.create(containerConfig);276 videoContainer.start();277 String videoContainerIp = runningInDocker ? videoContainer.inspect().getIp() : "localhost";278 try {279 URL videoContainerUrl = new URL(String.format("http://%s:%s", videoContainerIp, videoPort));280 HttpClient videoClient = clientFactory.createClient(videoContainerUrl);281 LOG.fine(String.format("Waiting for video recording... (id: %s)", videoContainer.getId()));282 waitForServerToStart(videoClient, Duration.ofMinutes(1));283 } catch (Exception e) {284 videoContainer.stop(Duration.ofSeconds(10));285 String message = String.format(286 "Unable to verify video recording started (container id: %s), %s", videoContainer.getId(),287 e.getMessage());288 LOG.warning(message);289 }290 LOG.info(String.format("Video container started (id: %s)", videoContainer.getId()));291 return videoContainer;292 }293 private Map<String, String> getVideoContainerEnvVars(Capabilities sessionRequestCapabilities,294 String containerIp) {295 Map<String, String> envVars = new HashMap<>();296 envVars.put("DISPLAY_CONTAINER_NAME", containerIp);297 Optional<Dimension> screenResolution =298 ofNullable(getScreenResolution(sessionRequestCapabilities));299 screenResolution.ifPresent(dimension -> envVars300 .put("VIDEO_SIZE", String.format("%sx%s", dimension.getWidth(), dimension.getHeight())));301 return envVars;302 }303 private TimeZone getTimeZone(Capabilities sessionRequestCapabilities) {304 Optional<Object> timeZone =305 ofNullable(sessionRequestCapabilities.getCapability("se:timeZone"));306 if (timeZone.isPresent()) {307 String tz = timeZone.get().toString();308 if (Arrays.asList(TimeZone.getAvailableIDs()).contains(tz)) {309 return TimeZone.getTimeZone(tz);310 }311 }312 return null;313 }314 private Dimension getScreenResolution(Capabilities sessionRequestCapabilities) {315 Optional<Object> screenResolution =316 ofNullable(sessionRequestCapabilities.getCapability("se:screenResolution"));317 if (!screenResolution.isPresent()) {318 return null;319 }320 try {321 String[] resolution = screenResolution.get().toString().split("x");322 int screenWidth = Integer.parseInt(resolution[0]);323 int screenHeight = Integer.parseInt(resolution[1]);324 if (screenWidth > 0 && screenHeight > 0) {325 return new Dimension(screenWidth, screenHeight);326 } else {327 LOG.warning("One of the values provided for screenResolution is negative, " +328 "defaults will be used. Received value: " + screenResolution);329 }330 } catch (Exception e) {331 LOG.warning("Values provided for screenResolution are not valid integers or " +332 "either width or height are missing, defaults will be used." +333 "Received value: " + screenResolution);334 }335 return null;336 }337 private boolean recordVideoForSession(Capabilities sessionRequestCapabilities) {338 Optional<Object> recordVideo =339 ofNullable(sessionRequestCapabilities.getCapability("se:recordVideo"));340 return recordVideo.isPresent() && Boolean.parseBoolean(recordVideo.get().toString());341 }342 private void saveSessionCapabilities(Capabilities sessionRequestCapabilities, String path) {343 String capsToJson = new Json().toJson(sessionRequestCapabilities);344 try {345 Files.createDirectories(Paths.get(path));346 Files.write(347 Paths.get(path, "sessionCapabilities.json"),348 capsToJson.getBytes(Charset.defaultCharset()));349 } catch (IOException e) {350 LOG.log(Level.WARNING,351 "Failed to save session capabilities", e);352 }353 }354 private void waitForServerToStart(HttpClient client, Duration duration) {...

Full Screen

Full Screen

Source:SauceDockerSession.java Github

copy

Full Screen

...146 jobInfo.setCapability(CapabilityType.PLATFORM_NAME, getCapabilities().getPlatformName());147 jobInfo.setCapability(CapabilityType.BROWSER_VERSION, getCapabilities().getBrowserVersion());148 jobInfo.setCapability("framework", "webdriver");149 getSauceCapability(getCapabilities(), "build")150 .ifPresent(build -> jobInfo.setCapability("build", build.toString()));151 getSauceCapability(getCapabilities(), "name")152 .ifPresent(name -> jobInfo.setCapability("name", name.toString()));153 getSauceCapability(getCapabilities(), "tags")154 .ifPresent(tags -> jobInfo.setCapability("tags", tags));155 SauceCommandInfo firstCommand = webDriverCommands.get(0);156 String startTime = ofEpochMilli(firstCommand.getStartTime()).toString();157 jobInfo.setCapability("startTime", startTime);158 SauceCommandInfo lastCommand = webDriverCommands.get(webDriverCommands.size() - 1);159 String endTime = ofEpochMilli(lastCommand.getStartTime()).toString();160 jobInfo.setCapability("endTime", endTime);161 // TODO: We cannot always know if the test passed or not162 jobInfo.setCapability("passed", true);163 String apiUrl = String.format(164 dataCenter.apiUrl,165 usernameAndPassword.username(),166 usernameAndPassword.password());167 String responseContents = "";168 try {169 HttpClient client = HttpClient.Factory.createDefault().createClient(new URL(apiUrl));170 HttpRequest request = new HttpRequest(HttpMethod.POST, "/v1/testcomposer/reports");171 request.setContent(asJson(jobInfo));172 request.setHeader(CONTENT_TYPE, JSON_UTF_8);173 HttpResponse response = client.execute(request);...

Full Screen

Full Screen

Source:ContainerConfig.java Github

copy

Full Screen

...73 Require.nonNull("Container network name", networkName);74 return new ContainerConfig(image, portBindings, envVars, volumeBinds, networkName);75 }76 @Override77 public String toString() {78 return "ContainerConfig{" +79 "image=" + image +80 ", portBindings=" + portBindings +81 ", envVars=" + envVars +82 ", volumeBinds=" + volumeBinds +83 ", networkName=" + networkName +84 ", autoRemove=" + autoRemove +85 '}';86 }87 private Map<String, Object> toJson() {88 List<String> envVars = this.envVars.keySet().stream()89 .map(key -> String.format("%s=%s", key, this.envVars.get(key)))90 .collect(Collectors.toList());91 List<String> volumeBinds = this.volumeBinds.keySet().stream()...

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1 ContainerConfig containerConfig = new ContainerConfig();2 containerConfig.setImage("selenium/standalone-chrome");3 containerConfig.setPortBindings(new HashMap<>());4 containerConfig.getPortBindings().put("4444/tcp", new ArrayList<>());5 containerConfig.getPortBindings().get("4444/tcp").add(new HostConfig.PortBinding().withHostPort("4444"));6 containerConfig.setExposedPorts(new HashSet<>());7 containerConfig.getExposedPorts().add("4444/tcp");8 containerConfig.setEnv(new ArrayList<>());9 containerConfig.getEnv().add("SCREEN_WIDTH=1920");10 containerConfig.getEnv().add("SCREEN_HEIGHT=1080");11 containerConfig.getEnv().add("TZ=Europe/London");12 containerConfig.setCmd(new ArrayList<>());13 containerConfig.getCmd().add("--whitelisted-ips");14 containerConfig.getCmd().add("");15 containerConfig.getCmd().add("--tz");16 containerConfig.getCmd().add("Europe/London");17 containerConfig.getCmd().add("--browserTimeout");18 containerConfig.getCmd().add("60");19 containerConfig.getCmd().add("--timeZone");20 containerConfig.getCmd().add("Europe/London");21 containerConfig.getCmd().add("--screenResolution");22 containerConfig.getCmd().add("1920x1080x24");23 containerConfig.getCmd().add("--enablePassThrough");24 containerConfig.getCmd().add("false");25 containerConfig.getCmd().add("--allowAllDomains");26 containerConfig.getCmd().add("false");27 containerConfig.getCmd().add("--debug");28 containerConfig.getCmd().add("false");29 containerConfig.getCmd().add("--logPath");30 containerConfig.getCmd().add("/tmp");31 containerConfig.getCmd().add("--videoRecordingEnabled");32 containerConfig.getCmd().add("true");33 containerConfig.getCmd().add("--videoFrameRate");34 containerConfig.getCmd().add("24");35 containerConfig.getCmd().add("--maxTestSessions");36 containerConfig.getCmd().add("1");37 containerConfig.getCmd().add("--servlets");38 containerConfig.getCmd().add("com.automation.remarks.video.VideoServlet");39 containerConfig.getCmd().add("--port");40 containerConfig.getCmd().add("4444");41 containerConfig.getCmd().add("--host");

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.docker.ContainerConfig;2import org.openqa.selenium.docker.Docker;3import org.openqa.selenium.docker.DockerException;4import org.openqa.selenium.docker.VncRecordingMode;5import java.nio.file.Paths;6import java.util.concurrent.TimeUnit;7public class DockerExample {8 public static void main(String[] args) throws DockerException {9 try (Docker docker = Docker.createDefault()) {10 ContainerConfig config = ContainerConfig.builder()11 .image("selenium/standalone-chrome")12 .port(4444)13 .vnc(VncRecordingMode.RECORD_ALL)14 .build();15 String containerId = docker.run(config);16 System.out.println("Started container: " + containerId);17 docker.stop(containerId, 30, TimeUnit.SECONDS);18 System.out.println("Stopped container: " + containerId);19 docker.copyFromContainer(containerId, "/home/seluser/videos", Paths.get("videos"));20 System.out.println("Copied video files from container: " + containerId);21 }22 }23}24import org.openqa.selenium.docker.ContainerConfig;25import org.openqa.selenium.docker.Docker;26import org.openqa.selenium.docker.DockerException;27import org.openqa.selenium.docker.VncRecordingMode;28import java.nio.file.Paths;29import java.util.concurrent.TimeUnit;30public class DockerExample {31 public static void main(String[] args) throws DockerException {32 try (Docker docker = Docker.createDefault()) {33 ContainerConfig config = ContainerConfig.builder()34 .image("selenium/standalone-chrome")35 .port(4444)36 .vnc(VncRecordingMode.RECORD_ALL)37 .build();38 String containerId = docker.run(config);39 System.out.println("Started container: " + containerId);40 docker.stop(containerId, 30, TimeUnit.SECONDS);41 System.out.println("Stopped container: " + containerId);42 docker.copyFromContainer(containerId, "/home/seluser/videos", Paths.get("videos"));43 System.out.println("Copied video files from container: " + containerId);44 }45 }46}

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1ContainerConfig containerConfig = new ContainerConfig()2 .withImage('selenium/standalone-chrome:3.14.0-beryllium')3 .withExposedPorts('4444')4 .withEnv('TZ=Europe/London')5 .withHostConfig(new HostConfig()6 .withBinds(new Bind()7 .withSource('/dev/shm')8 .withTarget('/dev/shm')9 .withBindMode('rw')))10 .withLabels('foo', 'bar')11 .withCmd(['--foo', '--bar'])12 .withEntrypoint('/bin/bash')13 .withHealthcheck(new Healthcheck()14 .withInterval(30)15 .withTimeout(30)16 .withRetries(5)17 .withStartPeriod(0))18 .withMacAddress('02:42:ac:11:00:02')19 .withNetworkDisabled(false)20 .withOnBuild('RUN echo "do something"')21 .withStopSignal('SIGINT')22 .withStopTimeout(10)23 .withUser('user')24 .withVolumes(new Volume()25 .withName('vol1')26 .withDriver('local'))27 .withWorkingDir('/tmp')28 .withAttachStderr(true)29 .withAttachStdin(true)30 .withAttachStdout(true)31 .withCpuPeriod(100000)32 .withCpuQuota(50000)33 .withCpuShares(512)34 .withCpusetCpus('0,1')35 .withCpusetMems('0,1')36 .withDevices(new Device()37 .withPathOnHost('/dev/sda')38 .withPathInContainer('/dev/xvda')39 .withCgroupPermissions('rwm'))40 .withDomainname('domainname')41 .withHostname('hostname')42 .withIpcMode('host')43 .withMemory(100000000)44 .withMemorySwap(200000000)45 .withMemorySwappiness(0)46 .withNetworkMode('host')47 .withOomKillDisable(false)48 .withOomScoreAdj(500)49 .withPidMode('host')50 .withPrivileged(true)51 .withPublishAllPorts(true)

Full Screen

Full Screen

toString

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.docker.ContainerConfig;2ContainerConfig containerConfig = new ContainerConfig();3containerConfig.withImage("selenium/standalone-chrome:latest");4containerConfig.withHostName("selenium");5containerConfig.withPortBindings("4444:4444");6System.out.println(containerConfig.toString());7{"Image":"selenium/standalone-chrome:latest","HostName":"selenium","ExposedPorts":{"4444/tcp":{}},8"HostConfig":{"PortBindings":{"4444/tcp":[{"HostPort":"4444"}]}}}9import org.openqa.selenium.docker.ContainerConfig;10ContainerConfig containerConfig = new ContainerConfig();11containerConfig.withImage("selenium/standalone-chrome:latest");12containerConfig.withHostName("selenium");13containerConfig.withPortBindings("4444:4444");14System.out.println(containerConfig.toYaml());15 4444/tcp: {}16import org.openqa.selenium.docker.ContainerConfig;17ContainerConfig containerConfig = new ContainerConfig();18containerConfig.withImage("selenium/standalone-chrome:latest");19containerConfig.withHostName("selenium");20containerConfig.withPortBindings("4444:4444");21System.out.println(containerConfig.toDockerCompose());22import org.openqa.selenium.docker.ContainerConfig;23ContainerConfig containerConfig = new ContainerConfig();24containerConfig.withImage("selenium/standalone-chrome:latest");25containerConfig.withHostName("selenium");26containerConfig.withPortBindings("4444:4444");27containerConfig.withContainerName("selenium");28System.out.println(containerConfig.toDockerCompose());

Full Screen

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 used method in ContainerConfig

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful