How to use ImageAnnotation class of org.testingisdocumenting.webtau.browser.documentation package

Best Webtau code snippet using org.testingisdocumenting.webtau.browser.documentation.ImageAnnotation

Source:BrowserDocumentation.java Github

copy

Full Screen

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

Full Screen

Full Screen

Source:ImageAnnotation.java Github

copy

Full Screen

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

Full Screen

Full Screen

Source:BadgeImageAnnotation.java Github

copy

Full Screen

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

Full Screen

Full Screen

ImageAnnotation

Using AI Code Generation

copy

Full Screen

1import org.testingisdocumenting.webtau.WebTauDsl.*;2import org.testingisdocumenting.webtau.browser.documentation.ImageAnnotation;3import static org.testingisdocumenting.webtau.Docs.doc;4public class ImageAnnotationExample {5 public static void main(String[] args) {6 doc("image annotation", () -> {7 image.annotate(100, 100, "cheese");8 image.annotate(200, 200, "cheese");9 image.annotate(300, 300, "cheese");10 image.annotate(100, 100, "cheese");11 image.annotate(200, 200, "cheese");12 image.annotate(300, 300, "cheese");13 image.annotate(100, 100, "cheese");14 image.annotate(200, 200, "cheese");15 image.annotate(300, 300, "cheese");16 image.annotate(100, 100, "cheese");17 image.annotate(200, 200, "cheese");18 image.annotate(300, 300, "cheese");19 image.annotate(100, 100, "cheese");20 image.annotate(200, 200, "cheese");21 image.annotate(300, 300, "cheese");22 image.annotate(100, 100, "cheese");23 image.annotate(200, 200, "cheese");24 image.annotate(300, 300, "cheese");25 image.annotate(100, 100, "cheese");26 image.annotate(200, 200, "cheese");27 image.annotate(300, 300, "cheese");28 image.annotate(100, 100, "cheese");29 image.annotate(200, 200, "cheese");30 image.annotate(300, 300, "cheese");31 image.annotate(100, 100, "cheese");32 image.annotate(200, 200, "cheese");33 image.annotate(300, 300, "cheese");34 image.annotate(100, 100, "cheese");35 image.annotate(200, 200, "cheese");36 image.annotate(300, 300, "cheese");37 image.annotate(100, 100, "cheese");38 image.annotate(200,

Full Screen

Full Screen

ImageAnnotation

Using AI Code Generation

copy

Full Screen

1import org.testingisdocumenting.webtau.browser.documentation.ImageAnnotation;2import org.testingisdocumenting.webtau.browser.documentation.ImageAnnotationBuilder;3import static org.testingisdocumenting.webtau.Ddjt.*;4public class 2 {5 public ImageAnnotation imageAnnotation() {6 return imageAnnotationBuilder()7 .withImage("image.png")8 .withText(

Full Screen

Full Screen

ImageAnnotation

Using AI Code Generation

copy

Full Screen

1import org.testingisdocumenting.webtau.Ddjt;2import org.testingisdocumenting.webtau.browser.documentation.ImageAnnotation;3public class 2 {4 public void shouldHaveImageAnnotation() {5 ImageAnnotation imageAnnotation = new ImageAnnotation();6 imageAnnotation.screenshot("screenshot-1");7 imageAnnotation.text("text-1");8 imageAnnotation.screenshot("screenshot-2");9 imageAnnotation.text("text-2");10 imageAnnotation.screenshot("screenshot-3");11 Ddjt.doc(imageAnnotation);12 }13}14import org.testingisdocumenting.webtau.Ddjt;15import org.testingisdocumenting.webtau.browser.documentation.ImageAnnotation;16public class 3 {17 public void shouldHaveImageAnnotation() {18 ImageAnnotation imageAnnotation = new ImageAnnotation();19 imageAnnotation.screenshot("screenshot-1");20 imageAnnotation.text("text-1");21 imageAnnotation.screenshot("screenshot-2");22 imageAnnotation.text("text-2");23 imageAnnotation.screenshot("screenshot-3");24 Ddjt.doc(imageAnnotation);25 }26}27import org.testingisdocumenting.webtau.Ddjt;28import org.testingisdocumenting.webtau.browser.documentation.ImageAnnotation;29public class 4 {30 public void shouldHaveImageAnnotation() {31 ImageAnnotation imageAnnotation = new ImageAnnotation();32 imageAnnotation.screenshot("screenshot-1");33 imageAnnotation.text("text-1");34 imageAnnotation.screenshot("screenshot-2");35 imageAnnotation.text("text-2");36 imageAnnotation.screenshot("screenshot-3");37 Ddjt.doc(imageAnnotation);38 }39}

Full Screen

Full Screen

ImageAnnotation

Using AI Code Generation

copy

Full Screen

1ImageAnnotation annotation = new ImageAnnotation();2annotation.setLabel("my label");3annotation.setX(10);4annotation.setY(20);5annotation.setW(30);6annotation.setH(40);7ImageAnnotation annotation = new ImageAnnotation(10, 20, 30, 40);8annotation.setLabel("my label");9ImageAnnotation annotation = new ImageAnnotation(10, 20, 30, 40, "my label");10ImageAnnotation annotation = new ImageAnnotation(10, 20, 30, 40, "my label", "my color");11ImageAnnotation annotation = new ImageAnnotation(10, 20, 30, 40, "my label", "my color", "my font");12ImageAnnotation annotation = new ImageAnnotation(10, 20, 30, 40, "my label", "my color", "my font", 12);13ImageAnnotation annotation = new ImageAnnotation(10, 20, 30, 40, "my label", "my color", "my font", 12, "my font style");14ImageAnnotation annotation = new ImageAnnotation(10, 20, 30, 40, "my label", "my color", "my font", 12, "my font style", "my font weight");15ImageAnnotation annotation = new ImageAnnotation(10, 20, 30, 40, "my label", "my color", "my font", 12, "my font style", "my font weight", "my text align");16ImageAnnotation annotation = new ImageAnnotation(10, 20, 30,

Full Screen

Full Screen

ImageAnnotation

Using AI Code Generation

copy

Full Screen

1import org.testingisdocumenting.webtau.browser.documentation.ImageAnnotation;2import org.testingisdocumenting.webtau.Docs;3import org.testingisdocumenting.webtau.reporter.IntegrationTestsMessageBuilder;4import static org.testingisdocumenting.webtau.Docs.*;5public class 2 {6 public void test() {7 Docs.annotate("some text to be annotated");8 Docs.annotate(new ImageAnnotation("some text to be annotated", 0.5, 0.5, 0.5, 0.5));9 }10}11import org.testingisdocumenting.webtau.browser.documentation.ImageAnnotation;12import org.testingisdocumenting.webtau.Docs;13import org.testingisdocumenting.webtau.reporter.IntegrationTestsMessageBuilder;14import static org.testingisdocumenting.webtau.Docs.*;15public class 3 {16 public void test() {17 Docs.annotate("some text to be annotated");18 Docs.annotate(new ImageAnnotation("some text to be annotated", 0.5, 0.5, 0.5, 0.5));19 }20}21import org.testingisdocumenting.webtau.browser.documentation.ImageAnnotation;22import org.testing

Full Screen

Full Screen

ImageAnnotation

Using AI Code Generation

copy

Full Screen

1import org.testingisdocumenting.webtau.Docs;2import org.testingisdocumenting.webtau.browser.Browser;3import org.testingisdocumenting.webtau.browser.documentation.ImageAnnotation;4public class 2 {5 public void test() {6 ImageAnnotation imageAnnotation = new ImageAnnotation();7 imageAnnotation.addText("This is a text annotation");8 imageAnnotation.addImage("src/test/resources/image.png");9 Browser.screenshot("screenshot1", imageAnnotation);10 }11}12import org.testingisdocumenting.webtau.Docs;13import org.testingisdocumenting.webtau.browser.Browser;14import org.testingisdocumenting.webtau.browser.documentation.ImageAnnotation;15public class 3 {16 public void test() {17 Browser.screenshot("screenshot1", new ImageAnnotation()18 .addText("This is a text annotation")19 .addImage("src/test/resources/image.png"));20 }21}22import org.testingisdocumenting.webtau.Docs;23import org.testingisdocumenting.webtau.browser.Browser;24import org.testingisdocumenting.webtau.browser.documentation.ImageAnnotation;25public class 4 {26 public void test() {

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 Webtau automation tests on LambdaTest cloud grid

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

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful