Skip to content
Permalink
Browse files

add highlight browser.doc annotation (#410)

  • Loading branch information...
MykolaGolubyev committed Aug 12, 2019
1 parent 366f7fe commit ef0635444e98ad1df6b8902c2484336d0b61fb48
@@ -53,10 +53,18 @@ public static ImageAnnotation badge(PageElement pageElement) {
return new BadgeImageAnnotation(pageElement, "");
}

public static ImageAnnotation highlighter(PageElement pageElement) {
public static ImageAnnotation highlight(PageElement pageElement) {
return new HighlighterImageAnnotation(pageElement);
}

public static ImageAnnotation cover(PageElement pageElement) {
return new RectangleImageAnnotation(pageElement, "");
}

public static ImageAnnotation cover(PageElement pageElement, String text) {
return new RectangleImageAnnotation(pageElement, text);
}

public static ImageAnnotation arrow(PageElement pageElement, String text) {
return new ArrowImageAnnotation(pageElement, text);
}
@@ -17,25 +17,9 @@
package com.twosigma.webtau.browser.documentation;

import com.twosigma.webtau.browser.page.PageElement;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebElement;

import java.util.Map;

public class HighlighterImageAnnotation extends ImageAnnotation {
public class HighlighterImageAnnotation extends RectangleBasedImageAnnotation {
public HighlighterImageAnnotation(PageElement pageElement) {
super(pageElement, "rectangle", "");
}

@Override
public void addAnnotationData(Map<String, Object> data, WebElement webElement) {
Point location = webElement.getLocation();
Dimension size = webElement.getSize();

data.put("x", location.getX());
data.put("y", location.getY());
data.put("width", size.getWidth());
data.put("height", size.getHeight());
super(pageElement, "highlight", "");
}
}
@@ -0,0 +1,41 @@
/*
* Copyright 2019 TWO SIGMA OPEN SOURCE, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.twosigma.webtau.browser.documentation;

import com.twosigma.webtau.browser.page.PageElement;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebElement;

import java.util.Map;

public class RectangleBasedImageAnnotation extends ImageAnnotation {
public RectangleBasedImageAnnotation(PageElement pageElement, String type, String text) {
super(pageElement, type, text);
}

@Override
public void addAnnotationData(Map<String, Object> data, WebElement webElement) {
Point location = webElement.getLocation();
Dimension size = webElement.getSize();

data.put("x", location.getX());
data.put("y", location.getY());
data.put("width", size.getWidth());
data.put("height", size.getHeight());
}
}
@@ -0,0 +1,25 @@
/*
* Copyright 2019 TWO SIGMA OPEN SOURCE, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.twosigma.webtau.browser.documentation;

import com.twosigma.webtau.browser.page.PageElement;

public class RectangleImageAnnotation extends RectangleBasedImageAnnotation {
public RectangleImageAnnotation(PageElement pageElement, String text) {
super(pageElement, "rectangle", text);
}
}
@@ -9,7 +9,7 @@ With UI testing we can validate scenarios and at the same time capture screensho

To capture screenshots use `browser.doc[.withAnnotations].capture`:

:include-file: scenarios/ui/docCapture.groovy {title: "docCapture"}
:include-file: doc-artifacts/snippets/doc-capture/captureBadges.groovy {title: "screenshot capture with badge annotations"}

The result of the `capture` command is two files: actual screenshot and `annotations.json`.

@@ -22,3 +22,10 @@ The result of the `capture` command is two files: actual screenshot and `annotat

:include-image: doc-artifacts/ui/search.png {annotationsPath: "doc-artifacts/ui/search.json"}

# Annotation Types

:include-file: doc-artifacts/snippets/doc-capture/captureBadges.groovy {title: "badges"}
:include-image: doc-artifacts/ui/search.png {annotationsPath: "doc-artifacts/ui/search.json"}

:include-file: doc-artifacts/snippets/doc-capture/captureHighlightCover.groovy {title: "cover and highlight"}
:include-image: doc-artifacts/ui/search-highlight-cover.png {annotationsPath: "doc-artifacts/ui/search-highlight-cover.json"}
@@ -0,0 +1,4 @@
url = "http://localhost:8180"

windowWidth = 1000
windowHeight = 240
@@ -3,10 +3,25 @@ package scenarios.ui
import static com.twosigma.webtau.WebTauGroovyDsl.*
import static pages.Pages.*

scenario('search and capture') {
scenario('restart browser to use a config size') {
browser.restart()
}

scenario('search and capture with badges') {
search.submit("search this")

browser.doc.withAnnotations(
browser.doc.badge(search.box),
browser.doc.badge(search.results)).capture('search')
}

scenario('capture with highlight and cover') {
browser.doc.withAnnotations(
browser.doc.highlight(search.box),
browser.doc.cover(search.results, "covering text")).capture('search-highlight-cover')
}

scenario('capture with arrow') {
browser.doc.withAnnotations(
browser.doc.arrow(search.box, "type to search")).capture('search-arrow')
}
@@ -245,7 +245,18 @@ class WebTauUiFeaturesTest {

@Test
void "documentation capture"() {
runCli('docCapture.groovy', 'webtau.cfg')
runCli('docCapture.groovy', 'docCapture.cfg')
}

@Test
void "doc capture extract snippets"() {
extractCodeSnippets(
'doc-artifacts/snippets/doc-capture',
'examples/scenarios/ui/docCapture.groovy', [
'captureBadges.groovy': 'search and capture with badges',
'captureHighlightCover.groovy': 'capture with highlight and cover',
'captureArrow.groovy': 'capture with arrow',
])
}

private static void extractHtmlSnippets(String extractedPath, String resourceName, Map<String, String> cssToOutputFile) {
@@ -50,6 +50,7 @@
var results = document.getElementById("results");
addTo(results, "result", "Result #1");
addTo(results, "result", "Result #2");
addTo(results, "result", "Result #3");
}
function addTo(node, className, text) {
@@ -1,10 +1,24 @@
{
"scenarioDetails" : [ {
"scenario" : "search and capture",
"scenario" : "restart browser to use a config size",
"shortContainerId" : "docCapture.groovy",
"stepsSummary" : {
"numberOfSuccessful" : 3
}
}, {
"scenario" : "search and capture with badges",
"shortContainerId" : "docCapture.groovy",
"stepsSummary" : {
"numberOfSuccessful" : 5
}
}, {
"scenario" : "capture with highlight and cover",
"shortContainerId" : "docCapture.groovy",
"stepsSummary" : { }
}, {
"scenario" : "capture with arrow",
"shortContainerId" : "docCapture.groovy",
"stepsSummary" : { }
} ],
"exitCode" : 0
}
@@ -21,7 +21,7 @@ scenario('customer update http calls') {
report.expandHttpCall(2)

browser.doc.withAnnotations(
browser.doc.highlighter(report.fullScreenIcon),
browser.doc.highlighter(report.collapsedHeader))
browser.doc.highlight(report.fullScreenIcon),
browser.doc.highlight(report.collapsedHeader))
.capture('report-crud-separated-http-calls')
}

0 comments on commit ef06354

Please sign in to comment.
You can’t perform that action at this time.