Skip to content

Commit

Permalink
[java] Fixing format of element screenshot command
Browse files Browse the repository at this point in the history
  • Loading branch information
barancev committed Dec 10, 2017
1 parent 0ebad53 commit f3e776f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public AbstractHttpCommandCodec() {

defineCommand(UPLOAD_FILE, post("/session/:sessionId/file"));
defineCommand(SCREENSHOT, get("/session/:sessionId/screenshot"));
defineCommand(ELEMENT_SCREENSHOT, get("/session/:sessionId/screenshot/:id"));
defineCommand(ELEMENT_SCREENSHOT, get("/session/:sessionId/element/:id/screenshot"));
defineCommand(GET_TITLE, get("/session/:sessionId/title"));

defineCommand(FIND_ELEMENT, post("/session/:sessionId/element"));
Expand Down
24 changes: 24 additions & 0 deletions java/client/test/org/openqa/selenium/TakesScreenshotTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.openqa.selenium;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
Expand Down Expand Up @@ -141,6 +142,29 @@ && getEffectivePlatform(driver).is(LINUX)
compareColors(expectedColors, actualColors);
}

@Test
@Ignore(value = CHROME)
@Ignore(value = FIREFOX)
@Ignore(value = IE)
@Ignore(value = SAFARI)
public void testShouldCaptureScreenshotOfAnElement() throws Exception {
driver.get(appServer.whereIs("screen/screen.html"));
WebElement element = driver.findElement(By.id("cell11"));

byte[] imageData = element.getScreenshotAs(OutputType.BYTES);
assertTrue(imageData != null);
assertTrue(imageData.length > 0);
BufferedImage image = ImageIO.read(new ByteArrayInputStream(imageData));
assertTrue(image != null);

Raster raster = image.getRaster();
String hex = String.format("#%02x%02x%02x",
(raster.getSample(1, 1, 0)),
(raster.getSample(1, 1, 1)),
(raster.getSample(1, 1, 2)));
assertEquals("#0f12f7", hex);
}

@Test
@Ignore(value = SAFARI, reason = "takes only visible viewport")
@Ignore(value = CHROME, reason = "takes only visible viewport")
Expand Down

0 comments on commit f3e776f

Please sign in to comment.