How to use highlight method of com.intuit.karate.robot.RobotUtils class

Best Karate code snippet using com.intuit.karate.robot.RobotUtils.highlight

Source:RobotBase.java Github

copy

Full Screen

...75 private Integer retryIntervalOverride = null;76 private Integer retryCountOverride = null;77 // debug78 protected boolean debug;79 public boolean highlight;80 public int highlightDuration;81 public void setDebug(boolean debug) {82 this.debug = debug;83 }84 public void setHighlight(boolean highlight) {85 this.highlight = highlight;86 }87 public void setHighlightDuration(int highlightDuration) {88 this.highlightDuration = highlightDuration;89 }90 public void disableRetry() {91 retryEnabled = false;92 retryCountOverride = null;93 retryIntervalOverride = null;94 }95 public void enableRetry(Integer count, Integer interval) {96 retryEnabled = true;97 retryCountOverride = count; // can be null98 retryIntervalOverride = interval; // can be null99 }100 private int getRetryCount() {101 return retryCountOverride == null ? engine.getConfig().getRetryCount() : retryCountOverride;102 }103 private int getRetryInterval() {104 return retryIntervalOverride == null ? engine.getConfig().getRetryInterval() : retryIntervalOverride;105 }106 private <T> T get(String key, T defaultValue) {107 T temp = (T) options.get(key);108 return temp == null ? defaultValue : temp;109 }110 public Logger getLogger() {111 return logger;112 } 113 public RobotBase(ScenarioRuntime runtime) {114 this(runtime, Collections.EMPTY_MAP);115 }116 public RobotBase(ScenarioRuntime runtime, Map<String, Object> options) {117 this.engine = runtime.engine;118 this.logger = runtime.logger;119 try {120 this.options = options;121 basePath = get("basePath", null);122 highlight = get("highlight", false);123 highlightDuration = get("highlightDuration", Config.DEFAULT_HIGHLIGHT_DURATION);124 autoDelay = get("autoDelay", 0);125 tessData = get("tessData", "tessdata");126 tessLang = get("tessLang", "eng");127 toolkit = Toolkit.getDefaultToolkit();128 dimension = toolkit.getScreenSize();129 screen = new Region(this, 0, 0, dimension.width, dimension.height);130 logger.debug("screen dimensions: {}", screen);131 robot = new java.awt.Robot();132 robot.setAutoDelay(autoDelay);133 robot.setAutoWaitForIdle(true);134 //==================================================================135 screenshotOnFailure = get("screenshotOnFailure", true);136 autoClose = get("autoClose", true);137 boolean attach = get("attach", true);138 String window = get("window", null);139 if (window != null) {140 currentWindow = window(window, false, false); // don't retry141 }142 if (currentWindow != null && attach) {143 logger.debug("window found, will re-use: {}", window);144 } else {145 Variable v = new Variable(options.get("fork"));146 if (v.isString()) {147 command = engine.fork(true, v.getAsString());148 } else if (v.isList()) {149 command = engine.fork(true, v.<List>getValue());150 } else if (v.isMap()) {151 command = engine.fork(true, v.<Map>getValue());152 }153 if (command != null) {154 delay(500); // give process time to start155 if (command.isFailed()) {156 throw new KarateException("robot fork command failed: " + command.getFailureReason().getMessage());157 }158 if (window != null) {159 retryCountOverride = get("retryCount", null);160 retryIntervalOverride = get("retryInterval", null);161 currentWindow = window(window); // will retry162 logger.debug("attached to process window: {} - {}", currentWindow, command.getArgList());163 }164 }165 if (currentWindow == null && window != null) {166 throw new KarateException("failed to find window: " + window);167 }168 }169 } catch (Exception e) {170 String message = "robot init failed: " + e.getMessage();171 throw new KarateException(message, e);172 }173 }174 public <T> T retry(Supplier<T> action, Predicate<T> condition, String logDescription, boolean failWithException) {175 long startTime = System.currentTimeMillis();176 int count = 0, max = getRetryCount();177 int interval = getRetryInterval();178 disableRetry(); // always reset179 T result;180 boolean success;181 do {182 if (count > 0) {183 logger.debug("{} - retry #{}", logDescription, count);184 delay(interval);185 }186 result = action.get();187 success = condition.test(result);188 } while (!success && count++ < max);189 if (!success) {190 long elapsedTime = System.currentTimeMillis() - startTime;191 String message = logDescription + ": failed after " + (count - 1) + " retries and " + elapsedTime + " milliseconds";192 logger.warn(message);193 if (failWithException) {194 throw new RuntimeException(message);195 }196 }197 return result;198 }199 public void setBasePath(String basePath) {200 this.basePath = basePath;201 }202 private byte[] readBytes(String path) {203 if (basePath != null) {204 String slash = basePath.endsWith(":") ? "" : "/";205 path = basePath + slash + path;206 }207 return engine.fileReader.readFileAsBytes(path);208 }209 @Override210 public void onFailure(StepResult stepResult) {211 if (screenshotOnFailure && !stepResult.isWithCallResults()) {212 byte[] bytes = screenshot();213 214 }215 }216 @Override217 public Robot retry() {218 return retry(null, null);219 }220 @Override221 public Robot retry(int count) {222 return retry(count, null);223 }224 @Override225 public Robot retry(Integer count, Integer interval) {226 enableRetry(count, interval);227 return this;228 }229 @Override230 public Robot delay(int millis) {231 robot.delay(millis);232 return this;233 }234 private static int mask(int num) {235 switch (num) {236 case 2:237 return InputEvent.BUTTON2_DOWN_MASK;238 case 3:239 return InputEvent.BUTTON3_DOWN_MASK;240 default:241 return InputEvent.BUTTON1_DOWN_MASK;242 }243 }244 @Override245 public Robot click() {246 return click(1);247 }248 @Override249 public Robot rightClick() {250 return click(3);251 }252 @Override253 public Robot click(int num) {254 int mask = mask(num);255 robot.mousePress(mask);256 if (highlight) {257 getLocation().highlight(highlightDuration);258 int toDelay = CLICK_POST_DELAY - highlightDuration;259 if (toDelay > 0) {260 RobotUtils.delay(toDelay);261 }262 } else {263 RobotUtils.delay(CLICK_POST_DELAY);264 }265 robot.mouseRelease(mask);266 return this;267 }268 @Override269 public Robot doubleClick() {270 click();271 delay(40);272 click();273 return this;274 }275 @Override276 public Robot press() {277 robot.mousePress(1);278 return this;279 }280 @Override281 public Robot release() {282 robot.mouseRelease(1);283 return this;284 }285 @Override286 public Robot input(String[] values) {287 return input(values, 0);288 }289 @Override290 public Robot input(String chars, int delay) {291 String[] array = new String[chars.length()];292 for (int i = 0; i < array.length; i++) {293 array[i] = Character.toString(chars.charAt(i));294 }295 return input(array, delay);296 }297 @Override298 public Robot input(String[] values, int delay) {299 for (String s : values) {300 if (delay > 0) {301 delay(delay);302 }303 input(s);304 }305 return this;306 }307 @Override308 public Robot input(String value) {309 if (highlight) {310 getFocused().highlight(highlightDuration);311 }312 StringBuilder sb = new StringBuilder();313 for (char c : value.toCharArray()) {314 if (Keys.isModifier(c)) {315 sb.append(c);316 int[] codes = RobotUtils.KEY_CODES.get(c);317 if (codes == null) {318 logger.warn("cannot resolve char: {}", c);319 robot.keyPress(c);320 } else {321 robot.keyPress(codes[0]);322 }323 continue;324 }325 int[] codes = RobotUtils.KEY_CODES.get(c);326 if (codes == null) {327 logger.warn("cannot resolve char: {}", c);328 robot.keyPress(c);329 robot.keyRelease(c);330 } else if (codes.length > 1) {331 robot.keyPress(codes[0]);332 robot.keyPress(codes[1]);333 robot.keyRelease(codes[1]);334 robot.keyRelease(codes[0]);335 } else {336 robot.keyPress(codes[0]);337 robot.keyRelease(codes[0]);338 }339 }340 for (char c : sb.toString().toCharArray()) {341 int[] codes = RobotUtils.KEY_CODES.get(c);342 if (codes == null) {343 logger.warn("cannot resolve char: {}", c);344 robot.keyRelease(c);345 } else {346 robot.keyRelease(codes[0]);347 }348 }349 return this;350 }351 public Robot clearFocused() {352 return input(Keys.CONTROL + "a" + Keys.DELETE);353 }354 protected int getHighlightDuration() {355 return highlight ? highlightDuration : -1;356 }357 @Override358 public Element input(String locator, String value) {359 return locate(locator).input(value);360 }361 @Override362 public byte[] screenshot() {363 return screenshot(screen);364 }365 @Override366 public byte[] screenshotActive() {367 return getActive().screenshot();368 }369 public byte[] screenshot(int x, int y, int width, int height) {370 return screenshot(new Region(this, x, y, width, height));371 }372 public byte[] screenshot(Region region) {373 BufferedImage image = region.capture();374 byte[] bytes = OpenCvUtils.toBytes(image);375 getRuntime().embed(bytes, ResourceType.PNG);376 return bytes;377 }378 @Override379 public Robot move(int x, int y) {380 robot.mouseMove(x, y);381 return this;382 }383 @Override384 public Robot click(int x, int y) {385 return move(x, y).click();386 }387 @Override388 public Element highlight(String locator) {389 return locate(Config.DEFAULT_HIGHLIGHT_DURATION, getSearchRoot(), locator);390 }391 @Override392 public List<Element> highlightAll(String locator) {393 return locateAll(Config.DEFAULT_HIGHLIGHT_DURATION, getSearchRoot(), locator);394 }395 @Override396 public Element focus(String locator) {397 return locate(getHighlightDuration(), getSearchRoot(), locator).focus();398 }399 @Override400 public Element locate(String locator) {401 return locate(getHighlightDuration(), getSearchRoot(), locator);402 }403 @Override404 public List<Element> locateAll(String locator) {405 return locateAll(getHighlightDuration(), getSearchRoot(), locator);406 }407 @Override408 public boolean exists(String locator) {409 return optional(locator).isPresent();410 }411 @Override412 public Element optional(String locator) {413 return optional(getSearchRoot(), locator);414 }415 @Override416 public boolean windowExists(String locator) {417 return windowOptional(locator).isPresent();418 }419 @Override420 public Element windowOptional(String locator) {421 return waitForWindowOptional(locator, false);422 }423 @Override424 public Element waitForWindowOptional(String locator) {425 return waitForWindowOptional(locator, true);426 }427 protected Element waitForWindowOptional(String locator, boolean retry) {428 Element prevWindow = currentWindow;429 Element window = window(locator, retry, false); // will update currentWindow 430 currentWindow = prevWindow; // so we reset it431 if (window == null) {432 return new MissingElement(this);433 }434 // note that currentWindow will NOT point to the new window located435 return window;436 }437 protected Element optional(Element searchRoot, String locator) {438 Element found = locateImageOrElement(searchRoot, locator);439 if (found == null) {440 logger.warn("element does not exist: {}", locator);441 return new MissingElement(this);442 }443 if (highlight) {444 found.highlight();445 }446 return found;447 }448 protected Element locate(int duration, Element searchRoot, String locator) {449 Element found;450 if (retryEnabled) {451 found = retryForAny(true, searchRoot, locator);452 } else {453 found = locateImageOrElement(searchRoot, locator);454 if (found == null) {455 String message = "cannot locate: '" + locator + "' (" + searchRoot.getDebugString() + ")";456 logger.error(message);457 throw new RuntimeException(message);458 }459 if (duration > 0) {460 found.getRegion().highlight(duration);461 }462 }463 return found;464 }465 protected List<Element> locateAll(int duration, Element searchRoot, String locator) {466 List<Element> found;467 if (locator.endsWith(".png")) {468 found = locateAllImages(searchRoot, locator);469 } else if (locator.startsWith("{")) {470 found = locateAllText(searchRoot, locator);471 } else {472 found = locateAllInternal(searchRoot, locator);473 }474 if (duration > 0) {475 RobotUtils.highlightAll(searchRoot.getRegion(), found, duration, false);476 }477 return found;478 }479 @Override480 public Element move(String locator) {481 return locate(getHighlightDuration(), getSearchRoot(), locator).move();482 }483 @Override484 public Element click(String locator) {485 return locate(getHighlightDuration(), getSearchRoot(), locator).click();486 }487 @Override488 public Element select(String locator) {489 return locate(getHighlightDuration(), getSearchRoot(), locator).select();490 }491 @Override492 public Element press(String locator) {493 return locate(getHighlightDuration(), getSearchRoot(), locator).press();494 }495 @Override496 public Element release(String locator) {497 return locate(getHighlightDuration(), getSearchRoot(), locator).release();498 }499 private StringUtils.Pair parseOcr(String raw) { // TODO make object500 int pos = raw.indexOf('}');501 String lang = raw.substring(1, pos);502 if (lang.length() < 2) {503 lang = lang + tessLang;504 }505 String text = raw.substring(pos + 1);506 return StringUtils.pair(lang, text);507 }508 public List<Element> locateAllText(Element searchRoot, String path) {509 StringUtils.Pair pair = parseOcr(path);510 String lang = pair.left;511 boolean negative = lang.charAt(0) == '-';512 if (negative) {513 lang = lang.substring(1);514 }515 String text = pair.right;516 return Tesseract.findAll(this, lang, searchRoot.getRegion(), text, negative);517 }518 public Element locateText(Element searchRoot, String path) {519 StringUtils.Pair pair = parseOcr(path);520 String lang = pair.left;521 boolean negative = lang.charAt(0) == '-';522 if (negative) {523 lang = lang.substring(1);524 }525 String text = pair.right;526 return Tesseract.find(this, lang, searchRoot.getRegion(), text, negative);527 }528 private static class PathAndStrict {529 final int strictness;530 final String path;531 public PathAndStrict(String path) {532 int pos = path.indexOf(':');533 if (pos > 0 && pos < 3) {534 strictness = Integer.valueOf(path.substring(0, pos));535 this.path = path.substring(pos + 1);536 } else {537 strictness = 10;538 this.path = path;539 }540 }541 }542 public List<Element> locateAllImages(Element searchRoot, String path) {543 PathAndStrict ps = new PathAndStrict(path);544 List<Region> found = OpenCvUtils.findAll(ps.strictness, this, searchRoot.getRegion(), readBytes(ps.path), true);545 List<Element> list = new ArrayList(found.size());546 for (Region region : found) {547 list.add(new ImageElement(region));548 }549 return list;550 }551 public Element locateImage(Region region, String path) {552 PathAndStrict ps = new PathAndStrict(path);553 return locateImage(region, ps.strictness, readBytes(ps.path));554 }555 public Element locateImage(Region searchRegion, int strictness, byte[] bytes) {556 Region region = OpenCvUtils.find(strictness, this, searchRegion, bytes, true);557 if (region == null) {558 return null;559 }560 return new ImageElement(region);561 }562 @Override563 public Element window(String title) {564 return window(title, true, true);565 }566 private Element window(String title, boolean retry, boolean failWithException) {567 return window(new StringMatcher(title), retry, failWithException);568 }569 @Override570 public Element window(Predicate<String> condition) {571 return window(condition, true, true);572 }573 private Element window(Predicate<String> condition, boolean retry, boolean failWithException) {574 try {575 currentWindow = retry ? retry(() -> windowInternal(condition), w -> w != null, "find window", failWithException) : windowInternal(condition);576 } catch (Exception e) {577 if (failWithException) {578 throw e;579 }580 logger.warn("failed to find window: {}", e.getMessage());581 currentWindow = null;582 }583 if (currentWindow != null && highlight) { // currentWindow can be null584 currentWindow.highlight(getHighlightDuration());585 }586 return currentWindow;587 }588 protected Element getSearchRoot() {589 if (currentWindow == null) {590 logger.warn("using desktop as search root, activate a window or parent element for better performance");591 return getRoot();592 }593 return currentWindow;594 }595 @Override596 public Object waitUntil(Supplier<Object> condition) {597 return waitUntil(condition, true);598 }599 @Override600 public Object waitUntilOptional(Supplier<Object> condition) {601 return waitUntil(condition, false);602 }603 protected Object waitUntil(Supplier<Object> condition, boolean failWithException) {604 return retry(() -> condition.get(), o -> o != null, "waitUntil (function)", failWithException);605 }606 @Override607 public Element waitFor(String locator) {608 return retryForAny(true, getSearchRoot(), locator);609 }610 @Override611 public Element waitForOptional(String locator) {612 return retryForAny(false, getSearchRoot(), locator);613 }614 @Override615 public Element waitForAny(String locator1, String locator2) {616 return retryForAny(true, getSearchRoot(), locator1, locator2);617 }618 @Override619 public Element waitForAny(String[] locators) {620 return retryForAny(true, getSearchRoot(), locators);621 }622 protected Element retryForAny(boolean failWithException, Element searchRoot, String... locators) {623 Element found = retry(() -> waitForAny(searchRoot, locators), r -> r != null, "find by locator(s): " + Arrays.asList(locators), failWithException);624 return found == null ? new MissingElement(this) : found;625 }626 private Element waitForAny(Element searchRoot, String... locators) {627 for (String locator : locators) {628 Element found = locateImageOrElement(searchRoot, locator);629 if (found != null) {630 if (highlight) {631 found.getRegion().highlight(highlightDuration);632 }633 return found;634 }635 }636 return null;637 }638 private Element locateImageOrElement(Element searchRoot, String locator) {639 if (locator.endsWith(".png")) {640 return locateImage(searchRoot.getRegion(), locator);641 } else if (locator.startsWith("{")) {642 return locateText(searchRoot, locator);643 } else if (searchRoot.isImage()) {644 // TODO645 throw new RuntimeException("todo find non-image elements within region");...

