Commit b1a9183d authored by Tatiana Buldina's avatar Tatiana Buldina Committed by Commit Bot

[ChromeDriver] Add test for take element screenshot

Change-Id: I9c6f935e3ce9b55297151dd8eabc57c15754081b
Reviewed-on: https://chromium-review.googlesource.com/1204850
Commit-Queue: Tatiana Buldina <buldina@chromium.org>
Reviewed-by: default avatarJohn Chen <johnchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#589005}
parent 3865fddc
...@@ -161,6 +161,10 @@ class ChromeDriver(object): ...@@ -161,6 +161,10 @@ class ChromeDriver(object):
# https://bugs.chromium.org/p/chromedriver/issues/detail?id=1695 # https://bugs.chromium.org/p/chromedriver/issues/detail?id=1695
chrome_switches.append('disable-gpu') chrome_switches.append('disable-gpu')
if chrome_switches is None:
chrome_switches = []
chrome_switches.append('force-color-profile=srgb')
if chrome_switches: if chrome_switches:
assert type(chrome_switches) is list assert type(chrome_switches) is list
options['args'] = chrome_switches options['args'] = chrome_switches
...@@ -491,6 +495,9 @@ class ChromeDriver(object): ...@@ -491,6 +495,9 @@ class ChromeDriver(object):
def FullScreenWindow(self): def FullScreenWindow(self):
return self.ExecuteCommand(Command.FULLSCREEN_WINDOW) return self.ExecuteCommand(Command.FULLSCREEN_WINDOW)
def TakeScreenshot(self):
return self.ExecuteCommand(Command.SCREENSHOT)
def Quit(self): def Quit(self):
"""Quits the browser and ends the session.""" """Quits the browser and ends the session."""
self.ExecuteCommand(Command.QUIT) self.ExecuteCommand(Command.QUIT)
......
...@@ -66,3 +66,6 @@ class WebElement(object): ...@@ -66,3 +66,6 @@ class WebElement(object):
def IsDisplayed(self): def IsDisplayed(self):
return self._Execute(Command.IS_ELEMENT_DISPLAYED) return self._Execute(Command.IS_ELEMENT_DISPLAYED)
def TakeElementScreenshot(self):
return self._Execute(Command.ELEMENT_SCREENSHOT)
...@@ -1696,6 +1696,19 @@ class ChromeDriverTest(ChromeDriverBaseTestWithWebServer): ...@@ -1696,6 +1696,19 @@ class ChromeDriverTest(ChromeDriverBaseTestWithWebServer):
self._driver.FindElement('id', 'top') self._driver.FindElement('id', 'top')
thread.join() thread.join()
def testTakeElementScreenshot(self):
self._driver.Load(self.GetHttpUrlForFile(
'/chromedriver/page_with_redBox.html'))
elementScreenshot = self._driver.FindElement(
'id', 'box').TakeElementScreenshot()
self.assertIsNotNone(elementScreenshot)
dataActualScreenshot = base64.b64decode(elementScreenshot)
filenameOfGoldenScreenshot = os.path.join(chrome_paths.GetTestData(),
'chromedriver/goldenScreenshots',
'redBoxScreenshot.png')
imageGoldenScreenshot = open(filenameOfGoldenScreenshot, 'rb').read()
self.assertEquals(imageGoldenScreenshot, dataActualScreenshot)
class ChromeDriverSiteIsolation(ChromeDriverBaseTestWithWebServer): class ChromeDriverSiteIsolation(ChromeDriverBaseTestWithWebServer):
"""Tests for ChromeDriver with the new Site Isolation Chrome feature. """Tests for ChromeDriver with the new Site Isolation Chrome feature.
......
<!DOCTYPE html>
<html>
<body>
<div id='box' style='width: 200px; height: 100px; background-color: red'></div>
</body>
</html>
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment