Best Webtau code snippet using org.testingisdocumenting.webtau.browser.documentation.ImageAnnotation.ImageAnnotation
Source:BrowserDocumentation.java
...30import static org.testingisdocumenting.webtau.cfg.WebTauConfig.*;31import static org.testingisdocumenting.webtau.reporter.IntegrationTestsMessageBuilder.*;32import static org.testingisdocumenting.webtau.reporter.TokenizedMessage.*;33public class BrowserDocumentation {34 private final List<ImageAnnotation> annotations;35 /**36 * capture limits screenshot to this optional element37 */38 private PageElement rootElement;39 private final WebDriver driver;40 public BrowserDocumentation(WebDriver driver) {41 this(driver, Collections.emptyList());42 }43 private BrowserDocumentation(WebDriver driver, List<ImageAnnotation> annotations) {44 this.driver = driver;45 this.annotations = annotations;46 }47 public BrowserDocumentation withRoot(PageElement pageElement) {48 BrowserDocumentation browserDocumentation = new BrowserDocumentation(driver, new ArrayList<>(annotations));49 browserDocumentation.rootElement = pageElement;50 return browserDocumentation;51 }52 public BrowserDocumentation withAnnotations(PageElement... pageElements) {53 return withAnnotations(Arrays.stream(pageElements)54 .map(this::badge)55 .toArray(ImageAnnotation[]::new));56 }57 public BrowserDocumentation withAnnotations(ImageAnnotation... annotations) {58 BrowserDocumentation browserDocumentation = new BrowserDocumentation(driver, assignDefaultText(Arrays.asList(annotations)));59 browserDocumentation.rootElement = rootElement;60 return browserDocumentation;61 }62 public ImageAnnotation badge(PageElement pageElement) {63 return new BadgeImageAnnotation(pageElement, "");64 }65 public ImageAnnotation rect(PageElement pageElement) {66 return new RectangleImageAnnotation(pageElement, "");67 }68 public ImageAnnotation rect(PageElement pageElement, String text) {69 return new RectangleImageAnnotation(pageElement, text);70 }71 public ImageAnnotation arrow(PageElement begin, PageElement end, String text) {72 return new ArrowImageAnnotation(begin, end, text);73 }74 public ImageAnnotation arrow(PageElement begin, PageElement end) {75 return new ArrowImageAnnotation(begin, end, "");76 }77 public void capture(String screenshotName) {78 WebTauStep step = WebTauStep.createStep(79 tokenizedMessage(classifier("documentation"), action("capturing"), classifier("screenshot"),80 AS, urlValue(screenshotName)),81 (path) -> tokenizedMessage(classifier("documentation"), action("captured"), classifier("screenshot")82 , AS, urlValue(((Path) path).toAbsolutePath())),83 () -> {84 Number pixelRatio = detectPixelRatio();85 WebElement optionalRootWebElement = validateAndFindRootElementIfRequired();86 Path screenshot = createScreenshot(optionalRootWebElement, pixelRatio, screenshotName);87 createAnnotations(optionalRootWebElement, pixelRatio, screenshotName);88 return screenshot;89 });90 step.execute(StepReportOptions.REPORT_ALL);91 }92 private WebElement validateAndFindRootElementIfRequired() {93 if (rootElement == null) {94 return null;95 }96 rootElement.should(new VisibleValueMatcher());97 return this.rootElement.findElement();98 }99 private Path createScreenshot(WebElement optionalRootWebElement, Number pixelRatio, String screenshotName) {100 DocumentationArtifacts.registerName(screenshotName);101 Screenshot screenshot = new Screenshot(getScreenshotTaker(),102 pixelRatio,103 rootElementLocationAndSizerProvider(optionalRootWebElement));104 String artifactName = screenshotName + ".png";105 Path screenShotPath = getCfg().getDocArtifactsPath().resolve(artifactName);106 FileUtils.createDirsForFile(screenShotPath);107 screenshot.save(screenShotPath);108 return screenShotPath;109 }110 private WebElementLocationAndSizeProvider rootElementLocationAndSizerProvider(WebElement optionalRootWebElement) {111 if (optionalRootWebElement == null) {112 return null;113 }114 return new WebElementLocationAndSizeProvider() {115 @Override116 public Point getLocation() {117 return optionalRootWebElement.getLocation();118 }119 @Override120 public Dimension getSize() {121 return optionalRootWebElement.getSize();122 }123 };124 }125 private TakesScreenshot getScreenshotTaker() {126 return (TakesScreenshot) this.driver;127 }128 private void createAnnotations(WebElement optionalRootWebElement, Number pixelRatio, String screenshotName) {129 Point rootPoint = findRootLocation(optionalRootWebElement);130 List<? extends Map<String, ?>> shapes = annotations.stream()131 .map((annotation) -> createAnnotationData(annotation, rootPoint)).collect(toList());132 Map<String, Object> result = new HashMap<>();133 result.put("shapes", shapes);134 result.put("pixelRatio", pixelRatio);135 String annotationsJson = JsonUtils.serializePrettyPrint(result);136 FileUtils.writeTextContent(getCfg().getDocArtifactsPath().resolve(Paths.get(screenshotName + ".json")),137 annotationsJson);138 }139 private Map<String, ?> createAnnotationData(ImageAnnotation annotation, Point rootPoint) {140 Map<String, Object> data = new LinkedHashMap<>();141 data.put("type", annotation.getType());142 data.put("text", annotation.getText());143 List<PageElement> pageElements = annotation.getPageElements();144 pageElements.forEach(pageElement -> pageElement.should(new VisibleValueMatcher()));145 List<WebElementLocationAndSizeProvider> locationAndSizeProviders = pageElements.stream()146 .map(pe -> createAdjustedForRootLocationAndSizeProvider(rootPoint, pe.findElement()))147 .collect(toList());148 annotation.addAnnotationData(data, locationAndSizeProviders);149 return data;150 }151 private List<ImageAnnotation> assignDefaultText(List<ImageAnnotation> annotations) {152 int badgeNumber = 0;153 for (ImageAnnotation annotation : annotations) {154 if (annotation instanceof BadgeImageAnnotation) {155 badgeNumber++;156 annotation.setText(String.valueOf(badgeNumber));157 }158 }159 return annotations;160 }161 private Number detectPixelRatio() {162 Object pixelRatio = ((JavascriptExecutor) driver).executeScript("return window.devicePixelRatio");163 return pixelRatio instanceof Number ? (Number) pixelRatio : 1;164 }165 private WebElementLocationAndSizeProvider createAdjustedForRootLocationAndSizeProvider(Point rootPoint,166 WebElement webElement) {167 return new WebElementLocationAndSizeProvider() {168 @Override...
Source:ImageAnnotation.java
...23import java.util.Map;24import java.util.concurrent.atomic.AtomicInteger;25import java.util.stream.Collectors;26import java.util.stream.Stream;27public abstract class ImageAnnotation {28 public enum Placement {29 Center,30 Above,31 Below,32 ToTheLeft,33 ToTheRight34 }35 private static final AtomicInteger idGen = new AtomicInteger();36 private final String id;37 private final String type;38 private String text;39 private final List<PageElement> pageElements;40 protected Placement placement;41 public ImageAnnotation(Stream<PageElement> pageElements, String type, String text) {42 this.id = type + idGen.incrementAndGet();43 this.pageElements = pageElements.collect(Collectors.toList());44 this.type = type;45 this.text = text;46 this.placement = Placement.Center;47 }48 public String getId() {49 return id;50 }51 public String getType() {52 return type;53 }54 public List<PageElement> getPageElements() {55 return Collections.unmodifiableList(pageElements);56 }57 public String getText() {58 return text;59 }60 public void setText(String text) {61 this.text = text;62 }63 public ImageAnnotation above() {64 placement = Placement.Above;65 return this;66 }67 public ImageAnnotation below() {68 placement = Placement.Below;69 return this;70 }71 public ImageAnnotation toTheLeft() {72 placement = Placement.ToTheLeft;73 return this;74 }75 public ImageAnnotation toTheRight() {76 placement = Placement.ToTheRight;77 return this;78 }79 public abstract void addAnnotationData(Map<String, Object> data,80 List<WebElementLocationAndSizeProvider> locationAndSizeProviders);81 protected Point position(WebElementLocationAndSizeProvider locationAndSizeProvider) {82 switch (placement) {83 case Above:84 return above(locationAndSizeProvider.getLocation(), locationAndSizeProvider.getSize());85 case Below:86 return below(locationAndSizeProvider.getLocation(), locationAndSizeProvider.getSize());87 case ToTheLeft:88 return toTheLeft(locationAndSizeProvider.getLocation(), locationAndSizeProvider.getSize());89 case ToTheRight:...
Source:BadgeImageAnnotation.java
...19import org.openqa.selenium.Point;20import java.util.List;21import java.util.Map;22import java.util.stream.Stream;23public class BadgeImageAnnotation extends ImageAnnotation {24 public BadgeImageAnnotation(PageElement pageElement, String text) {25 super(Stream.of(pageElement), "badge", text);26 }27 @Override28 public void addAnnotationData(Map<String, Object> data, List<WebElementLocationAndSizeProvider> locationAndSizeProviders) {29 Point location = position(locationAndSizeProviders.get(0));30 data.put("x", location.getX());31 data.put("y", location.getY());32 data.put("align", placement);33 }34}...
ImageAnnotation
Using AI Code Generation
1package org.testingisdocumenting.webtau.docs;2import org.testingisdocumenting.webtau.browser.documentation.ImageAnnotation;3import org.testingisdocumenting.webtau.reporter.IntegrationTestsMessageBuilder;4import org.testingisdocumenting.webtau.reporter.TokenizedMessage;5import org.testingisdocumenting.webtau.reporter.WebTauStep;6import static org.testingisdocumenting.webtau.Ddjt.*;7@ImageAnnotation(imagePath = "2.png", x = 10, y = 10)8public class ImageAnnotation2 {9 public static void main(String[] args) {10 WebTauStep step = WebTauStep.createAndStart("step1", () -> {});11 step.end();12 IntegrationTestsMessageBuilder builder = new IntegrationTestsMessageBuilder();13 builder.put("step1", step);14 TokenizedMessage message = builder.build();15 console.report(message);16 }17}18package org.testingisdocumenting.webtau.docs;19import org.testingisdocumenting.webtau.browser.documentation.ImageAnnotation;20import org.testingisdocumenting.webtau.reporter.IntegrationTestsMessageBuilder;21import org.testingisdocumenting.webtau.reporter.TokenizedMessage;22import org.testingisdocumenting.webtau.reporter.WebTauStep;23import static org.testingisdocumenting.webtau.Ddjt.*;24@ImageAnnotation(imagePath = "3.png", x = 10, y = 10)25public class ImageAnnotation3 {26 public static void main(String[] args) {27 WebTauStep step = WebTauStep.createAndStart("step1", () -> {});28 step.end();29 IntegrationTestsMessageBuilder builder = new IntegrationTestsMessageBuilder();30 builder.put("step1", step);31 TokenizedMessage message = builder.build();32 console.report(message);33 }34}35package org.testingisdocumenting.webtau.docs;36import org.testingisdocumenting.webtau.browser.documentation.ImageAnnotation;37import org.testingisdocumenting.webtau.reporter.IntegrationTestsMessageBuilder;38import org.testingisdocumenting.webtau.reporter.TokenizedMessage;39import org.testingisdocumenting.webtau.reporter.Web
ImageAnnotation
Using AI Code Generation
1import org.testingisdocumenting.webtau.browser.documentation.ImageAnnotation;2import org.testingisdocumenting.webtau.DD;3import org.testingisdocumenting.webtau.browser.page.BrowserPage;4import org.testingisdocumenting.webtau.browser.page.BrowserPageElement;5import org.testingisdocumenting.webtau.browser.page.BrowserPageElementLocation;6public class ImageAnnotationExample {7 public static void main(String[] args) {8 BrowserPage page = new BrowserPage();9 BrowserPageElement searchBox = page.get("input[name='q']");10 BrowserPageElementLocation location = searchBox.getLocation();11 ImageAnnotation.annotate(location, "Search box");12 DD.image(location);13 }14}
ImageAnnotation
Using AI Code Generation
1import org.testingisdocumenting.webtau.browser.documentation.ImageAnnotation;2import org.testingisdocumenting.webtau.Ddjt;3import org.testingisdocumenting.webtau.reporter.IntegrationTestsMessageBuilder;4public class Two {5 private static final IntegrationTestsMessageBuilder msgBuilder = Ddjt.msgBuilder("two");6 public static void main(String[] args) {7 msgBuilder.text("before");8 ImageAnnotation.imageAnnotation("2.png");9 msgBuilder.text("after");10 }11}12import org.testingisdocumenting.webtau.browser.documentation.ImageAnnotation;13import org.testingisdocumenting.webtau.Ddjt;14import org.testingisdocumenting.webtau.reporter.IntegrationTestsMessageBuilder;15public class One {16 private static final IntegrationTestsMessageBuilder msgBuilder = Ddjt.msgBuilder("one");17 public static void main(String[] args) {18 msgBuilder.text("before");19 ImageAnnotation.imageAnnotation("1.png");20 msgBuilder.text("after");21 }22}23import org.testingisdocumenting.webtau.browser.documentation.ImageAnnotation;24import org.testingisdocumenting.webtau.Ddjt;25import org.testingisdocumenting.webtau.reporter.IntegrationTestsMessageBuilder;26public class Three {27 private static final IntegrationTestsMessageBuilder msgBuilder = Ddjt.msgBuilder("three");28 public static void main(String[] args) {29 msgBuilder.text("before");30 ImageAnnotation.imageAnnotation("3.png");31 msgBuilder.text("after");32 }33}34import org.testingisdocumenting.webtau.browser.documentation.ImageAnnotation;35import org.testingisdocumenting.webtau.Ddjt;36import org.testingisdocumenting.webtau.reporter.IntegrationTestsMessageBuilder;37public class Four {38 private static final IntegrationTestsMessageBuilder msgBuilder = Ddjt.msgBuilder("four");39 public static void main(String[] args) {40 msgBuilder.text("before");41 ImageAnnotation.imageAnnotation("4.png");42 msgBuilder.text("after");43 }44}
ImageAnnotation
Using AI Code Generation
1import org.testingisdocumenting.webtau.Ddjt;2import org.testingisdocumenting.webtau.browser.Browser;3import org.testingisdocumenting.webtau.documentation.ImageAnnotation;4Ddjt.imageAnnotation("webtau home page", ImageAnnotation.of(5 ImageAnnotation.rect(100, 200, 300, 400, "some text"),6 ImageAnnotation.rect(200, 300, 400, 500, "some other text")7import org.testingisdocumenting.webtau.Ddjt;8import org.testingisdocumenting.webtau.browser.Browser;9import org.testingisdocumenting.webtau.documentation.ImageAnnotation;10Ddjt.imageAnnotation("webtau home page", ImageAnnotation.of(11 ImageAnnotation.rect(100, 200, 300, 400, "some text"),12 ImageAnnotation.rect(200, 300, 400, 500, "some other text")13import org.testingisdocumenting.webtau.Ddjt;14import org.testingisdocumenting.webtau.browser.Browser;15import org.testingisdocumenting.webtau.documentation.ImageAnnotation;16Ddjt.imageAnnotation("webtau home page", ImageAnnotation.of(17 ImageAnnotation.rect(100, 200, 300, 400, "some text"),18 ImageAnnotation.rect(200, 300, 400, 500, "some other text")19import org.testingisdocumenting.webtau.Ddjt;20import org.testingisdocumenting.webtau.browser.Browser;21import org.testingisdocumenting.webtau.documentation.ImageAnnotation;22Ddjt.imageAnnotation("webtau home page", ImageAnnotation.of(23 ImageAnnotation.rect(100,
ImageAnnotation
Using AI Code Generation
1import org.testingisdocumenting.webtau.browser.documentation.ImageAnnotation;2import org.testingisdocumenting.webtau.browser.page.BrowserPage;3import org.testingisdocumenting.webtau.http.Http;4import org.testingisdocumenting.webtau.reporter.IntegrationTestsMessageBuilder;5import org.testingisdocumenting.webtau.reporter.WebTauStep;6import org.testingisdocumenting.webtau.reporter.WebTauStepGroup;7import org.testingisdocumenting.webtau.reporter.WebTauStepGroupType;8import org.testingisdocumenting.webtau.reporter.WebTauStepPayload;9import org.testingisdocumenting.webtau.reporter.WebTauStepPayloadType;10public class ImageAnnotationExample {11 public void openPage() {12 BrowserPage browser = Http.http().get("/browser.html").browser();13 browser.navigateTo("/browser.html");14 WebTauStepGroup subGroup = new WebTauStepGroup(WebTauStepGroupType.ANNOTATION, "sub group");15 subGroup.addStep(new WebTauStep("image annotation", null, new WebTauStepPayload(ImageAnnotation.imageAnnotation("hello world"))));16 subGroup.addStep(new WebTauStep("image annotation", null, new WebTauStepPayload(ImageAnnotation.imageAnnotation("hello world", 100, 200))));17 subGroup.addStep(new WebTauStep("image annotation", null, new WebTauStepPayload(ImageAnnotation.imageAnnotation("hello world", 100, 200, 300, 400))));18 subGroup.addStep(new WebTauStep("image annotation", null, new WebTauStepPayload(ImageAnnotation.imageAnnotation("hello world", 100, 200, 300, 400, "red"))));19 subGroup.addStep(new WebTauStep("image annotation", null, new WebTauStepPayload(ImageAnnotation.imageAnnotation("hello world", 100, 200, 300, 400, "red", "green"))));20 subGroup.addStep(new WebTauStep("image annotation", null, new WebTauStepPayload(ImageAnnotation.imageAnnotation("hello world", 100, 200, 300, 400, "red", "green", "blue"))));21 subGroup.addStep(new WebTauStep("image annotation", null, new WebTauStepPayload(ImageAnnotation.imageAnnotation("hello world", 100, 200, 300, 400, "red", "green",
ImageAnnotation
Using AI Code Generation
1import org.testingisdocumenting.webtau.browser.documentation.ImageAnnotation;2import org.testingisdocumenting.webtau.Ddjt;3import java.io.File;4public class 2 {5 public static void main(String[] args) {6 ImageAnnotation imageAnnotation = new ImageAnnotation();7 imageAnnotation.addImageAnnotationToTestReport(new File("src/main/resources/2.png"));8 }9}10import org.testingisdocumenting.webtau.browser.documentation.ImageAnnotation;11import org.testingisdocumenting.webtau.Ddjt;12import java.io.File;13public class 3 {14 public static void main(String[] args) {15 ImageAnnotation imageAnnotation = new ImageAnnotation();16 imageAnnotation.addImageAnnotationToTestReport(new File("src/main/resources/3.png"));17 }18}19import org.testingisdocumenting.webtau.browser.documentation.ImageAnnotation;20import org.testingisdocumenting.webtau.Ddjt;21import java.io.File;22public class 4 {23 public static void main(String[] args) {24 ImageAnnotation imageAnnotation = new ImageAnnotation();25 imageAnnotation.addImageAnnotationToTestReport(new File("src/main/resources/4.png"));26 }27}28import org.testingisdocumenting.webtau.browser.documentation.ImageAnnotation;29import org.testingisdocumenting.webtau.Ddjt;30import java.io.File;31public class 5 {32 public static void main(String[] args) {33 ImageAnnotation imageAnnotation = new ImageAnnotation();34 imageAnnotation.addImageAnnotationToTestReport(new File("src/main/resources/5.png"));35 }36}37import org.testingisdocumenting.webtau.browser.documentation.ImageAnnotation;38import org.testingisdocumenting.webtau.Ddjt;39import java.io
ImageAnnotation
Using AI Code Generation
1import org.junit.Test;2import org.testingisdocumenting.webtau.Ddjt;3import org.testingisdocumenting.webtau.browser.Browser;4import org.testingisdocumenting.webtau.browser.documentation.ImageAnnotation;5public class 2 {6 public void annotateWebPageWithText() {7 ImageAnnotation.annotate("text to annotate page with");8 Ddjt.sleep(3000);9 }10}11import org.junit.Test;12import org.testingisdocumenting.webtau.Ddjt;13import org.testingisdocumenting.webtau.browser.Browser;14import org.testingisdocumenting.webtau.browser.documentation.ImageAnnotation;15public class 3 {16 public void annotateWebPageWithRectangle() {17 ImageAnnotation.annotate(0, 0, 100, 100);18 Ddjt.sleep(3000);19 }20}21import org.junit.Test;22import org.testingisdocumenting.webtau.Ddjt;23import org.testingisdocumenting.webtau.browser.Browser;24import org.testingisdocumenting.webtau.browser.documentation.ImageAnnotation;25public class 4 {26 public void annotateWebPageWithRectangleAndText() {27 ImageAnnotation.annotate(0, 0, 100, 100, "text to annotate page with");28 Ddjt.sleep(3000);29 }30}
ImageAnnotation
Using AI Code Generation
1import org.testingisdocumenting.webtau.browser.documentation.ImageAnnotation;2import org.testingisdocumenting.webtau.browser.documentation.ImageAnnotation;3import org.testingisdocumenting.webtau.browser.documentation.ImageAnnotation;4import org.testingisdocumenting.webtau.browser.documentation.ImageAnnotation;5import org.testingisdocumenting.webtau.browser.documentation.ImageAnnotation;6import org.testingisdocumenting.webtau.browser.documentation.ImageAnnotation;
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!!