Skip to content

Commit

Permalink
Renamed get-scrreenshot_by_filename to screenshot and added tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Og B. Maciel committed Oct 7, 2013
1 parent d2dacbd commit 9913fbb
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 13 deletions.
12 changes: 6 additions & 6 deletions splinter/driver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,6 @@ def get_iframe(self, name):
"""
raise NotImplementedError("%s doesn't support frames." % self.driver_name)

def get_screenshot_as_file(self, name=None, suffix=None):
"""
Takes a screenshot of the current page and saves it locally.
"""
raise NotImplementedError("%s doesn't support taking screenshots." % self.driver_name)

def execute_script(self, script):
"""
Executes a given JavaScript in the browser.
Expand Down Expand Up @@ -426,6 +420,12 @@ def is_element_not_present_by_id(self, id, wait_time=None):
"""
raise NotImplementedError("%s doesn't support verifying if element is not present by id" % self.driver_name)

def screenshot(self, name=None, suffix=None):
"""
Takes a screenshot of the current page and saves it locally.
"""
raise NotImplementedError("%s doesn't support taking screenshots." % self.driver_name)

@property
def cookies(self):
"""
Expand Down
15 changes: 9 additions & 6 deletions splinter/driver/webdriver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,6 @@ def is_element_not_present_by_id(self, id, wait_time=None):
def get_alert(self):
return AlertElement(self.driver.switch_to_alert())

def get_screenshot_as_file(self, name=None, suffix='.png'):
(fd, filename) = tempfile.mkstemp(prefix=name, suffix=suffix)

self.driver.get_screenshot_as_file(filename)
return filename

def is_text_present(self, text, wait_time=None):
wait_time = wait_time or self.wait_time
end_time = time.time() + wait_time
Expand Down Expand Up @@ -265,6 +259,15 @@ def check(self, name):
def uncheck(self, name):
self.find_by_name(name).first.uncheck()

def screenshot(self, name=None, suffix='.png'):

name = name or ''

(fd, filename) = tempfile.mkstemp(prefix=name, suffix=suffix)

self.driver.get_screenshot_as_file(filename)
return filename

def select(self, name, value):
self.find_by_xpath('//select[@name="%s"]/option[@value="%s"]' % (name, value)).first._element.click()

Expand Down
3 changes: 2 additions & 1 deletion tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from is_text_present import IsTextPresentTest
from mouse_interaction import MouseInteractionTest
from status_code import StatusCodeTest
from screenshot import ScreenshotTest
from type import SlowlyTypeTest
from popups import PopupWindowsTest

Expand Down Expand Up @@ -86,7 +87,7 @@ def test_should_receive_browser_on_parent(self):
self.assertEqual(self.browser, element.parent)


class WebDriverTests(BaseBrowserTests, IFrameElementsTest, ElementDoestNotExistTest, IsElementPresentTest, AsyncFinderTests, StatusCodeTest, MouseInteractionTest, PopupWindowsTest):
class WebDriverTests(BaseBrowserTests, IFrameElementsTest, ElementDoestNotExistTest, IsElementPresentTest, AsyncFinderTests, StatusCodeTest, MouseInteractionTest, PopupWindowsTest, ScreenshotTest):

def test_can_execute_javascript(self):
"should be able to execute javascript"
Expand Down
22 changes: 22 additions & 0 deletions tests/screenshot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-

# Copyright 2013 splinter authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

class ScreenshotTest(object):

def test_take_screenshot(self):
"should take a screenshot of the current page"
filename = self.browser.screenshot()
self.assertTrue('tmp' in filename)

def test_take_screenshot_with_prefix(self):
"should add the prefix to the screenshot file name"
filename = self.browser.screenshot(name='foobar')
self.assertTrue('foobar' in filename)

def test_take_screenshot_with_suffix(self):
"should add the suffix to the screenshot file name"
filename = self.browser.screenshot(suffix='jpeg')
self.assertEqual('jpg', filename[-3:])

0 comments on commit 9913fbb

Please sign in to comment.