Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit c6d805b44b84aed5ae5665de30169d0ce4049524 1 parent 957b13d
Jonas Baumann jone authored

Showing 1 changed file with 22 additions and 19 deletions. Show diff stats Hide diff stats

  1. +22 19 ftw/testing/pages.py
41 ftw/testing/pages.py
@@ -165,6 +165,28 @@ def create_object(self, type_title, fields):
165 165 page.assert_portal_message('info', 'Changes saved.')
166 166 return page
167 167
  168 + def get_button(self, value, type_=None):
  169 + if type_ is not None:
  170 + xpr = '//input[@type="%s" and @value="%s"]' % (type_, value)
  171 +
  172 + else:
  173 + xpr = '//input[(@type="submit" or @type="button") and @value="%s"]' % \
  174 + value
  175 +
  176 + elements = browser().find_by_xpath(xpr)
  177 +
  178 + if len(elements) == 0:
  179 + return None
  180 +
  181 + assert len(elements) < 2, \
  182 + 'Ambiguous matches for button "%s".\nXpath: %s\n%s' % (
  183 + value, xpr, str(map(lambda item: item.outer_html, elements)))
  184 +
  185 + return elements.first
  186 +
  187 + def click_button(self, value, type_=None):
  188 + self.get_button(value, type_=type_).click()
  189 +
168 190
169 191 class FormPage(Plone):
170 192
@@ -188,25 +210,6 @@ def fill_field(self, label, value):
188 210 else:
189 211 browser().fill_form({fields.first['name']: value})
190 212
191   - def click_button(self, value, type_=None):
192   - if type_ is not None:
193   - xpr = '//input[@type="%s" and @value="%s"]' % (type_, value)
194   -
195   - else:
196   - xpr = '//input[(@type="submit" or @type="button") and @value="%s"]' % \
197   - value
198   -
199   - elements = browser().find_by_xpath(xpr)
200   -
201   - assert len(elements) != 0, \
202   - 'No button "%s" found.\nXPath: %s' % (value, xpr)
203   -
204   - assert len(elements) < 2, \
205   - 'Ambiguous matches for button "%s".\nXpath: %s\n%s' % (
206   - value, xpr, str(map(lambda item: item.outer_html, elements)))
207   -
208   - elements.first.click()
209   -
210 213
211 214 class ATFormPage(FormPage):
212 215

0 comments on commit c6d805b

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