Permalink
Browse files

Fixes #49, agora dando deprecated warning nos metods que tao deprecated

  • Loading branch information...
1 parent d130b2c commit 1035d90a0ce841d9afb95e992f75b90df90f92b3 @fabiomcosta fabiomcosta committed Apr 10, 2011
@@ -26,8 +26,10 @@ def execute_script(self, script):
def evaluate_script(self, script):
raise NotImplementedError
- def find_by_css_selector(self, css_selector):
+ def find_by_css(self, css_selector):
raise NotImplementedError
+
+ find_by_css_selector = find_by_css
def find_by_xpath(self, xpath):
raise NotImplementedError
@@ -50,10 +52,10 @@ def find_link_by_text(self, text):
def wait_for_element(self, selector, timeout, interval):
raise NotImplementedError
- def fill_in(self, name, value):
+ def fill(self, name, value):
raise NotImplementedError
- fill = fill_in
+ fill_in = fill
attach_file = fill
def choose(self, name):
@@ -12,6 +12,8 @@
from splinter.driver import DriverAPI, ElementAPI
from splinter.element_list import ElementList
+from splinter.utils import warn_deprecated
+
class BaseWebDriver(DriverAPI):
old_popen = subprocess.Popen
@@ -99,14 +101,14 @@ def is_element_not_present(self, finder, selector):
return False
def is_element_present_by_css(self, css_selector, wait_time=None):
- return self.is_element_present(self.find_by_css_selector, css_selector, wait_time)
+ return self.is_element_present(self.find_by_css, css_selector, wait_time)
- is_element_present_by_css_selector = is_element_present_by_css
+ is_element_present_by_css_selector = warn_deprecated(is_element_present_by_css, 'is_element_present_by_css_selector')
@hltbra

hltbra Aug 22, 2011

Owner

I am thinking about a new way to deprecate methods.

What you think of:

@warn_deprecated(now_use='is_element_present_by_css')
def is_text_present_by_css_selector(*args, **kw):
    return is_element_present_by_css(*args, **kw)

or

@warn_deprecated(now_use=is_element_present_by_css)
def is_text_present_by_css_selector(*args, **kw):
    pass

It just popped in my mind as I read the code. If you want to ignore it, no problem.

see ya

@fsouza

fsouza Aug 22, 2011

Contributor

That's clever, but it was deprecated 4 months ago, isn't it time to drop it? :)

@fsouza

fsouza Aug 22, 2011

Contributor

Ops, "... isn't time to drop these methods?"

@heynemann

heynemann via email Aug 22, 2011

Owner
@hltbra

hltbra Aug 22, 2011

Owner

Oops, now I took a look at commit date. Well, it is up to you. How many releases it is behind? I recommend dropping, anyway.

