Best Karate code snippet using com.intuit.karate.driver.Driver
Source:DriverOptions.java
...25import com.intuit.karate.Http;26import com.intuit.karate.KarateException;27import com.intuit.karate.LogAppender;28import com.intuit.karate.Logger;29import com.intuit.karate.driver.appium.AndroidDriver;30import com.intuit.karate.driver.chrome.Chrome;31import com.intuit.karate.driver.chrome.ChromeWebDriver;32import com.intuit.karate.driver.indigo.IndigoDriver;33import com.intuit.karate.driver.microsoft.EdgeChromium;34import com.intuit.karate.driver.microsoft.IeWebDriver;35import com.intuit.karate.driver.microsoft.MsWebDriver;36import com.intuit.karate.driver.firefox.GeckoWebDriver;37import com.intuit.karate.driver.appium.IosDriver;38import com.intuit.karate.driver.microsoft.MsEdgeDriver;39import com.intuit.karate.driver.safari.SafariWebDriver;40import com.intuit.karate.driver.microsoft.WinAppDriver;41import com.intuit.karate.driver.playwright.PlaywrightDriver;42import com.intuit.karate.core.Config;43import com.intuit.karate.core.ScenarioEngine;44import com.intuit.karate.core.ScenarioRuntime;45import com.intuit.karate.shell.Command;46import java.io.File;47import java.util.ArrayList;48import java.util.Arrays;49import java.util.HashMap;50import java.util.Iterator;51import java.util.List;52import java.util.Map;53import java.util.function.Consumer;54import java.util.function.Predicate;55import java.util.function.Supplier;56import asura.ui.driver.DriverProvider;57/**58 *59 * @author pthomas360 */61public class DriverOptions {62 // injected63 private static DriverProvider driverProvider;64 public static DriverProvider getDriverProvider() {65 return driverProvider;66 }67 public static void setDriverProvider(DriverProvider driverProvider) {68 DriverOptions.driverProvider = driverProvider;69 }70 public static void loadOverride() {71 }72 public final Map<String, Object> options;73 public final int timeout;74 public final boolean start;75 public final boolean stop;76 public final String executable;77 public final String type;78 public final int port;79 public final String host;80 public final int pollAttempts;81 public final int pollInterval;82 public final boolean headless;83 public final boolean showProcessLog;84 public final boolean showDriverLog;85 public final Logger logger;86 public final LogAppender appender;87 public final Logger processLogger;88 public final Logger driverLogger;89 public final String uniqueName;90 public final File workingDir;91 public final String userAgent;92 public final String userDataDir;93 public final String processLogFile;94 public final int maxPayloadSize;95 public final List<String> addOptions;96 public final List<String> args = new ArrayList<>();97 public final String webDriverUrl;98 public final String webDriverPath;99 public final Map<String, Object> webDriverSession;100 public final Map<String, Object> httpConfig;101 public final Target target;102 public final String beforeStart;103 public final String afterStop;104 public final String videoFile;105 public final boolean highlight;106 public final int highlightDuration;107 public final String attach;108 public final boolean screenshotOnFailure;109 public final String playwrightUrl;110 public final Map<String, Object> playwrightOptions;111 // mutable during a test112 private boolean retryEnabled;113 private Integer retryInterval = null;114 private Integer retryCount = null;115 private String preSubmitHash = null;116 private Integer timeoutOverride;117 public static final String SCROLL_JS_FUNCTION = "function(e){ var d = window.getComputedStyle(e).display;"118 + " while(d == 'none'){ e = e.parentElement; d = window.getComputedStyle(e).display }"119 + " e.scrollIntoView({block: 'center'}) }";120 public static final String KARATE_REF_GENERATOR = "function(e){"121 + " if (!document._karate) document._karate = { seq: (new Date()).getTime() };"122 + " var ref = 'ref' + document._karate.seq++; document._karate[ref] = e; return ref }";123 public boolean isRetryEnabled() {124 return retryEnabled;125 }126 public String getPreSubmitHash() {127 return preSubmitHash;128 }129 public void setPreSubmitHash(String preSubmitHash) {130 this.preSubmitHash = preSubmitHash;131 }132 private <T> T get(String key, T defaultValue) {133 T temp = (T) options.get(key);134 return temp == null ? defaultValue : temp;135 }136 public DriverOptions(Map<String, Object> options, ScenarioRuntime sr, int defaultPort, String defaultExecutable) {137 this.options = options;138 this.appender = sr.logAppender;139 logger = new Logger(getClass());140 logger.setAppender(appender);141 timeout = get("timeout", Config.DEFAULT_TIMEOUT);142 type = get("type", null);143 start = get("start", true);144 stop = get("stop", true);145 executable = get("executable", defaultExecutable);146 headless = get("headless", false);147 showProcessLog = get("showProcessLog", false);148 addOptions = get("addOptions", null);149 uniqueName = type + "_" + System.currentTimeMillis();150 String packageName = getClass().getPackage().getName();151 processLogger = showProcessLog ? logger : new Logger(packageName + "." + uniqueName);152 showDriverLog = get("showDriverLog", false);153 driverLogger = showDriverLog ? logger : new Logger(packageName + "." + uniqueName);154 if (executable != null) {155 if (executable.startsWith(".")) { // honor path even when we set working dir156 args.add(new File(executable).getAbsolutePath());157 } else {158 args.add(executable);159 }160 }161 userAgent = get("userAgent", null);162 if (options.containsKey("userDataDir")) {163 String temp = get("userDataDir", null);164 if (temp != null) {165 workingDir = new File(temp);166 userDataDir = workingDir.getAbsolutePath();167 } else { // special case allow user-specified null168 userDataDir = null;169 workingDir = null;170 }171 } else {172 workingDir = new File(sr.featureRuntime.suite.buildDir + File.separator + uniqueName);173 userDataDir = workingDir.getAbsolutePath();174 }175 if (workingDir == null) {176 processLogFile = sr.featureRuntime.suite.buildDir + File.separator + uniqueName + ".log";177 } else {178 processLogFile = workingDir.getPath() + File.separator + type + ".log";179 }180 maxPayloadSize = get("maxPayloadSize", Integer.MAX_VALUE);181 target = get("target", null);182 host = get("host", "localhost");183 webDriverUrl = get("webDriverUrl", null);184 webDriverPath = get("webDriverPath", null);185 webDriverSession = get("webDriverSession", null);186 httpConfig = get("httpConfig", null);187 beforeStart = get("beforeStart", null);188 afterStop = get("afterStop", null);189 videoFile = get("videoFile", null);190 pollAttempts = get("pollAttempts", 20);191 pollInterval = get("pollInterval", 250);192 highlight = get("highlight", false);193 highlightDuration = get("highlightDuration", Config.DEFAULT_HIGHLIGHT_DURATION);194 attach = get("attach", null);195 screenshotOnFailure = get("screenshotOnFailure", true);196 playwrightUrl = get("playwrightUrl", null);197 playwrightOptions = get("playwrightOptions", null);198 // do this last to ensure things like logger, start-flag, webDriverUrl etc. are set199 port = resolvePort(defaultPort);200 }201 private int resolvePort(int defaultPort) {202 if (webDriverUrl != null) {203 return 0;204 }205 int preferredPort = get("port", defaultPort);206 if (start) {207 int freePort = Command.getFreePort(preferredPort);208 if (preferredPort == 0) {209 logger.info("use a automatically allocated port number {}", freePort);210 } else if (freePort != preferredPort) {211 logger.warn("preferred port {} not available, will use: {}", preferredPort, freePort);212 }213 return freePort;214 }215 return preferredPort;216 }217 public Http getHttp() {218 Http http = Http.to(getUrlBase());219 http.setAppender(driverLogger.getAppender());220 if (httpConfig != null) {221 http.configure(httpConfig);222 }223 return http;224 }225 private String getUrlBase() {226 if (webDriverUrl != null) {227 return webDriverUrl;228 }229 String urlBase = "http://" + host + ":" + port;230 if (webDriverPath != null) {231 return urlBase + webDriverPath;232 }233 return urlBase;234 }235 public void arg(String arg) {236 args.add(arg);237 }238 public Command startProcess() {239 return startProcess(null);240 }241 public Command startProcess(Consumer<String> listener) {242 if (beforeStart != null) {243 Command.execLine(null, beforeStart);244 }245 Command command;246 if (target != null || !start) {247 command = null;248 } else {249 if (addOptions != null) {250 args.addAll(addOptions);251 }252 command = new Command(false, processLogger, uniqueName, processLogFile, workingDir, args.toArray(new String[args.size()]));253 if (listener != null) {254 command.setListener(listener);255 }256 command.setPollAttempts(pollAttempts);257 command.setPollInterval(pollInterval);258 command.start();259 }260 if (command != null) { // wait for a slow booting browser / driver process261 command.waitForPort(host, port);262 if (command.isFailed()) {263 throw new KarateException("start failed", command.getFailureReason());264 }265 }266 return command;267 }268 public static Driver startOrigin(Map<String, Object> options, ScenarioRuntime sr) {269 Target target = (Target) options.get("target");270 if (target != null) {271 sr.logger.debug("custom target configured, calling start()");272 Map<String, Object> map = target.start(sr);273 sr.logger.trace("custom target returned options: {}", map);274 options.putAll(map);275 }276 String type = (String) options.get("type");277 if (type == null) {278 sr.logger.warn("type was null, defaulting to 'chrome'");279 type = "chrome";280 options.put("type", type);281 }282 try { // to make troubleshooting errors easier283 switch (type) {284 case "chrome":285 return Chrome.start(options, sr);286 case "msedge":287 return EdgeChromium.start(options, sr);288 case "chromedriver":289 return ChromeWebDriver.start(options, sr);290 case "geckodriver":291 return GeckoWebDriver.start(options, sr);292 case "safaridriver":293 return SafariWebDriver.start(options, sr);294 case "msedgedriver":295 return MsEdgeDriver.start(options, sr);296 case "mswebdriver":297 return MsWebDriver.start(options, sr);298 case "iedriver":299 return IeWebDriver.start(options, sr);300 case "winappdriver":301 return WinAppDriver.start(options, sr);302 case "android":303 return AndroidDriver.start(options, sr);304 case "ios":305 return IosDriver.start(options, sr);306 case "playwright":307 return PlaywrightDriver.start(options, sr);308 case "indigo":309 return IndigoDriver.start(options, sr);310 case "electron":311 return Chrome.start(options, sr);312 default:313 sr.logger.warn("unknown driver type: {}, defaulting to 'chrome'", type);314 options.put("type", "chrome");315 return Chrome.start(options, sr);316 }317 } catch (Exception e) {318 String message = "driver config / start failed: " + e.getMessage() + ", options: " + options;319 sr.logger.error(message, e);320 if (target != null) {321 target.stop(sr);322 }323 throw new RuntimeException(message, e);324 }325 }326 public static Driver start(Map<String, Object> options, ScenarioRuntime sr) { // TODO unify logger327 DriverProvider driverProvider = getDriverProvider();328 if (driverProvider != null) {329 return driverProvider.get(options, sr);330 } else {331 return startOrigin(options, sr);332 }333 }334 private Map<String, Object> getSession(String browserName) {335 Map<String, Object> session = webDriverSession;336 if (session == null) {337 session = new HashMap();338 }339 Map<String, Object> capabilities = (Map) session.get("capabilities");340 if (capabilities == null) {341 capabilities = (Map) session.get("desiredCapabilities");342 }343 if (capabilities == null) {344 capabilities = new HashMap();345 session.put("capabilities", capabilities);346 Map<String, Object> alwaysMatch = new HashMap();347 capabilities.put("alwaysMatch", alwaysMatch);348 alwaysMatch.put("browserName", browserName);349 }350 return session;351 }352 // TODO abstract as method per implementation353 public Map<String, Object> getWebDriverSessionPayload() {354 switch (type) {355 case "chromedriver":356 return getSession("chrome");357 case "geckodriver":358 return getSession("firefox");359 case "safaridriver":360 return getSession("safari");361 case "msedgedriver":362 case "mswebdriver":363 return getSession("edge");364 case "iedriver":365 return getSession("internet explorer");366 default:367 // else user has to specify full payload via webDriverSession368 return getSession(type);369 }370 }371 public static String preProcessWildCard(String locator) {372 boolean contains;373 String tag, prefix, text;374 int index;375 int pos = locator.indexOf('}');376 if (pos == -1) {377 throw new RuntimeException("bad locator prefix: " + locator);378 }379 if (locator.charAt(1) == '^') {380 contains = true;381 prefix = locator.substring(2, pos);382 } else {383 contains = false;384 prefix = locator.substring(1, pos);385 }386 text = locator.substring(pos + 1);387 pos = prefix.indexOf(':');388 if (pos != -1) {389 String tagTemp = prefix.substring(0, pos);390 tag = tagTemp.isEmpty() ? "*" : tagTemp;391 String indexTemp = prefix.substring(pos + 1);392 if (indexTemp.isEmpty()) {393 index = 0;394 } else {395 try {396 index = Integer.valueOf(indexTemp);397 } catch (Exception e) {398 throw new RuntimeException("bad locator prefix: " + locator + ", " + e.getMessage());399 }400 }401 } else {402 tag = prefix.isEmpty() ? "*" : prefix;403 index = 0;404 }405 if (!tag.startsWith("/")) {406 tag = "//" + tag;407 }408 String xpath;409 if (contains) {410 xpath = tag + "[contains(normalize-space(text()),'" + text + "')]";411 } else {412 xpath = tag + "[normalize-space(text())='" + text + "']";413 }414 if (index == 0) {415 return xpath;416 }417 return "/(" + xpath + ")[" + index + "]";418 }419 private static final String DOCUMENT = "document";420 public static String selector(String locator) {421 return selector(locator, DOCUMENT);422 }423 public static String selector(String locator, String contextNode) {424 if (locator.startsWith("(")) {425 return locator; // pure js !426 }427 if (locator.startsWith("{")) {428 locator = preProcessWildCard(locator);429 }430 if (locator.startsWith("/")) { // XPathResult.FIRST_ORDERED_NODE_TYPE = 9431 if (locator.startsWith("/(")) { // hack for wildcard with index (see preProcessWildCard last line)432 if (DOCUMENT.equals(contextNode)) {433 locator = locator.substring(1);434 } else {435 locator = "(." + locator.substring(2);436 }437 } else if (!DOCUMENT.equals(contextNode)) {438 locator = "." + locator; // evaluate relative to this node not root439 }440 return "document.evaluate(\"" + locator + "\", " + contextNode + ", null, 9, null).singleNodeValue";441 }442 return contextNode + ".querySelector(\"" + locator + "\")";443 }444 public void setTimeout(Integer timeout) {445 this.timeoutOverride = timeout;446 }447 public int getTimeout() {448 if (timeoutOverride != null) {449 return timeoutOverride;450 }451 return timeout;452 }453 public void setRetryInterval(Integer retryInterval) {454 this.retryInterval = retryInterval;455 }456 public int getRetryInterval() {457 if (retryInterval != null) {458 return retryInterval;459 }460 ScenarioEngine engine = ScenarioEngine.get();461 if (engine == null) {462 return Config.DEFAULT_RETRY_INTERVAL;463 } else {464 return engine.getConfig().getRetryInterval();465 }466 }467 public int getRetryCount() {468 if (retryCount != null) {469 return retryCount;470 }471 ScenarioEngine engine = ScenarioEngine.get();472 if (engine == null) {473 return Config.DEFAULT_RETRY_COUNT;474 } else {475 return ScenarioEngine.get().getConfig().getRetryCount();476 }477 }478 public <T> T retry(Supplier<T> action, Predicate<T> condition, String logDescription, boolean failWithException) {479 long startTime = System.currentTimeMillis();480 int count = 0, max = getRetryCount();481 T result;482 boolean success;483 do {484 if (count > 0) {485 logger.debug("{} - retry #{}", logDescription, count);486 sleep();487 }488 result = action.get();489 success = condition.test(result);490 } while (!success && count++ < max);491 if (!success) {492 long elapsedTime = System.currentTimeMillis() - startTime;493 String message = logDescription + ": failed after " + (count - 1) + " retries and " + elapsedTime + " milliseconds";494 logger.warn(message);495 if (failWithException) {496 throw new RuntimeException(message);497 }498 }499 return result;500 }501 public static String wrapInFunctionInvoke(String text) {502 return "(function(){ " + text + " })()";503 }504 private static final String HIGHLIGHT_FN = "function(e){ var old = e.getAttribute('style');"505 + " e.setAttribute('style', 'background: yellow; border: 2px solid red;');"506 + " setTimeout(function(){ e.setAttribute('style', old) }, %d) }";507 private static String highlightFn(int millis) {508 return String.format(HIGHLIGHT_FN, millis);509 }510 public String highlight(String locator, int millis) {511 String e = selector(locator);512 String temp = "var e = " + e + "; var fun = " + highlightFn(millis) + "; fun(e)";513 return wrapInFunctionInvoke(temp);514 }515 public String highlightAll(String locator, int millis) {516 return scriptAllSelector(locator, highlightFn(millis));517 }518 public String optionSelector(String locator, String text) {519 boolean textEquals = text.startsWith("{}");520 boolean textContains = text.startsWith("{^}");521 String condition;522 if (textEquals || textContains) {523 text = text.substring(text.indexOf('}') + 1);524 condition = textContains ? "e.options[i].text.indexOf(t) !== -1" : "e.options[i].text === t";525 } else {526 condition = "e.options[i].value === t";527 }528 String e = selector(locator);529 String temp = "var e = " + e + "; var t = \"" + text + "\";"530 + " for (var i = 0; i < e.options.length; ++i)"531 + " if (" + condition + ") { e.options[i].selected = true; e.dispatchEvent(new Event('change')) }";532 return wrapInFunctionInvoke(temp);533 }534 public String optionSelector(String id, int index) {535 String e = selector(id);536 String temp = "var e = " + e + "; var t = " + index + ";"537 + " for (var i = 0; i < e.options.length; ++i)"538 + " if (i === t) { e.options[i].selected = true; e.dispatchEvent(new Event('change')) }";539 return wrapInFunctionInvoke(temp);540 }541 private String fun(String expression) {542 char first = expression.charAt(0);543 return (first == '_' || first == '!') ? "function(_){ return " + expression + " }" : expression;544 }545 public String scriptSelector(String locator, String expression) {546 return scriptSelector(locator, expression, DOCUMENT);547 }548 public String scriptSelector(String locator, String expression, String contextNode) {549 String temp = "var fun = " + fun(expression) + "; var e = " + selector(locator, contextNode) + "; return fun(e)";550 return wrapInFunctionInvoke(temp);551 }552 public String scriptAllSelector(String locator, String expression) {553 return scriptAllSelector(locator, expression, DOCUMENT);554 }555 // the difference here from selector() is the use of querySelectorAll()556 // how the loop for XPath results has to be handled557 public String scriptAllSelector(String locator, String expression, String contextNode) {558 if (locator.startsWith("{")) {559 locator = preProcessWildCard(locator);560 }561 boolean isXpath = locator.startsWith("/");562 String selector;563 if (isXpath) { // XPathResult.ORDERED_NODE_ITERATOR_TYPE = 5564 selector = "document.evaluate(\"" + locator + "\", " + contextNode + ", null, 5, null)";565 } else {566 selector = contextNode + ".querySelectorAll(\"" + locator + "\")";567 }568 String temp = "var res = []; var fun = " + fun(expression) + "; var es = " + selector + "; ";569 if (isXpath) {570 temp = temp + "var e = null; while(e = es.iterateNext()) res.push(fun(e)); return res";571 } else {572 temp = temp + "es.forEach(function(e){ res.push(fun(e)) }); return res";573 }574 return wrapInFunctionInvoke(temp);575 }576 public void sleep() {577 sleep(getRetryInterval());578 }579 public void sleep(int millis) {580 if (millis == 0) {581 return;582 }583 try {584 processLogger.trace("sleeping for millis: {}", millis);585 Thread.sleep(millis);586 } catch (Exception e) {587 throw new RuntimeException(e);588 }589 }590 public static String getPositionJs(String locator) {591 String temp = "var r = " + selector(locator, DOCUMENT) + ".getBoundingClientRect();"592 + " var dx = window.scrollX; var dy = window.scrollY;"593 + " return { x: r.x + dx, y: r.y + dy, width: r.width + dx, height: r.height + dy }";594 return wrapInFunctionInvoke(temp);595 }596 public Map<String, Object> newMapWithSelectedKeys(Map<String, Object> map, String... keys) {597 Map<String, Object> out = new HashMap(keys.length);598 for (String key : keys) {599 Object o = map.get(key);600 if (o != null) {601 out.put(key, o);602 }603 }604 return out;605 }606 public void disableRetry() {607 retryEnabled = false;608 retryCount = null;609 retryInterval = null;610 }611 public void enableRetry(Integer count, Integer interval) {612 retryEnabled = true;613 retryCount = count; // can be null614 retryInterval = interval; // can be null615 }616 public Element waitUntil(Driver driver, String locator, String expression) {617 long startTime = System.currentTimeMillis();618 String js = scriptSelector(locator, expression);619 boolean found = driver.waitUntil(js);620 if (!found) {621 long elapsedTime = System.currentTimeMillis() - startTime;622 throw new RuntimeException("wait failed for: " + locator623 + " and condition: " + expression + " after " + elapsedTime + " milliseconds");624 }625 return DriverElement.locatorExists(driver, locator);626 }627 public String waitForUrl(Driver driver, String expected) {628 return retry(() -> driver.getUrl(), url -> url.contains(expected), "waitForUrl", true);629 }630 public Element waitForAny(Driver driver, String... locators) {631 long startTime = System.currentTimeMillis();632 List<String> list = Arrays.asList(locators);633 Iterator<String> iterator = list.iterator();634 StringBuilder sb = new StringBuilder();635 while (iterator.hasNext()) {636 String locator = iterator.next();637 String js = selector(locator);638 sb.append("(").append(js).append(" != null)");639 if (iterator.hasNext()) {640 sb.append(" || ");641 }642 }643 boolean found = driver.waitUntil(sb.toString());644 // important: un-set the retry flag645 disableRetry();646 if (!found) {647 long elapsedTime = System.currentTimeMillis() - startTime;648 throw new RuntimeException("wait failed for: " + list + " after " + elapsedTime + " milliseconds");649 }650 if (locators.length == 1) {651 return DriverElement.locatorExists(driver, locators[0]);652 }653 for (String locator : locators) {654 Element temp = driver.optional(locator);655 if (temp.isPresent()) {656 return temp;657 }658 }659 // this should never happen660 throw new RuntimeException("unexpected wait failure for locators: " + list);661 }662 public Element optional(Driver driver, String locator) {663 String js = selector(locator);664 String evalJs = js + " != null";665 Object o = driver.script(evalJs);666 if (o instanceof Boolean && (Boolean) o) {667 return DriverElement.locatorExists(driver, locator);668 } else {669 return new MissingElement(driver, locator);670 }671 }672 public static String karateLocator(String karateRef) {673 return "(document._karate." + karateRef + ")";674 }675 public String focusJs(String locator) {676 return "var e = " + selector(locator) + "; e.focus(); try { e.selectionStart = e.selectionEnd = e.value.length } catch(x) {}";677 }678 public List<Element> findAll(Driver driver, String locator) {679 List<String> list = driver.scriptAll(locator, DriverOptions.KARATE_REF_GENERATOR);680 List<Element> elements = new ArrayList(list.size());681 for (String karateRef : list) {682 String karateLocator = karateLocator(karateRef);683 elements.add(DriverElement.locatorExists(driver, karateLocator));684 }685 return elements;686 }687}...
Source:Chrome.java
...35import com.intuit.karate.StringUtils;36import com.intuit.karate.core.ScenarioEngine;37import com.intuit.karate.core.ScenarioRuntime;38import com.intuit.karate.core.Variable;39import com.intuit.karate.driver.DevToolsDriver;40import com.intuit.karate.driver.DevToolsMessage;41import com.intuit.karate.driver.Driver;42import com.intuit.karate.driver.DriverOptions;43import com.intuit.karate.driver.Input;44import com.intuit.karate.driver.Keys;45import com.intuit.karate.http.Response;46import com.intuit.karate.shell.Command;47import asura.ui.driver.DriverProvider;48import asura.ui.karate.KarateRunner;49/**50 * @author pthomas351 */52public class Chrome extends DevToolsDriver {53 private static Logger logger = LoggerFactory.getLogger(Chrome.class);54 public static final String DEFAULT_PATH_MAC = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome";55 public static final String DEFAULT_PATH_WIN = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe";56 public static final String DEFAULT_PATH_LINUX = "/usr/bin/google-chrome";57 public Driver parent; // used in 'DriverPoolActor'58 public ScenarioEngine engine;59 public Boolean inject;60 public Consumer<Map<String, Object>> filter;61 public Chrome(DriverOptions options, Command command, String webSocketUrl) {62 super(options, command, webSocketUrl);63 }64 // èªå®ä¹65 public Chrome(DriverOptions options, Command command, String webSocketUrl,66 ScenarioEngine engine, Boolean inject, Consumer<Map<String, Object>> filter67 ) {68 super(options, command, webSocketUrl);69 this.engine = engine;70 this.inject = inject;71 this.filter = filter;72 if (this.inject && this.engine != null) {73 this.engine.setDriver(this);74 }75 client.setTextHandler(text -> {76 Map<String, Object> map = Json.of(text).value();77 DevToolsMessage dtm = new DevToolsMessage(this, map);78 if (this.filter != null && !StringUtils.isBlank(dtm.getMethod())) {79 this.filter.accept(map);80 }81 receive(dtm);82 return false; // no async signalling, for normal use, e.g. chrome developer tools83 });84 }85 public void closeClient() {86 client.close();87 }88 public void enableLog() {89 method("Log.enable").send();90 }91 public void enableDom() {92 method("DOM.enable").send();93 }94 public void setDiscoverTargets() {95 method("Target.setDiscoverTargets").param("discover", true).send();96 }97 public String screenshotAsBase64() {98 Variable result = method("Page.captureScreenshot").send().getResult("data");99 if (result != null) {100 return result.getAsString();101 } else {102 return null;103 }104 }105 public DevToolsMessage openNewPage(String url) {106 return method("Target.createTarget")107 .param("url", url)108 .param("newWindow", false)109 .param("background", true)110 .send();111 }112 public List<Map<String, Object>> getJsonPageTargets() {113 Http http = options.getHttp();114 Command.waitForHttp(http.urlBase + "/json");115 Response res = http.path("json").get();116 List<Map<String, Object>> targets = res.json().asList();117 return targets;118 }119 public void goToTop(Integer idx) {120 List<Map<String, Object>> targets = getJsonPageTargets();121 if (targets.size() > idx) {122 Map<String, Object> target = targets.get(idx);123 reconnect((String) target.get("webSocketDebuggerUrl"));124 } else {125 throw new RuntimeException("only " + targets.size() + " pages.");126 }127 }128 public void switchPage2(String urlOrTitle) {129 if (urlOrTitle.matches("-?(0|[1-9]\\d*)")) { // nums130 goToTop(Integer.parseInt(urlOrTitle));131 } else {132 List<Map<String, Object>> targets = getJsonPageTargets();133 for (Map target : targets) {134 String targetUrl = (String) target.get("url");135 String targetTitle = (String) target.get("title");136 if (targetUrl.contains(urlOrTitle) || targetTitle.contains(urlOrTitle)) {137 reconnect((String) target.get("webSocketDebuggerUrl"));138 break;139 }140 }141 }142 }143 public void closeOthers() {144 DevToolsMessage dtm = method("Target.getTargets").send();145 List<Map> targets = dtm.getResult("targetInfos").getValue();146 if (targets != null) {147 targets.forEach(target -> {148 if ("page".equals(target.get("type"))) {149 String targetId = target.getOrDefault("targetId", "").toString();150 if (!rootFrameId.equals(targetId)) {151 method("Target.closeTarget").param("targetId", targetId).sendWithoutWaiting();152 }153 }154 });155 }156 }157 public void sendKey(char c, int modifiers, String type, Integer keyCode) {158 DevToolsMessage dtm = method("Input.dispatchKeyEvent")159 .param("modifiers", modifiers)160 .param("type", type);161 if (keyCode == null) {162 dtm.param("text", c + "");163 } else {164 switch (keyCode) {165 case 13:166 dtm.param("text", "\r"); // important ! \n does NOT work for chrome167 break;168 case 9: // TAB169 if ("char".equals(type)) {170 return; // special case171 }172 dtm.param("text", "");173 break;174 case 46: // DOT175 if ("rawKeyDown".equals(type)) {176 dtm.param("type", "keyDown"); // special case177 }178 dtm.param("text", ".");179 break;180 default:181 dtm.param("text", c + "");182 }183 dtm.param("windowsVirtualKeyCode", keyCode);184 }185 dtm.send();186 }187 public void input(String value) {188 Input input = new Input(value);189 while (input.hasNext()) {190 char c = input.next();191 int modifiers = input.getModifierFlags();192 Integer keyCode = Keys.code(c);193 if (keyCode != null) {194 sendKey(c, modifiers, "rawKeyDown", keyCode);195 sendKey(c, modifiers, "char", keyCode);196 sendKey(c, modifiers, "keyUp", keyCode);197 } else {198 sendKey(c, modifiers, "char", -1);199 }200 }201 }202 public static void loadOverride() {203 logger.info("use override chrome");204 }205 @Override206 public void quit() {207 DriverProvider provider = DriverOptions.getDriverProvider();208 if (provider != null) {209 provider.release(this);210 } else {211 super.quit();212 }213 }214 public void quit(Boolean force) {215 if (force) {216 super.quit();217 }218 }219 public static Chrome start(Map<String, Object> map, ScenarioRuntime sr) {220 DriverOptions options = new DriverOptions(map, sr, 9222,221 FileUtils.isOsWindows() ? DEFAULT_PATH_WIN : FileUtils.isOsMacOsX() ? DEFAULT_PATH_MAC : DEFAULT_PATH_LINUX);222 options.arg("--remote-debugging-port=" + options.port);223 options.arg("--no-first-run");224 options.arg("--disable-translate");225 options.arg("--disable-notifications");226 options.arg("--disable-infobars");227 options.arg("--disable-gpu");228 options.arg("--dbus-stub");229 options.arg("--disable-dev-shm-usage");230 if (options.userDataDir != null) {231 options.arg("--user-data-dir=" + options.userDataDir);232 }233 options.arg("--disable-popup-blocking");234 if (options.headless) {...
Source:EdgeDevToolsDriver.java
...25import com.intuit.karate.Http;26import com.intuit.karate.LogAppender;27import com.intuit.karate.core.ScenarioContext;28import com.intuit.karate.shell.Command;29import com.intuit.karate.driver.DevToolsDriver;30import com.intuit.karate.driver.DriverElement;31import com.intuit.karate.driver.DriverOptions;32import com.intuit.karate.driver.Element;33import java.util.Map;34/**35 *36 * @author pthomas337 */38public class EdgeDevToolsDriver extends DevToolsDriver {39 public EdgeDevToolsDriver(DriverOptions options, Command command, String webSocketUrl) {40 super(options, command, webSocketUrl);41 }42 public static EdgeDevToolsDriver start(ScenarioContext context, Map<String, Object> map, LogAppender appender) {43 DriverOptions options = new DriverOptions(context, map, appender, 9222, "MicrosoftEdge");44 options.arg("--devtools-server-port");45 options.arg(options.port + "");46 options.arg("about:blank");47 Command command = options.startProcess();48 Http http = options.getHttp();49 String webSocketUrl = http.path("json", "list").get()50 .jsonPath("get[0] $[?(@.type=='Page')].webSocketDebuggerUrl").asString();51 EdgeDevToolsDriver edge = new EdgeDevToolsDriver(options, command, webSocketUrl);52 // edge.activate(); // not supported53 edge.enablePageEvents();54 return edge;55 }56 @Override57 public void activate() {58 // not supported apparently59 }60 @Override61 public void setUrl(String url) {62 method("Page.navigate").param("url", url).send();63 currentUrl = url;64 }65 @Override66 public Element input(String locator, String value) {67 eval(options.selector(locator) + ".value = \"" + value + "\"");68 return DriverElement.locatorExists(this, locator);69 }70 @Override71 public void close() {72 // eval("window.close()", null); // this brings up an alert73 }74 @Override75 public void quit() {76 close();77 if (command != null) {78 // TODO this does not work because the command never blocks on windows79 command.close(true);80 }81 }82}...
Driver
Using AI Code Generation
1import com.intuit.karate.driver.Driver;2import com.intuit.karate.driver.DriverOptions;3import com.intuit.karate.driver.chrome.ChromeDriver;4import com.intuit.karate.driver.chrome.ChromeOptions;5import com.intuit.karate.driver.chrome.ChromeDevTools;6import com.intuit.karate.driver.chrome.ChromeDevTools.Page;7import com.intuit.karate.driver.chrome.ChromeDevTools.Network;8import com.intuit.karate.driver.chrome.ChromeDevTools.Network.RequestWillBeSent;9import com.intuit.karate.driver.chrome.ChromeDevTools.Network.ResponseReceived;10import com.intuit.karate.driver.chrome.ChromeDevTools.Network.RequestPattern;11import com.intuit.karate.driver.chrome.ChromeDevTools.Network.RequestInterception;12import com.intuit.karate.driver.chrome.ChromeDevTools.Network.RequestInterceptionResponse;13import com.intuit.karate.driver.chrome.ChromeDevTools.Network.RequestInterceptionResponseBuilder;14import com.intuit.karate.driver.chrome.ChromeDevTools.Network.RequestInterceptionResponseContinue;15import com.intuit.karate.driver.chrome.ChromeDevTools.Network.RequestInterceptionResponseContinueBuilder;16import com.intuit.karate.driver.chrome.ChromeDevTools.Network.RequestInterceptionResponseContinueBuilder;17import com.intuit.karate.FileUtils;18import java.util.Arrays;19import java.util.List;20import java.util.ArrayList;21import java.util.Collections;22import java.util.Map;23import java.util.HashMap;24import java.util.concurrent.TimeUnit;25import org.apache.commons.io.IOUtils;26import org.apache.commons.lang3.StringUtils;27import org.slf4j.Logger;28import org.slf4j.LoggerFactory;29import java.io.InputStream;30import java.io.FileInputStream;31import java.io.FileOutputStream;32import java.io.IOException;33import java.io.File;34import java.io.BufferedReader;35import java.io.InputStreamReader;36import java.io.OutputStream;37import java.io.PrintWriter;38import java.io.BufferedWriter;39import java.io.FileWriter;40import java.net.URL;41import java.net.URLConnection;42import java.net.HttpURLConnection;43import java.net.URLDecoder;44import java.nio.charset.StandardCharsets;45import java.util.Base64;46import java.util.concurrent.atomic.AtomicInteger;47import java.util.concurrent.atomic.AtomicReference;48import java.util.regex.Matcher;49import java.util.regex.Pattern;50import java.util.zip.GZIPInputStream;51import java.util.zip.ZipEntry;52import java.util.zip.ZipInputStream;53import java.util.zip.ZipOutputStream;54import java.util.zip.GZIPOutputStream;55import java.util.zip.DeflaterOutputStream;56import java.util.zip
Driver
Using AI Code Generation
1import com.intuit.karate.driver.Driver;2import com.intuit.karate.driver.DriverOptions;3import com.intuit.karate.driver.chrome.ChromeDriver;4import com.intuit.karate.driver.chrome.ChromeOptions;5import com.intuit.karate.driver.chrome.ChromeOptionsBuilder;6import com.intuit.karate.driver.chrome.ChromeDriverService;7import com.intuit.karate.driver.chrome.ChromeDriverServiceBuilder;8import org.openqa.selenium.WebDriver;9import org.openqa.selenium.chrome.ChromeDriver;10import org.openqa.selenium.chrome.ChromeOptions;11import org.openqa.selenium.chrome.ChromeDriverService;12import org.openqa.selenium.chrome.ChromeDriverServiceBuilder;13import java.io.File;14import java.util.HashMap;15import java.util.Map;16import java.util.concurrent.TimeUnit;17public class 4 {18 public static void main(String[] args) {19 System.setProperty("webdriver.chrome.driver", "C:\\Users\\srikanth\\Downloads\\chromedriver_win32\\chromedriver.exe");20 System.setProperty("webdriver.chrome.driver", "C:\\Users\\srikanth\\Downloads\\chromedriver_win32\\chromedriver.exe");21 System.setProperty("webdriver.chrome.driver", "C:\\Users\\srikanth\\Downloads\\chromedriver_win32\\chromedriver.exe");22 System.setProperty("webdriver.chrome.driver", "C:\\Users\\srikanth\\Downloads\\chromedriver_win32\\chromedriver.exe");23 System.setProperty("webdriver.chrome.driver", "C:\\Users\\srikanth\\Downloads\\chromedriver_win32\\chromedriver.exe");24 System.setProperty("webdriver.chrome.driver", "C:\\Users\\srikanth\\Downloads\\chromedriver_win32\\chromedriver.exe");25 System.setProperty("webdriver.chrome.driver", "C:\\Users\\srikanth\\Downloads\\chromedriver_win32\\chromedriver.exe");26 System.setProperty("webdriver.chrome.driver", "C:\\Users\\srikanth\\Downloads\\chromedriver_win32\\chromedriver.exe");
Driver
Using AI Code Generation
1import com.intuit.karate.driver.Driver;2import com.intuit.karate.driver.chrome.Chrome;3import com.intuit.karate.driver.chrome.ChromeOptions;4import com.intuit.karate.driver.chrome.ChromeDriver;5import com.intuit.karate.driver.chrome.ChromeDriverOptions;6import com.intuit.karate.driver.Driver;7import com.intuit.karate.driver.chrome.Chrome;8import com.intuit.karate.driver.chrome.ChromeOptions;9import com.intuit.karate.driver.chrome.ChromeDriver;10import com.intuit.karate.driver.chrome.ChromeDriverOptions;11import com.intuit.karate.driver.Driver;12import com.intuit.karate.driver.chrome.Chrome;13import com.intuit.karate.driver.chrome.ChromeOptions;14import com.intuit.karate.driver.chrome.ChromeDriver;15import com.intuit.karate.driver.chrome.ChromeDriverOptions;16import com.intuit.karate.driver.Driver;17import com.intuit.karate.driver.chrome.Chrome;18import com.intuit.karate.driver.chrome.ChromeOptions;19import com.intuit.karate.driver.chrome.ChromeDriver;20import com.intuit.karate.driver.chrome.ChromeDriverOptions;21import com.intuit.karate.driver.Driver;22import com.intuit.karate.driver.chrome.Chrome;23import com.intuit.karate.driver.chrome.ChromeOptions;24import com.intuit.karate.driver.chrome.ChromeDriver;25import com.intuit.karate.driver.chrome.ChromeDriverOptions;26import com.intuit.karate.driver.Driver;27import com.intuit.karate.driver.chrome.Chrome;28import com.intuit.karate.driver.chrome.ChromeOptions;29import com.intuit.karate.driver.chrome.ChromeDriver;30import com.intuit.karate.driver.chrome.ChromeDriverOptions;31import com.intuit.karate.driver.Driver;32import com.intuit.karate.driver.chrome.Chrome;33import com.intuit.karate.driver.chrome.ChromeOptions;34import com.intuit.karate.driver.chrome.ChromeDriver;35import com.intuit.karate.driver.chrome
Driver
Using AI Code Generation
1import com.intuit.karate.driver.Driver;2import com.intuit.karate.driver.chrome.Chrome;3import com.intuit.karate.driver.chrome.ChromeOptions;4import com.intuit.karate.driver.chrome.ChromeDriver;5import com.intuit.karate.driver.chrome.ChromeDriverService;6import com.intuit.karate.driver.chrome.ChromeDriverService.Builder;7import com.intuit.karate.driver.chrome.ChromeDriverService.Builder;8import
Driver
Using AI Code Generation
1import com.intuit.karate.driver.Driver;2import com.intuit.karate.driver.chrome.ChromeDriver;3import com.intuit.karate.driver.chrome.ChromeDriverOptions;4import com.intuit.karate.driver.chrome.ChromeDriverService;5import com.intuit.karate.driver.chrome.ChromeOptions;6import com.intuit.karate.driver.chrome.ChromeService;7import com.intuit.karate.driver.chrome.ChromeServiceOptions;8import com.intuit.karate.driver.chrome.ChromeServiceOptionsBuilder;9public class 4 {10 public static void main(String[] args) {11 ChromeServiceOptions chromeServiceOptions = ChromeServiceOptionsBuilder.builder().build();12 ChromeService chromeService = new ChromeService(chromeServiceOptions);13 ChromeOptions chromeOptions = new ChromeOptions();14 ChromeDriverOptions chromeDriverOptions = new ChromeDriverOptions(chromeOptions);15 ChromeDriver chromeDriver = new ChromeDriver(chromeDriverOptions, chromeService);16 Driver driver = new Driver(chromeDriver);17 driver.quit();18 }19}20import com.intuit.karate.driver.Driver;21import com.intuit.karate.driver.chrome.ChromeDriver;22import com.intuit.karate.driver.chrome.ChromeDriverOptions;23import com.intuit.karate.driver.chrome.ChromeDriverService;24import com.intuit.karate.driver.chrome.ChromeOptions;25import com.intuit.karate.driver.chrome.ChromeService;26import com.intuit.karate.driver.chrome.ChromeServiceOptions;27import com.intuit.karate.driver.chrome.ChromeServiceOptionsBuilder;28public class 5 {29 public static void main(String[] args) {30 ChromeServiceOptions chromeServiceOptions = ChromeServiceOptionsBuilder.builder().build();31 ChromeService chromeService = new ChromeService(chromeServiceOptions);32 ChromeOptions chromeOptions = new ChromeOptions();33 ChromeDriverOptions chromeDriverOptions = new ChromeDriverOptions(chromeOptions);34 ChromeDriver chromeDriver = new ChromeDriver(chromeDriverOptions, chromeService);35 Driver driver = new Driver(chromeDriver);36 driver.quit();37 }38}39import com.intuit.karate.driver.Driver;40import com.intuit.karate.driver.chrome.ChromeDriver;41import com
Driver
Using AI Code Generation
1import com.intuit.karate.driver.Driver;2import com.intuit.karate.driver.chrome.ChromeDriver;3import com.intuit.karate.driver.chrome.ChromeOptions;4import com.intuit.karate.driver.chrome.ChromeOptionsBuilder;5import com.intuit.karate.driver.chrome.Chrome;6import com.intuit.karate.driver.chrome.ChromeDriverService;7public class 4 {8 public static void main(String[] args) {9 ChromeOptions options = new ChromeOptionsBuilder().addArguments("--headless").build();10 ChromeDriverService service = new ChromeDriverService.Builder().withSilent(true).build();11 ChromeDriver driver = new ChromeDriver(service, options);12 System.out.println("Page title is: " + driver.getTitle());13 driver.quit();14 }15}16import com.intuit.karate.driver.Driver;17import com.intuit.karate.driver.chrome.ChromeDriver;18import com.intuit.karate.driver.chrome.ChromeOptions;19import com.intuit.karate.driver.chrome.ChromeOptionsBuilder;20import com.intuit.karate.driver.chrome.Chrome;21import com.intuit.karate.driver.chrome.ChromeDriverService;22public class 5 {23 public static void main(String[] args) {24 ChromeOptions options = new ChromeOptionsBuilder().addArguments("--headless").build();25 ChromeDriverService service = new ChromeDriverService.Builder().withSilent(true).build();26 ChromeDriver driver = new ChromeDriver(service, options);27 System.out.println("Page title is: " + driver.getTitle());28 driver.quit();29 }30}31import com.intuit.karate.driver.Driver;32import com.intuit.karate.driver.chrome.ChromeDriver;33import com.intuit.karate.driver.chrome.ChromeOptions;34import com.intuit.karate.driver.chrome.ChromeOptionsBuilder;35import com.intuit.karate.driver.chrome.Chrome;36import com.intuit.karate.driver.chrome.ChromeDriverService;37public class 6 {38 public static void main(String[] args) {39 ChromeOptions options = new ChromeOptionsBuilder().addArguments("--headless").build();40 ChromeDriverService service = new ChromeDriverService.Builder().withSilent(true
Driver
Using AI Code Generation
1import com.intuit.karate.driver.Driver;2import com.intuit.karate.driver.chrome.Chrome;3import com.intuit.karate.driver.chrome.ChromeOptions;4public class 4 {5 public static void main(String[] args) {6 ChromeOptions options = new ChromeOptions();7 options.setHeadless(true);8 Driver driver = Chrome.start(options);9 System.out.println(driver.getTitle());10 driver.quit();11 }12}13import com.intuit.karate.driver.Driver;14import com.intuit.karate.driver.chrome.Chrome;15import com.intuit.karate.driver.chrome.ChromeOptions;16public class 5 {17 public static void main(String[] args) {18 ChromeOptions options = new ChromeOptions();19 options.setHeadless(true);20 Driver driver = Chrome.start(options);21 System.out.println(driver.getTitle());22 driver.quit();23 }24}25import com.intuit.karate.driver.Driver;26import com.intuit.karate.driver.chrome.Chrome;27import com.intuit.karate.driver.chrome.ChromeOptions;28public class 6 {29 public static void main(String[] args) {30 ChromeOptions options = new ChromeOptions();31 options.setHeadless(true);32 Driver driver = Chrome.start(options);33 System.out.println(driver.getTitle());34 driver.quit();35 }36}37import com.intuit.karate.driver.Driver;38import com.intuit.karate.driver.chrome.Chrome;39import com.intuit.karate.driver.chrome.ChromeOptions;40public class 7 {41 public static void main(String[] args) {42 ChromeOptions options = new ChromeOptions();43 options.setHeadless(true);44 Driver driver = Chrome.start(options);45 System.out.println(driver.getTitle());46 driver.quit();47 }48}49import com.intuit.karate.driver.Driver;50import com.intuit.karate.driver.chrome.Chrome;51import com.intuit.k
Driver
Using AI Code Generation
1import com.intuit.karate.driver.Driver;2import com.intuit.karate.driver.DriverOptions;3import com.intuit.karate.driver.DriverOptions.DriverType;4import com.intuit.karate.driver.chrome.ChromeDriver;5import com.intuit.karate.driver.chrome.ChromeOptions;6import com.intuit.karate.driver.chrome.ChromeOptions.PlatformType;7import com.intuit.karate.driver.chrome.ChromeOptions.WindowSize;8import com.intuit.karate.driver.chrome.ChromeOptions.WindowSizeType;9public class 4 {10 public static void main(String[] args) {11 ChromeOptions options = new ChromeOptions();12 options.setPlatform(PlatformType.LINUX);13 options.setWindowSize(new WindowSize(1024, 768, WindowSizeType.PIXELS));14 options.setHeadless(true);15 DriverOptions driverOptions = new DriverOptions(DriverType.CHROME, options);16 try (Driver driver = new ChromeDriver(driverOptions)) {17 System.out.println(driver.getTitle());18 }19 }20}21import com.intuit.karate.driver.Driver;22import com.intuit.karate.driver.DriverOptions;23import com.intuit.karate.driver.DriverOptions.DriverType;24import com.intuit.karate.driver.chrome.ChromeDriver;25import com.intuit.karate.driver.chrome.ChromeOptions;26import com.intuit.karate.driver.chrome.ChromeOptions.PlatformType;27import com.intuit.karate.driver.chrome.ChromeOptions.WindowSize;28import com.intuit.karate.driver.chrome.ChromeOptions.WindowSizeType;29public class 5 {30 public static void main(String[] args) {31 ChromeOptions options = new ChromeOptions();32 options.setPlatform(PlatformType.LINUX);33 options.setWindowSize(new WindowSize(1024, 768, WindowSizeType.PIXELS));34 options.setHeadless(true);35 DriverOptions driverOptions = new DriverOptions(DriverType.CHROME, options);36 try (Driver driver = new ChromeDriver(driverOptions)) {37 System.out.println(driver.getTitle());38 }39 }40}41import com.intuit.karate.driver.Driver;42import com.intuit.karate.driver
Driver
Using AI Code Generation
1import com.intuit.karate.driver.DriverOptions;2import com.intuit.karate.driver.DriverOptions.DriverType;3import com.intuit.karate.driver.chrome.ChromeDriver;4import com.intuit.karate.driver.chrome.ChromeOptions;5import com.intuit.karate.driver.chrome.ChromeOptions.PlatformType;6import com.intuit.karate.driver.chrome.ChromeOptions.WindowSize;7import com.intuit.karate.driver.chrome.ChromeOptions.WindowSizeType;8public class 4 {9 public static void main(String[] args) {10 ChromeOptions options = new ChromeOptions();11 options.setPlatform(PlatformType.LINUX);12 options.setWindowSize(new WindowSize(1024, 768, WindowSizeType.PIXELS));13 options.setHeadless(true);14 DriverOptions driverOptions = new DriverOptions(DriverType.CHROME, options);15 try (Driver driver = new ChromeDriver(driverOptions)) {16 System.out.println(driver.getTitle());17 }18 }19}20import com.intuit.karate.driver.Driver;21import com.intuit.karate.driver.DriverOptions;22import com.intuit.karate.driver.DriverOptions.DriverType;23import com.intuit.karate.driver.chrome.ChromeDriver;24import com.intuit.karate.driver.chrome.ChromeOptions;25import com.intuit.karate.driver.chrome.ChromeOptions.PlatformType;26import com.intuit.karate.driver.chrome.ChromeOptions.WindowSize;27import com.intuit.karate.driver.chrome.ChromeOptions.WindowSizeType;28public class 5 {29 public static void main(String[] args) {30 ChromeOptions options = new ChromeOptions();31 options.setPlatform(PlatformType.LINUX);32 options.setWindowSize(new WindowSize(1024, 768, WindowSizeType.PIXELS));33 options.setHeadless(true);34 DriverOptions driverOptions = new DriverOptions(DriverType.CHROME, options);35 try (Driver driver = new ChromeDriver(driverOptions)) {36 System.out.println(driver.getTitle());37 }38 }39}40import com.intuit.karate.driver.Driver;41import com.intuit.karate.driver
Driver
Using AI Code Generation
1import com.intuit.karate.driver.Driver;2import com.intuit.karate.driver.chrome.Chrome;3import com.intuit.karate.driver.chrome.ChromeOptions;4public class 4 {5 public static void main(String[] args) {6 ChromeOptions options = new ChromeOptions();7 options.setHeadless(true);8 Driver driver = Chrome.start(options);9 System.out.println(driver.getTitle());10 driver.quit();11 }12}13import com.intuit.karate.driver.Driver;14import com.intuit.karate.driver.chrome.Chrome;15import com.intuit.karate.driver.chrome.ChromeOptions;16public class 5 {17 public static void main(String[] args) {18 ChromeOptions options = new ChromeOptions();19 options.setHeadless(true);20 Driver driver = Chrome.start(options);21 System.out.println(driver.getTitle());22 driver.quit();23 }24}25import com.intuit.karate.driver.Driver;26import com.intuit.karate.driver.chrome.Chrome;27import com.intuit.karate.driver.chrome.ChromeOptions;28public class 6 {29 public static void main(String[] args) {30 ChromeOptions options = new ChromeOptions();31 options.setHeadless(true);32 Driver driver = Chrome.start(options);33 System.out.println(driver.getTitle());34 driver.quit();35 }36}37import com.intuit.karate.driver.Driver;38import com.intuit.karate.driver.chrome.Chrome;39import com.intuit.karate.driver.chrome.ChromeOptions;40public class 7 {41 public static void main(String[] args) {42 ChromeOptions options = new ChromeOptions();43 options.setHeadless(true);44 Driver driver = Chrome.start(options);45 System.out.println(driver.getTitle());46 driver.quit();47 }48}49import com.intuit.karate.driver.Driver;50import com.intuit.karate.driver.chrome.Chrome;51import com.intuit.k
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!