|
17 | 17 |
|
18 | 18 | package org.openqa.selenium;
|
19 | 19 |
|
| 20 | +import static org.junit.Assert.assertEquals; |
20 | 21 | import static org.junit.Assert.assertFalse;
|
21 | 22 | import static org.junit.Assert.assertTrue;
|
22 | 23 | import static org.junit.Assert.fail;
|
@@ -141,6 +142,29 @@ && getEffectivePlatform(driver).is(LINUX)
|
141 | 142 | compareColors(expectedColors, actualColors);
|
142 | 143 | }
|
143 | 144 |
|
| 145 | + @Test |
| 146 | + @Ignore(value = CHROME) |
| 147 | + @Ignore(value = FIREFOX) |
| 148 | + @Ignore(value = IE) |
| 149 | + @Ignore(value = SAFARI) |
| 150 | + public void testShouldCaptureScreenshotOfAnElement() throws Exception { |
| 151 | + driver.get(appServer.whereIs("screen/screen.html")); |
| 152 | + WebElement element = driver.findElement(By.id("cell11")); |
| 153 | + |
| 154 | + byte[] imageData = element.getScreenshotAs(OutputType.BYTES); |
| 155 | + assertTrue(imageData != null); |
| 156 | + assertTrue(imageData.length > 0); |
| 157 | + BufferedImage image = ImageIO.read(new ByteArrayInputStream(imageData)); |
| 158 | + assertTrue(image != null); |
| 159 | + |
| 160 | + Raster raster = image.getRaster(); |
| 161 | + String hex = String.format("#%02x%02x%02x", |
| 162 | + (raster.getSample(1, 1, 0)), |
| 163 | + (raster.getSample(1, 1, 1)), |
| 164 | + (raster.getSample(1, 1, 2))); |
| 165 | + assertEquals("#0f12f7", hex); |
| 166 | + } |
| 167 | + |
144 | 168 | @Test
|
145 | 169 | @Ignore(value = SAFARI, reason = "takes only visible viewport")
|
146 | 170 | @Ignore(value = CHROME, reason = "takes only visible viewport")
|
|
0 commit comments