def is_element_not_present_by_css(self, css_selector):
- return self.is_element_not_present(self.find_by_css_selector, css_selector)
+ return self.is_element_not_present(self.find_by_css, css_selector)
- is_element_not_present_by_css_selector = is_element_not_present_by_css
+ is_element_not_present_by_css_selector = warn_deprecated(is_element_not_present_by_css, 'is_element_not_present_by_css_selector')
def is_element_present_by_xpath(self, xpath, wait_time=None):
return self.is_element_present(self.find_by_xpath, xpath, wait_time)
@@ -175,7 +177,7 @@ def find_by_css(self, css_selector):
selector = CSSSelector(css_selector)
return self.find_by(self.driver.find_elements_by_xpath, selector.path)
- find_by_css_selector = find_by_css
+ find_by_css_selector = warn_deprecated(find_by_css, 'find_by_css_selector')
def find_by_xpath(self, xpath):
return self.find_by(self.driver.find_elements_by_xpath, xpath)
@@ -193,7 +195,7 @@ def fill(self, name, value):
field = self.find_by_name(name).first
field.value = value
- fill_in = fill
+ fill_in = warn_deprecated(fill, 'fill_in')
attach_file = fill
def choose(self, name):
@@ -1,9 +1,12 @@
-from splinter.driver import DriverAPI, ElementAPI
+import mimetypes
+
+import lxml.html
+from lxml.cssselect import CSSSelector
from zope.testbrowser.browser import Browser
+
from splinter.element_list import ElementList
-from lxml.cssselect import CSSSelector
-import lxml.html
-import mimetypes
+from splinter.driver import DriverAPI, ElementAPI
+from splinter.utils import warn_deprecated
class ZopeTestBrowser(DriverAPI):
@@ -48,7 +51,7 @@ def find_by_css(self, selector):
xpath = CSSSelector(selector).path
return self.find_by_xpath(xpath)
- find_by_css_selector = find_by_css
+ find_by_css_selector = warn_deprecated(find_by_css, 'find_by_css_selector')
def find_by_xpath(self, xpath):
html = lxml.html.fromstring(self.html)
@@ -93,7 +96,7 @@ def find_link_by_href(self, href):
def fill(self, name, value):
self.find_by_name(name=name).first._control.value = value
- fill_in = fill
+ fill_in = warn_deprecated(fill, 'fill_in')
def choose(self, name):
control = self._browser.getControl(name=name)
View
@@ -1,28 +1,28 @@
class AsyncFinderTests(object):
- def test_find_by_css_selector_should_found_an_async_element(self):
- "should find element by css selector found an async element"
- self.browser.find_by_css_selector('.add-async-element').first.click()
- assert 1 == len(self.browser.find_by_css_selector('.async-element'))
+ def test_find_by_css_should_found_an_async_element(self):
+ "should find element by css found an async element"
+ self.browser.find_by_css('.add-async-element').first.click()
+ assert 1 == len(self.browser.find_by_css('.async-element'))
def test_find_by_xpath_should_found_an_async_element(self):
"should find by xpath found an async element"
- self.browser.find_by_css_selector('.add-async-element').first.click()
+ self.browser.find_by_css('.add-async-element').first.click()
assert 1 == len(self.browser.find_by_xpath('//h4'))
def test_find_by_tag_should_found_an_async_element(self):
"should find by tag found an async element"
- self.browser.find_by_css_selector('.add-async-element').first.click()
+ self.browser.find_by_css('.add-async-element').first.click()
assert 1 == len(self.browser.find_by_tag('h4'))
def test_find_by_id_should_found_an_async_element(self):
"should find by id found an async element"
- self.browser.find_by_css_selector('.add-async-element').first.click()
+ self.browser.find_by_css('.add-async-element').first.click()
assert 1 == len(self.browser.find_by_id('async-header'))
def test_find_by_name_should_found_an_async_element(self):
"should find by name found an async element"
- self.browser.find_by_css_selector('.add-async-element').first.click()
+ self.browser.find_by_css('.add-async-element').first.click()
assert 1 == len(self.browser.find_by_name('async-input'))
View
@@ -7,12 +7,12 @@ def test_click_links(self):
def test_click_element_by_css_selector(self):
"should allow to click at elements by css selector"
- self.browser.find_by_css_selector('a[href="/foo"]').first.click()
+ self.browser.find_by_css('a[href="/foo"]').first.click()
assert 'BAR!' in self.browser.html
def test_click_input_by_css_selector(self):
"should allow to click at inputs by css selector"
- self.browser.find_by_css_selector('input[name="send"]').first.click()
+ self.browser.find_by_css('input[name="send"]').first.click()
assert 'My name is: Master Splinter' in self.browser.html
def test_click_link_by_href(self):
@@ -5,14 +5,14 @@ class ElementDoestNotExistTest(object):
@raises(ElementDoesNotExist)
def test_element_query_should_raises_when_element_first_doest_exists(self):
- self.browser.find_by_css_selector('.element-that-dont-exists').first
+ self.browser.find_by_css('.element-that-dont-exists').first
@raises(ElementDoesNotExist)
def test_element_list_raises_when_element_last_does_not_exists(self):
- self.browser.find_by_css_selector('.element-that-dont-exists').last
+ self.browser.find_by_css('.element-that-dont-exists').last
@raises(ElementDoesNotExist)
def test_element_list_raises_when_element_does_not_exists(self):
- self.browser.find_by_css_selector('.element-that-dont-exists')[2]
+ self.browser.find_by_css('.element-that-dont-exists')[2]
View
@@ -1,3 +1,5 @@
+import warnings
+
from nose.tools import assert_equals
class FindElementsTest(object):
@@ -7,9 +9,18 @@ def test_finding_by_css(self):
value = self.browser.find_by_css('h1').first.value
assert_equals(value, 'Example Header')
- def test_existence_of_find_by_css_selector_alias(self):
- "should check the existence of finds_by_css_selector alias"
- assert_equals(self.browser.find_by_css, self.browser.find_by_css_selector)
+ def test_existence_of_find_by_css_selector_alias_and_that_its_deprecated(self):
+ "should check the existence of find_by_css_selector alias for backwards compatibility"
+ found = self.browser.find_by_css('h1').first.value
+ with warnings.catch_warnings(record=True) as w:
+ warnings.simplefilter("always")
+ found_deprecated = self.browser.find_by_css_selector('h1').first.value
+ warn = w[-1]
+ warn_message = str(warn.message)
+ assert issubclass(warn.category, DeprecationWarning)
+ assert "find_by_css" in warn_message
+ assert "find_by_css_selector" in warn_message
+ assert_equals(found, found_deprecated)
def test_finding_by_xpath(self):
"should find elements by xpath"
View
@@ -1,3 +1,5 @@
+import warnings
+
from nose.tools import assert_equals, assert_true, assert_false
class FormElementsTest(object):
@@ -8,6 +10,19 @@ def test_can_change_field_value(self):
value = self.browser.find_by_name('query').first.value
assert_equals(value, 'new query')
+ def test_existence_of_the_fill_in_alias_and_that_its_deprecated(self):
+ "should check the existence of the fill_in alias for backwards compatibility"
+ with warnings.catch_warnings(record=True) as w:
+ warnings.simplefilter("always")
+ self.browser.fill_in('query', 'new query')
+ warn = w[-1]
+ warn_message = str(warn.message)
+ assert issubclass(warn.category, DeprecationWarning)
+ assert "fill" in warn_message
+ assert "fill_in" in warn_message
+ value = self.browser.find_by_name('query').first.value
+ assert_equals(value, 'new query')
+
def test_submiting_a_form_and_verifying_page_content(self):
"should be able search a term in google and verifying if content expected exists"
self.browser.fill('query', 'my name')
@@ -1,3 +1,5 @@
+import warnings
+
from nose.tools import assert_true, assert_false, assert_equals
class IsElementPresentTest(object):
@@ -27,13 +29,31 @@ def test_is_element_not_present_by_css_returns_false_if_element_is_present(self)
"should is element not present by css selector returns False if element is present"
assert_false(self.browser.is_element_not_present_by_css('h1'))
- def test_existence_of_is_element_present_by_css_selector_alias(self):
- "should check ths existance of the is_element_present_by_css_selector alias for backwards compatibility"
- assert_equals(self.browser.is_element_present_by_css_selector, self.browser.is_element_present_by_css)
-
- def test_existence_of_is_element_not_present_by_css_selector_alias(self):
- "should check ths existance of the is_element_not_present_by_css_selector alias for backwards compatibility"
- assert_equals(self.browser.is_element_not_present_by_css_selector, self.browser.is_element_not_present_by_css)
+ def test_existence_of_is_element_present_by_css_selector_alias_and_that_its_deprecated(self):
+ "should check the existence of the is_element_present_by_css_selector alias for backwards compatibility"
+ is_present = self.browser.is_element_present_by_css('h1')
+ with warnings.catch_warnings(record=True) as w:
+ warnings.simplefilter("always")
+ is_present_deprecated = self.browser.is_element_present_by_css_selector('h1')
+ warn = w[-1]
+ warn_message = str(warn.message)
+ assert issubclass(warn.category, DeprecationWarning)
+ assert "is_element_present_by_css" in warn_message
+ assert "is_element_present_by_css_selector" in warn_message
+ assert_equals(is_present, is_present_deprecated)
+
+ def test_existence_of_is_element_not_present_by_css_selector_alias_and_that_its_deprecated(self):
+ "should check the existence of the is_element_not_present_by_css_selector alias for backwards compatibility"
+ is_not_present = self.browser.is_element_not_present_by_css('h1')
+ with warnings.catch_warnings(record=True) as w:
+ warnings.simplefilter("always")
+ is_not_present_deprecated = self.browser.is_element_not_present_by_css_selector('h1')
+ warn = w[-1]
+ warn_message = str(warn.message)
+ assert issubclass(warn.category, DeprecationWarning)
+ assert "is_element_not_present_by_css" in warn_message
+ assert "is_element_not_present_by_css_selector" in warn_message
+ assert_equals(is_not_present, is_not_present_deprecated)
def test_is_element_present_by_xpath(self):
"should is element present by xpath verify if element is present"
@@ -19,5 +19,5 @@ def tearDownClass(cls):
@raises(NotImplementedError)
def test_attach_file_is_not_implemented(self):
- "attach file is no implemented for chrome driver"
- self.browser.attach_file('file', 'file_paht')
+ "attach file is not implemented for chrome driver"
+ self.browser.attach_file('file', 'file_path')

0 comments on commit 1035d90

Please sign in to comment.