Skip to content
Browse files

Move click_button to plone page object, also provide a get_button.

  • Loading branch information...
1 parent 957b13d commit c6d805b44b84aed5ae5665de30169d0ce4049524 @jone jone committed Mar 21, 2013
Showing with 22 additions and 19 deletions.
  1. +22 −19 ftw/testing/pages.py
View
41 ftw/testing/pages.py
@@ -165,6 +165,28 @@ def create_object(self, type_title, fields):
page.assert_portal_message('info', 'Changes saved.')
return page
+ def get_button(self, value, type_=None):
+ if type_ is not None:
+ xpr = '//input[@type="%s" and @value="%s"]' % (type_, value)
+
+ else:
+ xpr = '//input[(@type="submit" or @type="button") and @value="%s"]' % \
+ value
+
+ elements = browser().find_by_xpath(xpr)
+
+ if len(elements) == 0:
+ return None
+
+ assert len(elements) < 2, \
+ 'Ambiguous matches for button "%s".\nXpath: %s\n%s' % (
+ value, xpr, str(map(lambda item: item.outer_html, elements)))
+
+ return elements.first
+
+ def click_button(self, value, type_=None):
+ self.get_button(value, type_=type_).click()
+
class FormPage(Plone):
@@ -188,25 +210,6 @@ def fill_field(self, label, value):
else:
browser().fill_form({fields.first['name']: value})
- def click_button(self, value, type_=None):
- if type_ is not None:
- xpr = '//input[@type="%s" and @value="%s"]' % (type_, value)
-
- else:
- xpr = '//input[(@type="submit" or @type="button") and @value="%s"]' % \
- value
-
- elements = browser().find_by_xpath(xpr)
-
- assert len(elements) != 0, \
- 'No button "%s" found.\nXPath: %s' % (value, xpr)
-
- assert len(elements) < 2, \
- 'Ambiguous matches for button "%s".\nXpath: %s\n%s' % (
- value, xpr, str(map(lambda item: item.outer_html, elements)))
-
- elements.first.click()
-
class ATFormPage(FormPage):

0 comments on commit c6d805b

Please sign in to comment.
Something went wrong with that request. Please try again.