Development

LimeFunctionalTestingHints

You must first sign up to be able to contribute.

Version 8 (modified by jmorris14, 7 years ago)
--

Lime Functional Testing Hints

CSS Selectors

One of the more powerful methods of selecting page content for testing and one of the best reasons to use Lime. But some of the selectors can be a bit unfamiliar, partly because they're defined in CSS3.

Attribute Selectors

Also see the W3C CSS3 Attribute selectors page
and of course the CSS Selectors section of The Book

When used with this html fragment

line 1: <a href="/user/list" rel="copyright copyleft copyeditor" hreflang="en-US">All users</a>
line 2: <a href="/post/list" class="sf_admin_link" hreflang="en-GB" >All posts</a>

and

$browser->checkResponseElement($selector, true)

if $selector =

'a[href]'
any a element with an "href" attribute
returns true for line 1 and line 2:
line 1: <a href="/user/list" rel="copyright copyleft copyeditor" hreflang="en-US">All users</a>
line 2: <a href="/post/list" class="sf_admin_link" hreflang="en-GB">All posts</a>
'a[href="/post/list"]'
an a element whose "href" attribute value is exactly equal to "/post/list"
returns true for line 2 (see note in "Gotcha's" below):
line 2: <a href="/post/list" class="sf_admin_link" hreflang="en-GB">All posts</a>
'a[rel~="copyleft"]'
an a element whose "rel" attribute value is a list of space-separated values, one of which is exactly equal to "copyleft"
returns true for line 1:
line 1: <a href="/user/list" rel="copyright copyleft copyeditor" hreflang="en-US">All users</a>
'a[href^="/user"]'
an a element whose "href" attribute value begins exactly with the string "/user"
returns true for line 1 and line 2:
line 1: <a href="/user/list" rel="copyright copyleft copyeditor" hreflang="en-US">All users</a>
'a[href$="list"]'
an a element whose "href" attribute value ends exactly with the string "list"
returns true for line 1 and line 2
line 1: <a href="/user/list" rel="copyright copyleft copyeditor" hreflang="en-US">All users</a>
line 2: <a href="/post/list" class="sf_admin_link" hreflang="en-GB">All posts</a>
'a[class*="admin"]'
an a element whose "class" attribute value contains the substring "admin"
returns true for line 2:
line 2: <a href="/post/list" class="sf_admin_link">All posts</a>
'a[hreflang|="en"]'
an a element whose "hreflang" attribute has a hyphen-separated list of values beginning (from the left) with "en"
returns true for line 1 and line 2:
line 1: <a href="/user/list" rel="copyright copyleft copyeditor" hreflang="en-US">All users</a>
line 2: <a href="/post/list" class="sf_admin_link" hreflang="en-GB">All posts</a>

Gotcha's

  • In the above tests, 'a[href="/post/list"]' will actually never return true in Lime. Lime doesn't know about mod_rewrite or .htaccess, so it can't rewrite the URL to remove 'index.php'. So either that selector has to be written as 'a[href$="/post/list"]' or as 'a[href="index.php/post/list"]'.

Forwards, Redirects, and Secure Pages

Lime has 2 methods for testing that the page returned is not the page you asked for:

These are covered in the Browsing with the sfTestBrowser Object section of The Book.

If you're trying to test security on your pages, and you want to make sure that an unauthorized user can't access certain pages, you need to test using $browser->isForwardedTo() (NOT $browser->isRedirected()) and test that the correct module/action are displayed to the user.

By default, when a user needs to be logged in to see a page ("is_secure: on" in security.yml) the test code will be

$browser->isForwardedTo('default', 'login')

When a user doesn't have sufficient credentials, the test code will be

$browser->isForwardedTo('default', 'secure')

These correspond to the values set in your apps/settings.yml file, which again by default are:

#    login_module:           default   # To be called when a non-authenticated user
#    login_action:           login     # Tries to access a secure page
#
#    secure_module:          default   # To be called when a user doesn't have
#    secure_action:          secure    # The credentials required for an action

Your settings for these values may vary.

assignment writing assignment help assignment writing college application essays essay help