Full Screen

Full Screen

Source:Robot.java Github

copy

Full Screen

...50 public final java.awt.Robot robot;51 public final Toolkit toolkit;52 public final Dimension dimension;53 public final Map<String, Object> options;54 public final boolean highlight;55 public final int highlightDuration;56 public final int retryCount;57 public final int retryInterval;58 public String basePath;59 private <T> T get(String key, T defaultValue) {60 T temp = (T) options.get(key);61 return temp == null ? defaultValue : temp;62 }63 public Robot(ScenarioContext context) {64 this(context, Collections.EMPTY_MAP);65 }66 public Robot(ScenarioContext context, Map<String, Object> options) {67 this.context = context;68 try {69 this.options = options;70 basePath = get("basePath", "classpath:");71 highlight = get("highlight", false);72 highlightDuration = get("highlightDuration", 1000);73 retryCount = get("retryCount", 3);74 retryInterval = get("retryInterval", 2000);75 toolkit = Toolkit.getDefaultToolkit();76 dimension = toolkit.getScreenSize();77 robot = new java.awt.Robot();78 robot.setAutoDelay(40);79 robot.setAutoWaitForIdle(true);80 String app = (String) options.get("app");81 if (app != null) {82 switchTo(app);83 }84 } catch (Exception e) {85 throw new RuntimeException(e);86 }87 }88 public <T> T retry(Supplier<T> action, Predicate<T> condition, String logDescription) {89 long startTime = System.currentTimeMillis();90 int count = 0, max = retryCount;91 T result;92 boolean success;93 do {94 if (count > 0) {95 logger.debug("{} - retry #{}", logDescription, count);96 delay(retryInterval);97 }98 result = action.get();99 success = condition.test(result);100 } while (!success && count++ < max);101 if (!success) {102 long elapsedTime = System.currentTimeMillis() - startTime;103 logger.warn("failed after {} retries and {} milliseconds", (count - 1), elapsedTime);104 }105 return result;106 }107 public void setBasePath(String basePath) {108 this.basePath = basePath;109 }110 public byte[] read(String path) {111 if (basePath != null) {112 String slash = basePath.endsWith(":") ? "" : "/";113 path = basePath + slash + path;114 }115 ScriptValue sv = FileUtils.readFile(path, context);116 return sv.getAsByteArray();117 }118 public Robot delay(int millis) {119 robot.delay(millis);120 return this;121 }122 123 private static int mask(int num) {124 switch (num) {125 case 2: return InputEvent.BUTTON2_DOWN_MASK;126 case 3: return InputEvent.BUTTON3_DOWN_MASK;127 default: return InputEvent.BUTTON1_DOWN_MASK;128 } 129 }130 131 public Robot click() { 132 return click(1); 133 } 134 public Robot click(int num) {135 int mask = mask(num);136 robot.mousePress(mask);137 robot.mouseRelease(mask);138 return this;139 }140 public Robot input(char s) {141 return input(Character.toString(s));142 }143 public Robot input(String mod, char s) {144 return input(mod, Character.toString(s));145 }146 public Robot input(char mod, String s) {147 return input(Character.toString(mod), s);148 }149 public Robot input(char mod, char s) {150 return input(Character.toString(mod), Character.toString(s));151 }152 public Robot input(String mod, String s) { // TODO refactor153 for (char c : mod.toCharArray()) {154 int[] codes = RobotUtils.KEY_CODES.get(c);155 if (codes == null) {156 logger.warn("cannot resolve char: {}", c);157 robot.keyPress(c);158 } else {159 robot.keyPress(codes[0]);160 }161 }162 input(s);163 for (char c : mod.toCharArray()) {164 int[] codes = RobotUtils.KEY_CODES.get(c);165 if (codes == null) {166 logger.warn("cannot resolve char: {}", c);167 robot.keyRelease(c);168 } else {169 robot.keyRelease(codes[0]);170 }171 }172 return this;173 }174 public Robot input(String s) {175 for (char c : s.toCharArray()) {176 int[] codes = RobotUtils.KEY_CODES.get(c);177 if (codes == null) {178 logger.warn("cannot resolve char: {}", c);179 robot.keyPress(c);180 robot.keyRelease(c);181 } else if (codes.length > 1) {182 robot.keyPress(codes[0]);183 robot.keyPress(codes[1]);184 robot.keyRelease(codes[1]);185 robot.keyRelease(codes[0]);186 } else {187 robot.keyPress(codes[0]);188 robot.keyRelease(codes[0]);189 }190 }191 return this;192 }193 public BufferedImage capture() {194 int width = dimension.width;195 int height = dimension.height;196 Image image = robot.createScreenCapture(new Rectangle(0, 0, width, height));197 BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY);198 Graphics g = bi.createGraphics();199 g.drawImage(image, 0, 0, width, height, null);200 return bi;201 }202 public File captureAndSave(String path) {203 BufferedImage image = capture();204 File file = new File(path);205 RobotUtils.save(image, file);206 return file;207 }208 209 public Region move(int x, int y) {210 return new Region(x, y).with(this).move(); 211 }212 213 public Region click(int x, int y) {214 return move(x, y).click();215 } 216 public Region move(String path) {217 return find(path).move();218 } 219 public Region click(String path) {220 return find(path).click();221 }222 public Region find(String path) {223 return find(read(path)).with(this);224 }225 public Region find(byte[] bytes) {226 AtomicBoolean resize = new AtomicBoolean();227 Region region = retry(() -> RobotUtils.find(capture(), bytes, resize.getAndSet(true)), r -> r != null, "find by image");228 if (highlight) {229 region.highlight(highlightDuration);230 }231 return region;232 }233 public boolean switchTo(String title) {234 if (title.startsWith("^")) {235 return switchTo(t -> t.contains(title.substring(1)));236 }237 FileUtils.OsType type = FileUtils.getOsType();238 switch (type) {239 case LINUX:240 return RobotUtils.switchToLinuxOs(title);241 case MACOSX:242 return RobotUtils.switchToMacOs(title);243 case WINDOWS:...

Full Screen

Full Screen

highlight

Using AI Code Generation

copy

Full Screen

1import com.intuit.karate.robot.RobotUtils;2import org.junit.Test;3import org.junit.runner.RunWith;4import com.intuit.karate.junit4.Karate;5@RunWith(Karate.class)6public class 4 {7 public void test(){8 RobotUtils.highlight(1, 1, 100, 100, 10, 10);9 }10}11import com.intuit.karate.robot.RobotUtils;12import org.junit.Test;13import org.junit.runner.RunWith;14import com.intuit.karate.junit4.Karate;15@RunWith(Karate.class)16public class 5 {17 public void test(){18 RobotUtils.highlight(1, 1, 100, 100, 10, 10);19 }20}21import com.intuit.karate.robot.RobotUtils;22import org.junit.Test;23import org.junit.runner.RunWith;24import com.intuit.karate.junit4.Karate;25@RunWith(Karate.class)26public class 6 {27 public void test(){28 RobotUtils.highlight(1, 1, 100, 100, 10, 10);29 }30}31import com.intuit.karate.robot.RobotUtils;32import org.junit.Test;33import org.junit.runner.RunWith;34import com.intuit.karate.junit4.Karate;35@RunWith(Karate.class)36public class 7 {37 public void test(){38 RobotUtils.highlight(1, 1, 100, 100, 10, 10);39 }40}41import com.intuit.karate.robot.RobotUtils;42import org.junit.Test;43import org.junit.runner.RunWith;44import com.intuit.karate.junit4.Karate;45@RunWith(Karate.class)46public class 8 {47 public void test(){48 RobotUtils.highlight(1, 1, 100,

Full Screen

Full Screen

highlight

Using AI Code Generation

copy

Full Screen

1import com.intuit.karate.robot.RobotUtils;2import java.awt.Color;3import java.awt.Point;4import java.awt.Rectangle;5import java.awt.image.BufferedImage;6import java.io.File;7import java.io.IOException;8import javax.imageio.ImageIO;9public class 4 {10 public static void main(String[] args) {11 try {12 BufferedImage image = ImageIO.read(new File("C:\\Users\\user\\Desktop\\screenshot.png"));13 BufferedImage newImage = RobotUtils.highlight(image, new Rectangle(100, 100, 200, 200), Color.red, 2);14 ImageIO.write(newImage, "png", new File("C:\\Users\\user\\Desktop\\highlighted.png"));15 } catch (IOException e) {16 e.printStackTrace();17 }18 }19}20import com.intuit.karate.robot.RobotUtils;21import java.awt.Color;22import java.awt.Point;23import java.awt.Rectangle;24import java.awt.image.BufferedImage;25import java.io.File;26import java.io.IOException;27import javax.imageio.ImageIO;28public class 5 {29 public static void main(String[] args) {30 try {31 BufferedImage image = ImageIO.read(new File("C:\\Users\\user\\Desktop\\screenshot.png"));32 BufferedImage newImage = RobotUtils.highlight(image, new Point(100, 100), 200, 200, Color.red, 2);33 ImageIO.write(newImage, "png", new File("C:\\Users\\user\\Desktop\\highlighted.png"));34 } catch (IOException e) {35 e.printStackTrace();36 }37 }38}39import com.intuit.karate.robot.RobotUtils;40import java.awt.Color;41import java.awt.Point;42import java.awt.Rectangle;43import java.awt.image.BufferedImage;44import java.io.File;45import java.io.IOException;46import javax.imageio.ImageIO;47public class 6 {48 public static void main(String[] args) {49 try {50 BufferedImage image = ImageIO.read(new File("C:\\Users\\user\\Desktop\\screenshot.png"));51 BufferedImage newImage = RobotUtils.highlight(image, new Point(100, 100

Full Screen

Full Screen

highlight

Using AI Code Generation

copy

Full Screen

1import com.intuit.karate.robot.RobotUtils;2import java.awt.Color;3import java.awt.Rectangle;4import java.awt.image.BufferedImage;5import java.io.File;6import javax.imageio.ImageIO;7import org.junit.Test;8public class 4 {9public void test() throws Exception {10BufferedImage image = ImageIO.read(new File("c:/temp/test.png"));11Rectangle rect = new Rectangle(100, 100, 200, 200);12RobotUtils.highlight(image, rect, Color.RED, 2);13ImageIO.write(image, "png", new File("c:/temp/test2.png"));14}15}16import com.intuit.karate.robot.RobotUtils;17import java.awt.Color;18import java.awt.Rectangle;19import java.awt.image.BufferedImage;20import java.io.File;21import javax.imageio.ImageIO;22import org.junit.Test;23public class 5 {24public void test() throws Exception {25BufferedImage image = ImageIO.read(new File("c:/temp/test.png"));26Rectangle rect = new Rectangle(100, 100, 200, 200);27RobotUtils.highlight(image, rect, Color.RED, 2);28ImageIO.write(image, "png", new File("c:/temp/test2.png"));29}30}31import com.intuit.karate.robot.RobotUtils;32import java.awt.Color;33import java.awt.Rectangle;34import java.awt.image.BufferedImage;35import java.io.File;36import javax.imageio.ImageIO;37import org.junit.Test;38public class 6 {39public void test() throws Exception {40BufferedImage image = ImageIO.read(new File("c:/temp/test.png"));41Rectangle rect = new Rectangle(100, 100, 200, 200);42RobotUtils.highlight(image, rect, Color.RED, 2);43ImageIO.write(image, "png", new File("c:/temp/test2.png"));44}45}46import com.intuit.karate.robot.RobotUtils;47import java.awt.Color;48import java.awt.Rectangle;49import java.awt.image.BufferedImage;50import java.io.File;51import javax.imageio.ImageIO;52import

Full Screen

Full Screen

highlight

Using AI Code Generation

copy

Full Screen

1import com.intuit.karate.robot.RobotUtils2import java.awt.Color3import java.awt.Rectangle4import java.awt.Robot5import java.awt.Toolkit6import java.awt.image.BufferedImage7import java.io.File8import javax.imageio.ImageIO9def robot = new Robot()10def screenSize = Toolkit.getDefaultToolkit().getScreenSize()11def screenBounds = new Rectangle(screenSize)12def screen = robot.createScreenCapture(screenBounds)13def image = RobotUtils.highlight(screen, startX, startY, endX, endY, color, thickness)14ImageIO.write(image, 'png', new File('highlight.png'))15import com.intuit.karate.robot.RobotUtils16import java.awt.Color17import java.awt.Rectangle18import java.awt.Robot19import java.awt.Toolkit20import java.awt.image.BufferedImage21import java.io.File22import javax.imageio.ImageIO23def robot = new Robot()24def screenSize = Toolkit.getDefaultToolkit().getScreenSize()25def screenBounds = new Rectangle(screenSize)26def screen = robot.createScreenCapture(screenBounds)27def image = RobotUtils.highlight(screen, startX, startY, endX, endY, color, thickness)28ImageIO.write(image, 'png', new File('highlight.png'))29import com.intuit.karate.robot.RobotUtils30import java.awt.Color31import java.awt.Rectangle32import java.awt.Robot33import java.awt.Toolkit34import java.awt.image.BufferedImage35import java.io.File36import javax.imageio.ImageIO37def robot = new Robot()38def screenSize = Toolkit.getDefaultToolkit().getScreenSize()39def screenBounds = new Rectangle(screenSize)

Full Screen

Full Screen

highlight

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.By;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.WebElement;4import org.openqa.selenium.chrome.ChromeDriver;5import com.intuit.karate.robot.RobotUtils;6public class 4 {7public static void main(String[] args) throws InterruptedException {8 System.setProperty("webdriver.chrome.driver", "C:\\Users\\prashant\\Downloads\\chromedriver_win32\\chromedriver.exe");9 WebDriver driver = new ChromeDriver();10 WebElement ele = driver.findElement(By.name("q"));11 RobotUtils.highlight(ele);12 Thread.sleep(5000);13 driver.quit();14}15}

Full Screen

Full Screen

highlight

Using AI Code Generation

copy

Full Screen

1import com.intuit.karate.robot.RobotUtils;2import java.awt.Color;3import java.awt.event.KeyEvent;4import java.awt.event.InputEvent;5import java.awt.AWTException;6import java.awt.Robot;7import java.awt.Rectangle;8import java.awt.Toolkit;9import java.awt.image.BufferedImage;10import javax.imageio.ImageIO;11import java.io.File;12import java.io.IOException;13import java.awt.Graphics2D;14import java.awt.Graphics;15import java.awt.image.BufferedImage;16import java.awt.Rectangle;17import java.awt.image.DataBufferByte;18import java.awt.image.DataBufferInt;19import java.awt.image.WritableRaster;20import java.awt.image.Raster;21import java.awt.image.RenderedImage;22import java.awt.image.DataBuffer;23import java.awt.image.WritableRaster;24import java.awt.image.DataBufferByte;25import java.awt.image.DataBufferInt;26import java.awt.image.RenderedImage;27import java.awt.image.BufferedImage;28import java.awt.image.DataBuffer;29import java.awt.image.WritableRaster;30import java.awt.image.DataBufferByte;31import java.awt.image.DataBufferInt;32import java.awt.image.RenderedImage;33import java.awt.image.BufferedImage;34import java.awt.image.DataBuffer;35import java.awt.image.WritableRaster;36import java.awt.image.DataBufferByte;37import java.awt.image.DataBufferInt;38import java.awt.image.RenderedImage;39public class 4 {40 public static void main(String[] args) throws AWTException, IOException {41 Robot robot = new Robot();42 robot.setAutoDelay(1000);43 robot.setAutoWaitForIdle(true);44 robot.keyPress(KeyEvent.VK_WINDOWS);45 robot.keyPress(KeyEvent.VK_R);46 robot.keyRelease(KeyEvent.VK_R);47 robot.keyRelease(KeyEvent.VK_WINDOWS);48 robot.delay(1000);49 robot.keyPress(KeyEvent.VK_C);50 robot.keyPress(KeyEvent.VK_O);51 robot.keyPress(KeyEvent.VK_M);52 robot.keyPress(KeyEvent.VK_P);53 robot.keyPress(KeyEvent.VK_U);54 robot.keyPress(KeyEvent.VK_T);55 robot.keyPress(KeyEvent.VK_E);56 robot.keyPress(KeyEvent.VK_R);57 robot.keyRelease(KeyEvent.VK_C);58 robot.keyRelease(KeyEvent.VK_O);59 robot.keyRelease(KeyEvent.VK_M);60 robot.keyRelease(KeyEvent.VK_P);61 robot.keyRelease(KeyEvent.VK_U);62 robot.keyRelease(KeyEvent.VK_T);63 robot.keyRelease(KeyEvent.VK_E);64 robot.keyRelease(KeyEvent.VK_R);65 robot.delay(1000);66 robot.keyPress(KeyEvent.VK_ENTER);67 robot.keyRelease(KeyEvent

Full Screen

Full Screen

highlight

Using AI Code Generation

copy

Full Screen

1import com.intuit.karate.robot.RobotUtils;2import java.awt.Color;3import java.awt.Rectangle;4import org.junit.Test;5public class 4 {6public void test4() {7RobotUtils.highlight(new Rectangle(0,0,100,100),Color.red,1);8}9}10* highlight { x: 0, y: 0, width: 100, height: 100, color: 'red', duration: 1 }

Full Screen

Full Screen

highlight

Using AI Code Generation

copy

Full Screen

1import com.intuit.karate.robot.RobotUtils;2RobotUtils.highlight(4, 4, 4, 4);3import com.intuit.karate.robot.RobotUtils;4RobotUtils.highlight(5, 5, 5, 5);5import com.intuit.karate.robot.RobotUtils;6RobotUtils.highlight(6, 6, 6, 6);7import com.intuit.karate.robot.RobotUtils;8RobotUtils.highlight(7, 7, 7, 7);9import com.intuit.karate.robot.RobotUtils;10RobotUtils.highlight(8, 8, 8, 8);11import com.intuit.karate.robot.RobotUtils;12RobotUtils.highlight(9, 9, 9, 9);13import com.intuit.karate.robot.RobotUtils;14RobotUtils.highlight(10, 10, 10, 10);15import com.intuit.karate.robot.RobotUtils;16RobotUtils.highlight(11, 11, 11, 11);17import com.intuit.karate.robot.RobotUtils;18RobotUtils.highlight(12, 12, 12, 12);19import com.intuit.karate.robot.RobotUtils;20RobotUtils.highlight(13, 13,

Full Screen

Full Screen

highlight

Using AI Code Generation

copy

Full Screen

1import com.intuit.karate.robot.RobotUtils;2import org.openqa.selenium.By;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.chrome.ChromeDriver;5import org.openqa.selenium.WebElement;6import java.util.concurrent.TimeUnit;7public class 4 {8public static void main(String[] args) {9System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");10WebDriver driver = new ChromeDriver();11driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);12WebElement element = driver.findElement(By.name("q"));13RobotUtils.highlight(element, driver);14}15}16import com.intuit.karate.robot.RobotUtils;17import org.openqa.selenium.By;18import org.openqa.selenium.WebDriver;19import org.openqa.selenium.chrome.ChromeDriver;20import org.openqa.selenium.WebElement;21import java.util.concurrent.TimeUnit;22public class 5 {23public static void main(String[] args) {24System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");25WebDriver driver = new ChromeDriver();26driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);27WebElement element = driver.findElement(By.name("q"));28RobotUtils.highlight(element, driver);29}30}31import com.intuit.karate.robot.RobotUtils;32import org.openqa.selenium.By;33import org.openqa.selenium.WebDriver;34import org.openqa.selenium.chrome.ChromeDriver;35import org.openqa.selenium.WebElement;36import java.util.concurrent.TimeUnit;37public class 6 {38public static void main(String[] args) {39System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");40WebDriver driver = new ChromeDriver();41driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);42WebElement element = driver.findElement(By.name("q"));43RobotUtils.highlight(element, driver);44}45}46import com.intuit.karate.robot.RobotUtils;47import org.openqa.selenium.By

Full Screen

Full Screen

highlight

Using AI Code Generation

copy

Full Screen

1import com.intuit.karate.junit5.Karate;2class 4 {3 Karate testUsers() {4 return Karate.run("4").relativeTo(getClass());5 }6}7 * def driver = createDriver()8 ${driver}= create driver9 ${driver}= driver ${driver} maximize10 ${robotUtils}= get library instance KarateLibrary11 ${robotUtils}= highlight ${robotUtils} ${element} red 500 212 ${driver}= driver ${driver} quit13import com.intuit.karate.junit5.Karate;14class 5 {15 Karate testUsers() {16 return Karate.run("5").relativeTo(getClass());17 }18}

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 RobotUtils

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful