How to use start method of com.intuit.karate.driver.Driver class

Best Karate code snippet using com.intuit.karate.driver.Driver.start

Source:DriverOptions.java Github

copy

Full Screen

...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 }...

Full Screen

Full Screen

Source:Chrome.java Github

copy

Full Screen

...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) {235 options.arg("--headless");236 }237 Command command = options.startProcess();238 String webSocketUrl = null;239 if (map.containsKey("debuggerUrl")) {240 webSocketUrl = (String) map.get("debuggerUrl");241 } else {242 Object targetId = map.get("targetId");243 Object startUrl = map.get("startUrl");244 Object top = map.get("top");245 Http http = options.getHttp();246 Command.waitForHttp(http.urlBase + "/json");247 Response res = http.path("json").get();248 if (res.json().asList().isEmpty()) {249 if (command != null) {250 command.close(true);251 }252 throw new RuntimeException("chrome server returned empty list from " + http.urlBase);253 }254 List<Map<String, Object>> targets = res.json().asList();255 for (Map<String, Object> target : targets) {256 String targetUrl = (String) target.get("url");257 if (targetUrl == null || targetUrl.startsWith("chrome-")) {258 continue;259 }260 if (top != null && top.equals(true)) {261 webSocketUrl = (String) target.get("webSocketDebuggerUrl");262 break;263 } else if (targetId != null) {264 if (targetId.equals(target.get("id"))) {265 webSocketUrl = (String) target.get("webSocketDebuggerUrl");266 break;267 }268 } else if (startUrl != null) {269 String targetTitle = (String) target.get("title");270 if (targetUrl.contains(startUrl.toString()) || targetTitle.contains(startUrl.toString())) {271 webSocketUrl = (String) target.get("webSocketDebuggerUrl");272 break;273 }274 } else {275 String targetType = (String) target.get("type");276 if (!"page".equals(targetType)) {277 continue;278 }279 webSocketUrl = (String) target.get("webSocketDebuggerUrl");280 if (options.attach == null) { // take the first281 break;282 }283 if (targetUrl.contains(options.attach)) {284 break;285 }286 }287 }288 }289 if (webSocketUrl == null) {290 throw new RuntimeException("failed to attach to chrome debug server");291 }292 Boolean inject = (Boolean) map.getOrDefault("_inject", false);293 Consumer<Map<String, Object>> filter = (Consumer<Map<String, Object>>) map.getOrDefault("_filter", null);294 Chrome chrome = new Chrome(options, command, webSocketUrl, sr.engine, inject, filter);295 chrome.activate();296 chrome.enablePageEvents();297 chrome.enableRuntimeEvents();298 chrome.enableTargetEvents();299 chrome.enableLog();300 chrome.setDiscoverTargets();301 if (!options.headless) {302 chrome.initWindowIdAndState();303 }304 return chrome;305 }306 public static Chrome start(Boolean start, Consumer<Map<String, Object>> filter, Boolean inject) {307 Map<String, Object> options = new HashMap();308 options.put("start", start);309 options.put("_inject", inject);310 options.put("_filter", filter);311 return Chrome.start(options, KarateRunner.buildScenarioEngine().runtime);312 }313 public static Chrome start(Map<String, Object> options, Consumer<Map<String, Object>> filter, Boolean inject) {314 options.put("_inject", inject);315 options.put("_filter", filter);316 return Chrome.start(options, KarateRunner.buildScenarioEngine().runtime);317 }318 public static Chrome start(Map<String, Object> options, ScenarioEngine engine, Consumer<Map<String, Object>> filter,319 Boolean inject) {320 options.put("_inject", inject);321 options.put("_filter", filter);322 return Chrome.start(options, engine.runtime);323 }324 public static Chrome start(String chromeExecutablePath, boolean headless) {325 Map<String, Object> options = new HashMap();326 options.put("executable", chromeExecutablePath);327 options.put("headless", headless);328 return Chrome.start(options, null);329 }330 public static Chrome start(Map<String, Object> options) {331 if (options == null) {332 options = new HashMap();333 }334 return Chrome.start(options, null);335 }336 public static Chrome start() {337 return start(null);338 }339 public static Chrome startHeadless() {340 return start(Collections.singletonMap("headless", true));341 }342}...

Full Screen

Full Screen

Source:AndroidDriver.java Github

copy

Full Screen

...19 protected AndroidDriver(DriverOptions options, CommandThread command, Http http, String sessionId, String windowId) {20 super(options, command, http, sessionId, windowId);21 }2223 public static AndroidDriver start(ScenarioContext context, Map<String, Object> map, Logger logger) {24 DriverOptions options = new DriverOptions(context, map, logger, 4723, FileUtils.isOsWindows() ? "cmd.exe" : "appium");25 // additional commands needed to start appium on windows26 if (FileUtils.isOsWindows()){27 options.arg("/C");28 options.arg("cmd.exe");29 options.arg("/K");30 options.arg("appium");31 }32 options.arg("--port=" + options.port);33 CommandThread command = options.startProcess();34 String urlBase = "http://" + options.host + ":" + options.port + "/wd/hub";35 Http http = Http.forUrl(options.driverLogger, urlBase);36 http.config("readTimeout","120000");37 String sessionId = http.path("session")38 .post(Collections.singletonMap("desiredCapabilities", map))39 .jsonPath("get[0] response..sessionId").asString();40 options.driverLogger.debug("init session id: {}", sessionId);41 http.url(urlBase + "/session/" + sessionId);42 AndroidDriver driver = new AndroidDriver(options, command, http, sessionId, null);43 driver.activate();44 return driver;45 }4647 @Override ...

Full Screen

Full Screen

start

Using AI Code Generation

copy

Full Screen

1package com.intuit.karate.driver;2import com.intuit.karate.KarateOptions;3import com.intuit.karate.junit4.Karate;4import cucumber.api.CucumberOptions;5import org.junit.runner.RunWith;6@RunWith(Karate.class)7@KarateOptions(features = "classpath:com/intuit/karate/driver/4.feature")8public class 4Runner {9}10 * def driver = Driver.start()11 * def driver = Driver.start('chrome')12 * def driver = Driver.start('firefox')13 * def driver = Driver.start('phantomjs')14 * def driver = Driver.start('ie')15 * def driver = Driver.start('edge')16 * def driver = Driver.start('htmlunit')17 * def driver = Driver.start('htmlunitwithjs')18 * def driver = Driver.start('safari')19 * def driver = Driver.start('opera')20 * def driver = Driver.start('android')21 * def driver = Driver.start('iphone')22 * def driver = Driver.start('ipad')23 * def driver = Driver.start('phantomjs')

Full Screen

Full Screen

start

Using AI Code Generation

copy

Full Screen

1import com.intuit.karate.driver.Driver;2public class 4 {3 public static void main(String[] args) {4 Driver driver = new Driver();5 driver.start();6 }7}8import com.intuit.karate.driver.Driver;9public class 5 {10 public static void main(String[] args) {11 Driver driver = new Driver();12 driver.start();13 }14}15import com.intuit.karate.driver.Driver;16public class 6 {17 public static void main(String[] args) {18 Driver driver = new Driver();19 driver.start();20 }21}22import com.intuit.karate.driver.Driver;23public class 7 {24 public static void main(String[] args) {25 Driver driver = new Driver();26 driver.start();27 }28}29import com.intuit.karate.driver.Driver;30public class 8 {31 public static void main(String[] args) {32 Driver driver = new Driver();33 driver.start();34 }35}36import com.intuit.karate.driver.Driver;37public class 9 {38 public static void main(String[] args) {39 Driver driver = new Driver();40 driver.start();41 }42}43import com.intuit.karate.driver.Driver;44public class 10 {45 public static void main(String[] args) {46 Driver driver = new Driver();47 driver.start();48 }49}50import com.intuit.karate.driver.Driver;51public class 11 {52 public static void main(String[] args) {53 Driver driver = new Driver();54 driver.start();55 }56}

Full Screen

Full Screen

start

Using AI Code Generation

copy

Full Screen

1import com.intuit.karate.driver.Driver;2import com.intuit.karate.driver.DriverOptions;3import com.intuit.karate.driver.DriverOptions.DriverType;4import com.intuit.karate.driver.DriverOptions.PlatformType;5public class Test {6 public static void main(String[] args) {7 DriverOptions options = new DriverOptions();8 options.setDriverType(DriverType.CHROME);9 options.setPlatformType(PlatformType.WINDOWS);10 options.setHeadless(true);11 Driver driver = new Driver(options);12 driver.start();13 System.out.println(driver.getTitle());14 driver.quit();15 }16}17import com.intuit.karate.driver.Driver;18import com.intuit.karate.driver.DriverOptions;19import com.intuit.karate.driver.DriverOptions.DriverType;20import com.intuit.karate.driver.DriverOptions.PlatformType;21public class Test {22 public static void main(String[] args) {23 DriverOptions options = new DriverOptions();24 options.setDriverType(DriverType.CHROME);25 options.setPlatformType(PlatformType.WINDOWS);26 options.setHeadless(true);27 Driver driver = new Driver(options);28 driver.start();29 System.out.println(driver.getTitle());30 driver.quit();31 }32}33import com.intuit.karate.driver.Driver;34import com.intuit.karate.driver.DriverOptions;35import com.intuit.karate.driver.DriverOptions.DriverType;36import com.intuit.karate.driver.DriverOptions.PlatformType;37public class Test {38 public static void main(String[] args) {39 DriverOptions options = new DriverOptions();40 options.setDriverType(DriverType.CHROME);41 options.setPlatformType(PlatformType.WINDOWS);42 options.setHeadless(true);43 Driver driver = new Driver(options);44 driver.start();45 System.out.println(driver.getTitle());46 driver.quit();47 }48}49import com.intuit.karate.driver.Driver;50import com

Full Screen

Full Screen

start

Using AI Code Generation

copy

Full Screen

1package demo;2import org.junit.Test;3import org.junit.runner.RunWith;4import com.intuit.karate.junit4.Karate;5@RunWith(Karate.class)6public class TestRunner {7 public void testParallel() {8 Driver.start("classpath:demo/5.feature", 5, true);9 }10}11* driver.findElement({id: 'lst-ib'}).sendKeys('karate')12* driver.findElement({name: 'btnK'}).click()13* driver.getTitle() == 'karate - Google Search'14* driver.findElement({id: 'lst-ib'}).sendKeys('karate')15* driver.findElement({name: 'btnK'}).click()16* driver.getTitle() == 'karate - Google Search'17* driver.findElement({id: 'lst-ib'}).sendKeys('karate')18* driver.findElement({name: 'btnK'}).click()19* driver.getTitle() == 'karate - Google Search'20* driver.findElement({id: 'lst-ib'}).sendKeys('karate')21* driver.findElement({name: 'btnK'}).click()22* driver.getTitle() == 'karate - Google Search'23* driver.findElement({id: 'lst-ib'}).sendKeys('karate')24* driver.findElement({name: 'btnK'}).click()25* driver.getTitle() == 'karate - Google Search'

Full Screen

Full Screen

start

Using AI Code Generation

copy

Full Screen

1import org.junit.Test;2import com.intuit.karate.driver.Driver;3import com.intuit.karate.driver.DriverOptions;4public class 4 {5 public void test4() {6 DriverOptions options = new DriverOptions();7 options.set("headless", true);8 options.set("browser", "chrome");9 Driver driver = new Driver(options);10 driver.start();11 driver.quit();12 }13}14import org.junit.Test;15import com.intuit.karate.driver.Driver;16import com.intuit.karate.driver.DriverOptions;17public class 5 {18 public void test5() {19 DriverOptions options = new DriverOptions();20 options.set("headless", true);21 options.set("browser", "chrome");22 Driver driver = new Driver(options);23 driver.start();24 driver.quit();25 }26}27import org.junit.Test;28import com.intuit.karate.driver.Driver;29import com.intuit.karate.driver.DriverOptions;30public class 6 {31 public void test6() {32 DriverOptions options = new DriverOptions();33 options.set("headless", true);34 options.set("browser", "chrome");35 Driver driver = new Driver(options);36 driver.start();37 driver.quit();38 }39}40import org.junit.Test;41import com.intuit.karate.driver.Driver;42import com.intuit.karate.driver.DriverOptions;43public class 7 {44 public void test7() {45 DriverOptions options = new DriverOptions();46 options.set("headless", true);

Full Screen

Full Screen

start

Using AI Code Generation

copy

Full Screen

1package com.intuit.karate.driver;2import org.openqa.selenium.WebDriver;3public class Driver {4 public static void main(String[] args) {5 WebDriver driver = new ChromeDriver().start();6 driver.quit();7 }8}9package com.intuit.karate.driver;10import org.openqa.selenium.WebDriver;11public class Driver {12 public static void main(String[] args) {13 driver.quit();14 }15}16package com.intuit.karate.driver;17import org.openqa.selenium.WebDriver;18public class Driver {19 public static void main(String[] args) {20 driver.quit();21 }22}23package com.intuit.karate.driver;24import org.openqa.selenium.WebDriver;25import org.openqa.selenium.Dimension;26public class Driver {27 public static void main(String[] args) {28 Dimension dimension = new Dimension(500, 500);29 driver.quit();30 }31}32package com.intuit.karate.driver;33import org.openqa.selenium.WebDriver;34import org.openqa.selenium.Dimension;35import org.openqa.selenium.Point;36public class Driver {37 public static void main(String[]

Full Screen

Full Screen

start

Using AI Code Generation

copy

Full Screen

1import com.intuit.karate.driver.Driver;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.chrome.ChromeOptions;4import org.openqa.selenium.remote.RemoteWebDriver;5import java.net.URL;6public class 4 {7 public static void main(String[] args) throws Exception {8 ChromeOptions options = new ChromeOptions();9 options.addArguments("--start-maximized");10 Thread.sleep(5000);11 driver.quit();12 }13}14import com.intuit.karate.driver.Driver;15import org.openqa.selenium.WebDriver;16import org.openqa.selenium.chrome.ChromeOptions;17import org.openqa.selenium.remote.RemoteWebDriver;18import java.net.URL;19public class 5 {20 public static void main(String[] args) throws Exception {21 ChromeOptions options = new ChromeOptions();22 options.addArguments("--start-maximized");23 Thread.sleep(5000);24 driver.quit();25 }26}27import com.intuit.karate.driver.Driver;28import org.openqa.selenium.WebDriver;29import org.openqa.selenium.chrome.ChromeOptions;30import org.openqa.selenium.remote.RemoteWebDriver;31import java.net.URL;32public class 6 {33 public static void main(String[] args) throws Exception {34 ChromeOptions options = new ChromeOptions();35 options.addArguments("--start-maximized");36 Thread.sleep(5000);37 driver.quit();38 }39}40import com.intuit.karate.driver.Driver;41import org.openqa.selenium.WebDriver;42import org.openqa.selenium.chrome.ChromeOptions;43import org.openqa.selenium.remote.RemoteWebDriver;44import java.net.URL;45public class 7 {46 public static void main(String[] args) throws Exception {47 ChromeOptions options = new ChromeOptions();48 options.addArguments("--start-max

Full Screen

Full Screen

start

Using AI Code Generation

copy

Full Screen

1package com.intuit.karate.driver;2import org.openqa.selenium.WebDriver;3public class Driver {4public static void main(String[] args) {5WebDriver driver = Driver.start();6}7}8package com.intuit.karate.driver;9import org.openqa.selenium.WebDriver;10public class Driver {11public static void main(String[] args) {12WebDriver driver = Driver.start();13}14}15package com.intuit.karate.driver;16import org.openqa.selenium.WebDriver;17public class Driver {18public static void main(String[] args) {19WebDriver driver = Driver.start();20}21}22package com.intuit.karate.driver;23import org.openqa.selenium.WebDriver;24public class Driver {25public static void main(String[] args) {26WebDriver driver = Driver.start();27}28}29package com.intuit.karate.driver;30import org.openqa.selenium.WebDriver;31public class Driver {32public static void main(String[] args) {33WebDriver driver = Driver.start();34}35}36package com.intuit.karate.driver;37import org.openqa.selenium.WebDriver;38public class Driver {39public static void main(String[] args) {40WebDriver driver = Driver.start();41}42}43package com.intuit.karate.driver;44import org.openqa.selenium.WebDriver;45public class Driver {46public static void main(String[] args) {47WebDriver driver = Driver.start();48}49}50package com.intuit.karate.driver;51import org.openqa.selenium.WebDriver;

Full Screen

Full Screen

start

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.WebDriver;2import org.openqa.selenium.WebElement;3import org.openqa.selenium.By;4import org.openqa.selenium.chrome.ChromeDriver;5import org.openqa.selenium.chrome.ChromeOptions;6import org.openqa.selenium.remote.RemoteWebDriver;7import org.openqa.selenium.remote.DesiredCapabilities;8import com.intuit.karate.driver.Driver;9public class 4 {10 public static void main(String[] args) throws Exception {11 System.out.println("Starting driver...");12 WebDriver driver = Driver.start("chrome", true);13 System.out.println("Driver started.");14 element.sendKeys("karate");15 element.submit();16 Thread.sleep(3000);17 driver.quit();18 }19}20import org.openqa.selenium.WebDriver;21import org.openqa.selenium.WebElement;22import org.openqa.selenium.By;23import org.openqa.selenium.chrome.ChromeDriver;24import org.openqa.selenium.chrome.ChromeOptions;25import org.openqa.selenium.remote.RemoteWebDriver;26import org.openqa.selenium.remote.DesiredCapabilities;27import com.intuit.karate.driver.Driver;28public class 5 {29 public static void main(String[] args) throws Exception {30 System.out.println("Starting driver...");31 WebDriver driver = Driver.start("chrome", true);32 System.out.println("Driver started.");33 element.sendKeys("karate");34 element.submit();35 Thread.sleep(3000);36 driver.quit();37 }38}39import org.openqa.selenium.WebDriver;40import org.openqa.selenium.WebElement;41import org.openqa.selenium.By;42import org.openqa.selenium.chrome.ChromeDriver;43import org.openqa.selenium.chrome.ChromeOptions;44import org.openqa.selenium.remote.RemoteWebDriver;45import org.openqa.selenium.remote.DesiredCapabilities;46import com.intuit.karate.driver.Driver;47public class 6 {48 public static void main(String[] args) throws Exception {49 System.out.println("Starting driver...");50 WebDriver driver = Driver.start("chrome

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Karate automation tests on LambdaTest cloud grid

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

Most used method in Driver

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful