TestPlan form search.test example
Document

form search.test example

by Group Public on Friday September 18 2009 @ 11:18:58 (1/1 Points)

Tutorial ↪User Guide ✑ Reply ✓ Stick It ✗ Ditch It ⚐ Tag It

This is a fairly simply example which simply submits a search at this site. It covers the very basic functions of TestPlan and is thus a good introduction to the test language.

Execution

Execute the test with:

testplan samples.form_search

Explanation

This code can be located in the testplan_home/tests/samples/form_search.test.

# Go to the documentation website
GotoURL http://testplan.brainbrain.net/

# Search for the Getting Started Guide
SubmitForm with
  # we wish only to set this one value in the form
  %Params:search% Getting Started 

  # This form has no button to press, so we must press enter instead
  %Submit% key:enter
end

# Now, if nobody has modified the page there should be a "Download" header in it somewhere
Check //h1[contains(text(),'Download')]

# And let's just output the title of the page
Notice Page Title: %Response://title%

# And all the related note links (doing it a different way)
set %Related% as response //div[@class='related']//a
foreach %Link% in %Related%
  # outputting an xpath result simply converts it to a string like the xpath string() function
  Notice Related Title: %Link%
  
  # we can also inspect this result further, for example to get the URL of it
  set %URL% as selectIn %Link% @href
  Notice URL: %URL%
end

GotoURL

GotoURL http://testplan.brainbrain.net/

The GotoURL is the first step and takes use to the target web page. What actually happens is that a browser is created internally in TestPlan and that browser will be given the provided URL. The internal state of TestPlan is now at this web site.

SubmitForm

SubmitForm with
  %Params:search% Getting Started 
  %Submit% key:enter
end

SubmitForm is used, as you can image, to submit a form on the page. We don't need to say which form to use since this page has only one.

As we have only one parmater to submit a short-form has been used to specify that parameter. The name of the parameter is the one used as the form name, not the visual label. If we had multiple parameters an alternate syntax would make more sense, though the above can still be used.

%Params% with
    %search% GEtting Started
    %other% value
  end

Check

Check //h1[contains(text(),'Download')]

Check is one of the high-level testing functions. It takes an XPath as a parameter and simple checks whether such an element exists on the page. If no matching element can be found an error will be reported in the output report.

Notice

Notice Page Title: %Response://title%

Notice is a simple tracing functionality which takes it parameter, converts it to a string, and writes it to the console.

The %Response:...% shows a dynamic lookup functionality. The percentages mark context items (something like variables), and in this case they reference a dynamic item. This dynamic treats the second part of the item reference as an XPath and returns the evaluation of that XPath.

Note that the current state of the application will also be represented as XML, whether a web page, email, downloaded file, or otherwise. The format of these response can be seen in Response Formats

set and response

set %Related% as response //div[@class='related']//a

set is the general purpose assignment operation. This simply assigns a value, or evaluation of a function, to a particular context item.

The as response in this case indicates we wish to call the function response. We've already seen that we could get this same value via a context lookup though, so in fact this line is equivalent to:

set %Related% %Response://div[@class='related']//a%

Which form you use greatly depends on the situation, though the true functional form is preferred when possible. You will discover some cases where the item form simply can't express what you need.

foreach

foreach %Link% in %Related%

We recommend you indent the code in foreach loops, though technically it is not required.

The previous xpath we used actually returns a list of objects, not just a single value. To work with a collection of values the foreach function is used.

Here we are saying to that for each item in %Related% set the item %Link% to this value and execute the code up to the end statement.

selectIn

set %URL% as selectIn %Link% @href

You will not normally need the selectIn function. It is used in cases where you need to resolve an XPath against an already retrieved XPath result (that is, an xpath relative to a node).

© 2008-2010 edA-qa mort-ora-y
Using Persephone and TestPlan
Tag: