Common WebTest/Selenium API =========================== This page documents the methods and attributes that are provided by both :class:`django_functest.FuncWebTestMixin` and :class:`django_functest.FuncSeleniumMixin`. Conventions: unittest provides assertion methods that are ``camelCased``. Django follows suit with assertion methods, but for other things defaults to the PEP8 recommendation of ``name_with_underscores`` e.g. ``live_server_url``. We have followed the same pattern. .. currentmodule:: django_functest .. class:: FuncCommonApi **Assertion methods** .. method:: assertUrlsEqual(url, other_url=None) Checks that the URLs are equal, with ``other_url`` defaulting to the current URL if not passed. The path and query are checked, and if both URLs contain a domain name and/or protocol, these are also checked. This means that relative URLs can be used, or protocol-relative URLs. .. method:: assertTextPresent(text, within="body", wait=True) Asserts that the text is present in the body of the current page. You can pass ``within`` as some other CSS selector to narrow the assertion to within the matching element(s). For Selenium tests, it will also wait for the specified ``within`` element to appear, unless ``wait=False`` is passed. The ``wait`` parameter has no effect on WebTest. .. method:: assertTextAbsent(text, within="body") Asserts that the text is not present in the body of the current page. You can pass ``within`` as some other CSS selector to narrow the assertion to within the matching element(s). **Other methods and attributes** .. method:: back() Go back in the browser. For WebTest, this will not make additional requests. For Selenium tests, this may or may not make additional requests, depending on caching etc. and what happens when you press 'Back' in the browser being used. .. attribute:: current_url The current full URL .. method:: follow_link(css_selector=None, text=None) Follows the link specified in the CSS selector, or a link matching the specified link text. You will get an exception if no links match. For :class:`django_functest.FuncWebTestMixin`, you will get an exception if multiple links match and they don't have the same href. .. method:: fill(data_dict, scroll=NotPassed) Fills form inputs using the values in ``data_dict``. The keys are CSS selectors, and the values are the values for the inputs. Works for text inputs, radio boxes, check boxes, and select fields. Checkbox values can be specified using ``True`` and ``False``. Radio button values should be specified using the ``value`` attribute that should be matched, and the radio button that matches that will be selected (even if the selector matched another button in that group). To upload a file, pass an :class:`~django_functest.Upload` instance as the value. This will raise an exception if the fields can't be found. It will be a timeout exception for Selenium tests, so you will want to avoid attempting to fill in fields that don't exist. If multiple fields match, you will get an exception for :class:`~django_functest.FuncWebTestMixin` but not for :class:`~django_functest.FuncSeleniumMixin` due to the way Selenium finds elements. For Selenium, you can specify whether to scroll first (to bring the element into view), which defaults to the value of :attr:`~django_functest.FuncSeleniumMixin.auto_scroll_by_default`. This parameter has no effect for WebTest. .. method:: fill_by_id(data_dict) Same as :meth:`fill` except the keys are element IDs. **Deprecated** — instead of ``fill_by_id({'foo': 'bar'})`` you should do ``fill({'#foo': 'bar'})``, because it is shorter and more flexible. .. method:: fill_by_name(data_dict) Same as :meth:`fill` except the keys are input names. .. method:: fill_by_text(data_dict) Same as :meth:`fill`, except the values are text captions. This can be used only for ``