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

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

Source:SauceDockerSessionFactory.java Github

copy

Full Screen

...3import static com.saucelabs.grid.Common.SAUCE_OPTIONS;4import static com.saucelabs.grid.Common.getSauceCapability;5import static java.util.Optional.ofNullable;6import static org.openqa.selenium.ImmutableCapabilities.copyOf;7import static org.openqa.selenium.docker.ContainerConfig.image;8import static org.openqa.selenium.remote.Dialect.W3C;9import static org.openqa.selenium.remote.http.Contents.string;10import static org.openqa.selenium.remote.http.HttpMethod.GET;11import static org.openqa.selenium.remote.http.HttpMethod.POST;12import static org.openqa.selenium.remote.tracing.Tags.EXCEPTION;13import org.openqa.selenium.Capabilities;14import org.openqa.selenium.Dimension;15import org.openqa.selenium.ImmutableCapabilities;16import org.openqa.selenium.PersistentCapabilities;17import org.openqa.selenium.RetrySessionRequestException;18import org.openqa.selenium.SessionNotCreatedException;19import org.openqa.selenium.TimeoutException;20import org.openqa.selenium.UsernameAndPassword;21import org.openqa.selenium.WebDriverException;22import org.openqa.selenium.docker.Container;23import org.openqa.selenium.docker.ContainerConfig;24import org.openqa.selenium.docker.ContainerInfo;25import org.openqa.selenium.docker.Docker;26import org.openqa.selenium.docker.Image;27import org.openqa.selenium.docker.Port;28import org.openqa.selenium.grid.data.CreateSessionRequest;29import org.openqa.selenium.grid.node.ActiveSession;30import org.openqa.selenium.grid.node.SessionFactory;31import org.openqa.selenium.grid.node.docker.DockerAssetsPath;32import org.openqa.selenium.internal.Either;33import org.openqa.selenium.internal.Require;34import org.openqa.selenium.net.PortProber;35import org.openqa.selenium.remote.Command;36import org.openqa.selenium.remote.Dialect;37import org.openqa.selenium.remote.DriverCommand;38import org.openqa.selenium.remote.ProtocolHandshake;39import org.openqa.selenium.remote.Response;40import org.openqa.selenium.remote.SessionId;41import org.openqa.selenium.remote.http.HttpClient;42import org.openqa.selenium.remote.http.HttpRequest;43import org.openqa.selenium.remote.http.HttpResponse;44import org.openqa.selenium.remote.tracing.AttributeKey;45import org.openqa.selenium.remote.tracing.EventAttribute;46import org.openqa.selenium.remote.tracing.EventAttributeValue;47import org.openqa.selenium.remote.tracing.Span;48import org.openqa.selenium.remote.tracing.Status;49import org.openqa.selenium.remote.tracing.Tracer;50import org.openqa.selenium.support.ui.FluentWait;51import org.openqa.selenium.support.ui.Wait;52import java.io.IOException;53import java.io.UncheckedIOException;54import java.net.MalformedURLException;55import java.net.URI;56import java.net.URL;57import java.nio.charset.Charset;58import java.nio.file.Files;59import java.nio.file.Paths;60import java.time.Duration;61import java.time.Instant;62import java.util.Arrays;63import java.util.Collections;64import java.util.HashMap;65import java.util.Map;66import java.util.Objects;67import java.util.Optional;68import java.util.TimeZone;69import java.util.TreeMap;70import java.util.logging.Level;71import java.util.logging.Logger;72public class SauceDockerSessionFactory implements SessionFactory {73 private static final Logger LOG = Logger.getLogger(SauceDockerSessionFactory.class.getName());74 private final Tracer tracer;75 private final HttpClient.Factory clientFactory;76 private final Docker docker;77 private final URI dockerUri;78 private final Image browserImage;79 private final Capabilities stereotype;80 private final Image videoImage;81 private final Image assetsUploaderImage;82 private final DockerAssetsPath assetsPath;83 private final String networkName;84 private final boolean runningInDocker;85 public SauceDockerSessionFactory(86 Tracer tracer,87 HttpClient.Factory clientFactory,88 Docker docker,89 URI dockerUri,90 Image browserImage,91 Capabilities stereotype,92 Image videoImage,93 Image assetsUploaderImage,94 DockerAssetsPath assetsPath,95 String networkName,96 boolean runningInDocker) {97 this.tracer = Require.nonNull("Tracer", tracer);98 this.clientFactory = Require.nonNull("HTTP client", clientFactory);99 this.docker = Require.nonNull("Docker command", docker);100 this.dockerUri = Require.nonNull("Docker URI", dockerUri);101 this.browserImage = Require.nonNull("Docker browser image", browserImage);102 this.networkName = Require.nonNull("Docker network name", networkName);103 this.stereotype = copyOf(Require.nonNull("Stereotype", stereotype));104 this.videoImage = videoImage;105 this.assetsUploaderImage = assetsUploaderImage;106 this.assetsPath = assetsPath;107 this.runningInDocker = runningInDocker;108 }109 @Override110 public boolean test(Capabilities capabilities) {111 return stereotype.getCapabilityNames().stream()112 .map(113 name ->114 Objects.equals(stereotype.getCapability(name), capabilities.getCapability(name)))115 .reduce(Boolean::logicalAnd)116 .orElse(false);117 }118 @Override119 public Either<WebDriverException, ActiveSession> apply(CreateSessionRequest sessionRequest) {120 Optional<Object> accessKey =121 getSauceCapability(sessionRequest.getDesiredCapabilities(), "accessKey");122 Optional<Object> userName =123 getSauceCapability(sessionRequest.getDesiredCapabilities(), "username");124 if (!accessKey.isPresent() && !userName.isPresent()) {125 String message = String.format("Unable to create session. No Sauce Labs accessKey and "126 + "username were found in the '%s' block.", SAUCE_OPTIONS);127 LOG.log(Level.WARNING, message);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()));...

Full Screen

Full Screen

Source:SauceDockerSession.java Github

copy

Full Screen

2import static com.google.common.net.HttpHeaders.CONTENT_TYPE;3import static com.saucelabs.grid.Common.JSON;4import static com.saucelabs.grid.Common.getSauceCapability;5import static java.time.Instant.ofEpochMilli;6import static org.openqa.selenium.docker.ContainerConfig.image;7import static org.openqa.selenium.json.Json.JSON_UTF_8;8import static org.openqa.selenium.remote.http.Contents.asJson;9import org.openqa.selenium.Capabilities;10import org.openqa.selenium.MutableCapabilities;11import org.openqa.selenium.UsernameAndPassword;12import org.openqa.selenium.docker.Container;13import org.openqa.selenium.docker.Docker;14import org.openqa.selenium.docker.Image;15import org.openqa.selenium.grid.node.ProtocolConvertingSession;16import org.openqa.selenium.grid.node.docker.DockerAssetsPath;17import org.openqa.selenium.internal.Require;18import org.openqa.selenium.remote.CapabilityType;19import org.openqa.selenium.remote.Dialect;20import org.openqa.selenium.remote.SessionId;21import org.openqa.selenium.remote.http.Contents;22import org.openqa.selenium.remote.http.HttpClient;23import org.openqa.selenium.remote.http.HttpMethod;24import org.openqa.selenium.remote.http.HttpRequest;25import org.openqa.selenium.remote.http.HttpResponse;26import org.openqa.selenium.remote.tracing.Tracer;27import java.net.URL;28import java.nio.file.Files;29import java.nio.file.Paths;30import java.time.Duration;31import java.time.Instant;32import java.util.ArrayList;33import java.util.Collections;34import java.util.HashMap;35import java.util.List;36import java.util.Map;37import java.util.concurrent.atomic.AtomicBoolean;38import java.util.concurrent.atomic.AtomicInteger;39import java.util.logging.Level;40import java.util.logging.Logger;41public class SauceDockerSession extends ProtocolConvertingSession {42 private static final Logger LOG = Logger.getLogger(SauceDockerSession.class.getName());43 private final Docker docker;44 private final Container container;45 private final Container videoContainer;46 private final AtomicInteger screenshotCount;47 private final AtomicBoolean screenshotsEnabled;48 private final DockerAssetsPath assetsPath;49 private final List<SauceCommandInfo> webDriverCommands;50 private final UsernameAndPassword usernameAndPassword;51 private final Image assetsUploaderImage;52 private final DataCenter dataCenter;53 private final AtomicBoolean tearDownTriggered;54 SauceDockerSession(55 Container container,56 Container videoContainer,57 Tracer tracer,58 HttpClient client,59 SessionId id,60 URL url,61 Capabilities stereotype,62 Capabilities capabilities,63 Dialect downstream,64 Dialect upstream,65 Instant startTime,66 DockerAssetsPath assetsPath,67 UsernameAndPassword usernameAndPassword,68 DataCenter dataCenter,69 Image assetsUploaderImage,70 SauceCommandInfo firstCommand,71 Docker docker) {72 super(tracer, client, id, url, downstream, upstream, stereotype, capabilities, startTime);73 this.container = Require.nonNull("Container", container);74 this.videoContainer = videoContainer;75 this.assetsPath = Require.nonNull("Assets path", assetsPath);76 this.screenshotCount = new AtomicInteger(0);77 this.screenshotsEnabled = new AtomicBoolean(false);78 this.usernameAndPassword = Require.nonNull("Sauce user & key", usernameAndPassword);79 this.webDriverCommands = new ArrayList<>();80 this.webDriverCommands.add(firstCommand);81 this.assetsUploaderImage = assetsUploaderImage;82 this.dataCenter = dataCenter;83 this.docker = Require.nonNull("Docker", docker);84 this.tearDownTriggered = new AtomicBoolean(false);85 }86 public int increaseScreenshotCount() {87 return screenshotCount.getAndIncrement();88 }89 public boolean canTakeScreenshot() {90 return screenshotsEnabled.get();91 }92 public void enableScreenshots() {93 screenshotsEnabled.set(true);94 }95 public void addSauceCommandInfo(SauceCommandInfo commandInfo) {96 if (!webDriverCommands.isEmpty()) {97 // Get when the last command ended to calculate times between commands98 SauceCommandInfo lastCommand = webDriverCommands.get(webDriverCommands.size() - 1);99 long betweenCommands = commandInfo.getStartTime() - lastCommand.getEndTime();100 commandInfo.setBetweenCommands(betweenCommands);101 commandInfo.setVideoStartTime(lastCommand.getVideoStartTime());102 }103 this.webDriverCommands.add(commandInfo);104 }105 public DockerAssetsPath getAssetsPath() {106 return assetsPath;107 }108 @Override109 public void stop() {110 new Thread(() -> {111 if (!tearDownTriggered.getAndSet(true)) {112 if (videoContainer != null) {113 videoContainer.stop(Duration.ofSeconds(10));114 }115 saveLogs();116 container.stop(Duration.ofMinutes(1));117 integrateWithSauce();118 }119 }).start();120 }121 private void saveLogs() {122 String sessionAssetsPath = assetsPath.getContainerPath(getId());123 String seleniumServerLog = String.format("%s/selenium-server.log", sessionAssetsPath);124 String logJson = String.format("%s/log.json", sessionAssetsPath);125 try {126 List<String> logs = container.getLogs().getLogLines();127 Files.write(Paths.get(logJson), getProcessedWebDriverCommands());128 Files.write(Paths.get(seleniumServerLog), logs);129 } catch (Exception e) {130 LOG.log(Level.WARNING, "Error saving logs", e);131 }132 }133 private void integrateWithSauce() {134 String sauceJobId = createSauceJob();135 Container assetUploaderContainer = createAssetUploaderContainer(sauceJobId);136 assetUploaderContainer.start();137 }138 private byte[] getProcessedWebDriverCommands() {139 String webDriverCommands = JSON.toJson(this.webDriverCommands);140 webDriverCommands = webDriverCommands.replaceAll("\"null\"", "null");141 return webDriverCommands.getBytes();142 }143 private String createSauceJob() {144 MutableCapabilities jobInfo = new MutableCapabilities();145 jobInfo.setCapability(CapabilityType.BROWSER_NAME, getCapabilities().getBrowserName());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);174 responseContents = Contents.string(response);175 Map<String, String> jobId = JSON.toType(responseContents, Map.class);176 return jobId.get("ID");177 } catch (Exception e) {178 LOG.log(Level.WARNING, String.format("Error creating job in Sauce Labs. %s", responseContents), e);179 }180 return null;181 }182 private Container createAssetUploaderContainer(String sauceJobId) {183 String hostSessionAssetsPath = assetsPath.getHostPath(getId());184 Map<String, String> assetUploaderContainerEnvVars = getAssetUploaderContainerEnvVars(sauceJobId);185 Map<String, String> assetsPath =186 Collections.singletonMap(hostSessionAssetsPath, "/opt/selenium/assets");187 return docker.create(188 image(assetsUploaderImage)189 .env(assetUploaderContainerEnvVars)190 .bind(assetsPath));191 }192 private Map<String, String> getAssetUploaderContainerEnvVars(String sauceJobId) {193 Map<String, String> envVars = new HashMap<>();194 envVars.put("SAUCE_JOB_ID", sauceJobId);195 envVars.put("SAUCE_API_HOST", dataCenter.apiHost);196 envVars.put("SAUCE_USERNAME", usernameAndPassword.username());197 envVars.put("SAUCE_ACCESS_KEY", usernameAndPassword.password());198 return envVars;199 }200}...

Full Screen

Full Screen

image

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.docker.ContainerConfig2import org.openqa.selenium.docker.Docker3def docker = Docker.getDefaultInstance()4def config = ContainerConfig.builder()5 .withImage("selenium/standalone-chrome:3.141.59-20200609")6 .build()7def container = docker.create(config)8container.start()9def docker = Docker.getDefaultInstance()10def config = ContainerConfig.builder()11 .withImage("selenium/standalone-chrome:3.141.59-20200609")12 .build()13def container = docker.create(config)14container.start()15import org.openqa.selenium.docker.ContainerConfig16import org.openqa.selenium.docker.Docker17def docker = Docker.getDefaultInstance()18def config = ContainerConfig.builder()19 .withImage("selenium/standalone-chrome:3.141.59-20200609")20 .build()21def container = docker.create(config)22container.start()23import org.openqa.selenium.docker.ContainerConfig24import org.openqa.selenium.docker.Docker25def docker = Docker.getDefaultInstance()26def config = ContainerConfig.builder()27 .withImage("selenium/standalone-chrome:3.141.59-20200609")28 .build()29def container = docker.create(config)30container.start()31import org.openqa.selenium.docker.ContainerConfig32import org.openqa.selenium.docker.Docker33def docker = Docker.getDefaultInstance()34def config = ContainerConfig.builder()35 .withImage("selenium/standalone-chrome:3.141.59-20200609")36 .build()37def container = docker.create(config)38container.start()39import org.openqa.selenium.docker.ContainerConfig40import org.openqa.selenium.docker.Docker41def docker = Docker.getDefaultInstance()42def config = ContainerConfig.builder()43 .withImage("selenium/standalone-chrome:3.141.59-20200609")

Full Screen

Full Screen

image

Using AI Code Generation

copy

Full Screen

1ContainerConfig containerConfig = new ContainerConfig()2containerConfig.image("selenium/standalone-chrome:3.141.59-20210208")3containerConfig.exposedPorts("4444/tcp")4containerConfig.cmd("google-chrome", "--headless", "--disable-gpu", "--no-sandbox", "--remote-debugging-port=4444")5containerConfig.env("TZ=Europe/Berlin")6ContainerConfig containerConfig = new ContainerConfig()7containerConfig.image("selenium/standalone-chrome:3.141.59-20210208")8containerConfig.exposedPorts("4444/tcp")9containerConfig.cmd("google-chrome", "--headless", "--disable-gpu", "--no-sandbox", "--remote-debugging-port=4444")10containerConfig.env("TZ=Europe/Berlin")11ContainerConfig containerConfig = new ContainerConfig()12containerConfig.image("selenium/standalone-chrome:3.141.59-20210208")13containerConfig.exposedPorts("4444/tcp")14containerConfig.cmd("google-chrome", "--headless", "--disable-gpu", "--no-sandbox", "--remote-debugging-port=4444")15containerConfig.env("TZ=Europe/Berlin")16ContainerConfig containerConfig = new ContainerConfig()17containerConfig.image("selenium/standalone-chrome:3.141.59-20210208")18containerConfig.exposedPorts("4444/tcp")19containerConfig.cmd("google-chrome", "--headless", "--disable-gpu", "--no-sandbox", "--remote-debugging-port=4444")20containerConfig.env("TZ=Europe/Berlin")21ContainerConfig containerConfig = new ContainerConfig()22containerConfig.image("selenium/standalone-chrome:3.141.59-20210208")23containerConfig.exposedPorts("4444/tcp")24containerConfig.cmd("google-chrome", "--headless", "--disable-gpu", "--no-sandbox", "--remote-debugging-port=4444")25containerConfig.env("TZ=Europe/Berlin")

Full Screen

Full Screen

image

Using AI Code Generation

copy

Full Screen

1public class ContainerConfigExample {2 public static void main(String[] args) {3 ContainerConfig containerConfig = new ContainerConfig();4 Container container = containerConfig.image("alpine:latest").start();5 System.out.println(container.getId());6 }7}8public class ContainerConfigExample {9 public static void main(String[] args) {10 ContainerConfig containerConfig = new ContainerConfig();11 Container container = containerConfig.image("alpine:latest").name("test").start();12 System.out.println(container.getId());13 }14}15public class ContainerConfigExample {16 public static void main(String[] args) {17 ContainerConfig containerConfig = new ContainerConfig();18 Container container = containerConfig.image("alpine:latest").command("echo", "Hello World").start();19 System.out.println(container.getId());20 }21}22public class ContainerConfigExample {23 public static void main(String[] args) {24 ContainerConfig containerConfig = new ContainerConfig();25 Container container = containerConfig.image("alpine:latest").env("TEST=TEST").start();26 System.out.println(container.getId());

Full Screen

Full Screen

image

Using AI Code Generation

copy

Full Screen

1ContainerConfig containerConfig = new ContainerConfig("selenium/standalone-chrome");2containerConfig.image("selenium/standalone-chrome:latest");3containerConfig.mount("/opt/selenium/config.json", "config.json");4ContainerConfig containerConfig = new ContainerConfig("selenium/standalone-chrome");5containerConfig.volume("/opt/selenium/config.json", "config.json");6ContainerConfig containerConfig = new ContainerConfig("selenium/standalone-chrome");7containerConfig.volume("/opt/selenium/config.json", "config.json");8ContainerConfig containerConfig = new ContainerConfig("selenium/standalone-chrome");9containerConfig.volume("/opt/selenium/config.json", "config.json");10ContainerConfig containerConfig = new ContainerConfig("selenium/standalone-chrome");11containerConfig.volume("/opt/selenium/config.json", "config.json");12ContainerConfig containerConfig = new ContainerConfig("selenium/standalone-chrome");13containerConfig.volume("/opt/selenium/config.json", "config.json");14ContainerConfig containerConfig = new ContainerConfig("selenium/standalone-chrome");15containerConfig.volume("/opt/selenium/config.json", "config.json");16ContainerConfig containerConfig = new ContainerConfig("selenium/standalone-chrome");17containerConfig.volume("/opt/selenium/config.json", "config.json");18ContainerConfig containerConfig = new ContainerConfig("selenium/standalone-chrome");19containerConfig.volume("/opt/selenium/config.json", "config.json");

Full Screen

Full Screen

image

Using AI Code Generation

copy

Full Screen

1ContainerConfig config = ContainerConfig.builder()2 .image(Image.fromDockerHub("selenium/standalone-firefox"))3 .build();4ContainerConfig config = ContainerConfig.builder()5 .image(Image.fromDockerHub("selenium/standalone-firefox"))6 .build();7ContainerConfig config = ContainerConfig.builder()8 .image(Image.fromDockerHub("selenium/standalone-firefox"))9 .build();10ContainerConfig config = ContainerConfig.builder()11 .image(Image.fromDockerHub("selenium/standalone-firefox"))12 .build();13ContainerConfig config = ContainerConfig.builder()14 .image(Image.fromDockerHub("selenium/standalone-firefox"))15 .build();

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