-
Notifications
You must be signed in to change notification settings - Fork 2
Writing Madcow Tests
The main principle behind Madcow is to easily specify an element in your web application and manipulate it and make assertions on it. To specify an element simply refer to its html ID on the page. For instance the html:
<input type="text" id="searchBox" value="" />
can be found and used in your test by:
searchBox.value = "Find me the cheapest phone"
This will find the element with id searchBox, which is an input element and then set its value to "Find me the cheapest phone".
But what if the element you are trying to test doesn't have an ID? Madcow has a simple mapping mechanism that map xpaths, names or even other IDs to nice IDs you can use in your tests.
So let's write our first test. We will do a simple google search.
By default Madcow will use the IDs in your html to find elements. But often these are ugly or non-existent. The google front page is a good example of this. So we will need to map the search box and search button to nice names to use them.
Madcow looks for files in your test/mappings directory named *.madcow.mappings.properties.
Create a new file call google.madcow.mappings.properties and add the following lines:
#Google Search
searchBox.name=q
searchButton.name=btnG
aptiveLink.href=http://www.aptive.com.au/
companyLink.xpath=//*[@id='companyLink']/a
The Google front page has an input box with no ID but has a name attribute of the value "q"
<input class="lst" value="" title="Google Search" size="55" name="q" maxlength="2048" autocomplete="off"/>
In our mappings file we mapped it to the label searchBox by writing:
searchBox.name=q
We do the same thing for the searchButton
To invoke your web app in your test simply run the invoke step
invokeUrl = http://google.com.au/
Now we want to do a search for the 4impact home page.
searchBox.value = 4impact
searchButton.clickButton
The .value command set the value of the input box to be 4impact. And the clickButton command clicked on the search button, which in this case, submitted the google search and displayed a new page with the search result.
Finally we want to click on the 4impact website. We know that the link of the 4impact site will be http://www.4impact.com.au/ so in our google.madcow.mappings.properties file we mapped the href to the fourimpactLink label.
fourimpactLink.href=http://www.4impact.com.au/
So let's click that link
fourimpactLink.clickLink
And that's it for your first test! Here is the full listing.
invokeUrl = http://google.com.au
searchBox.value = 4impact
searchButton.clickButton
fourimpactLink.clickLink
To write tests in groovy simple create your own package structure under the test/groovy directory and create a Groovy Class that extends MadcowTestCase. You can create tests by creating methods that start with "test" and have the void return type. Everything else is the same.
public class GoogleTest extends au.com.ts4impact.Madcow.engine.MadcowTestCase {
void testSearchPage() {
invokeUrl = "http://google.com.au"
searchBox.value = "4impact"
searchButton.clickButton
fourimpactLink.clickLink
}
}
The import command is not available in groovy code as it is a reserved word. To get the same effect you can simply call any other groovy method.
The simplest form of tests in Madcow is in a properties file. Simply create a test ending with MadcowTest.properties such as GoogleMadcowTest.properties in the test/properties directory and Madcow will automatically find and run it.
You can only have one test in a single properties file.
A powerful feature of Madcow is the ability to load other properties files in your tests to get greater reuse. To do this you use the import command.
import = LoginActions
searchClaimBox.value = 123323
searchButton.clickLink
policyNumber.checkValue = 3344
import = LogoutActions
The import command will look for properties files, in this case LoginActions.properties and LogoutActions.properties and insert the contents of these files into the script. See Templates for more information.
The most powerful way of writing tests in Madcow is in a CSV file or spreadsheet. This allows you to make your tests data driven by allowing you to have multiple tests with different data for the same structure.
Avoid any spaces and special characters in the test and sheet names.
Madcow allows the use of data parameters, to specify reusable pieces of test data throughout a test. This allows a test to be data driven rather than being bound to a specific set of data throughout the test. The data parameters are used through the @ notation. See Data Parameters for more information.
To add single line comment to a test simply prepend a # to the front of the line.
# this is a useful test
- Home
- Setting Up
- Configuration
- Writing Madcow Tests
- Running Madcow Tests
- Data Parameters
- Templates
- Macros
- Disabling A Test
- Spreadsheet Scenario Testing
Madcow Operations
- Madcow Operations
- Madcow Operations - Table
- Madcow Operations - XPath Extras
- List of Madcow Operations
Extending and Customising Madcow
Reference
For Developers