Writing Your First Test Script

In this section we are going to write a very basic automated test script that simply loads the Google site, does a query and validates that the query was made by validating the new title of the page.

<jm:testcase xmlns:jm="jelly:jameleon">

  <jm:test-case-summary>Tests searching on the sourceforege site</jm:test-case-summary>
  <jm:test-case-author>Christian Hargraves</jm:test-case-author>
  <jm:test-case-level>ACCEPTANCE</jm:test-case-level>
  <jm:functional-point-tested>Jiffie Example</jm:functional-point-tested>

  <jm:ie-session baseUrl="http://sourceforge.net" beginSession="true">
    <jm:ie-validate
        functionId="Verify that we are on the sourceforge home page"
        title="SourceForge.net: Welcome to SourceForge.net"
        textPresent="Open Source Technology Group"/>
    <jm:ie-set-text-field
        functionId="Enter jameleon into the search box."
        name="words"
        value="jameleon"
        form="searchform"/>
    <jm:ie-click-button
        functionId="Click on the 'Google Search' button."
        form="searchform"
        value="Search"
        eventToFire="onclick"
        functionDelay="300"/>
    <jm:ie-validate
        functionId="Check that we actually did a search for 'Jameleon' and that we found 'Jameleon'"
        title="SourceForge.net: Software Search"
        linkPresent="Jameleon"/>
    <jm:ie-click-link
        functionId="Click on the 'Jameleon' link"
        link="Jameleon"/>
    <jm:ie-validate
        functionId="Validate that we arrived at the Jameleon SourceForge Page."
        title="SourceForge.net: Jameleon"
        linkPresent="engrean"/>
    <jm:ie-click-link
        functionId="Navigate to the Jameleon site by clicking on the 'Home Page' link"
        link="Home Page"/>
    <jm:ie-validate
        functionId="Validate that we arrived at the Jameleon SourceForge Page."
        title="Jameleon - An Automated Testing Tool - Overview"/>

  </jm:ie-session>
</jm:testcase>

Save the above file as jameleon-test-suite-x.x.x/scripts/jiffie-sourceforge.xml.

This section will begin explaining from the <ie-session/> tag since the other tags are discussed in the Jameleon Getting Started section.

If you start up the Jameleon GUI, select the "Functional Points" tab and navigate to the net->sf->jameleon->plugin->jiffie package, you will see the following tags:

By selecting the ie-session tag, we can see that baseUrl and beginSession are supported attributes. baseUrl tells the Jiffie plug-in where to open IE to and beginSession tells the Jiffie plug-in to start IE at the baseUrl or Sourceforge's home page.

Try clicking on the other tags used above to see what they do. Now select your new script by selecting the "Test Cases" tab and then selecting the new script. If it's not there, then try double-clicking on the "Test Cases" folder. Now select the jiffie-sourceforge.xml script and you should see the following:

I believe the generated docs explain what is happening in the script. I will discuss a few tricky points to this script.

  • By viewing the HTML source of the SourceForge home page we find several forms. The first form is the one that we want to use and find that it has a name attribute. While we could just say use the form '0', meaning the first form on the page, that makes the test more brittle as the location of the form could change, causing our script to fail. The name of the form is searchform. When using the provided tags, the form's name, id or index number can be given to indentify the form. In the ie-set-text-field tag, we used the form's name.
  • We use the submit button's value attribute to define which button in the form we want to click on.
  • Even though the Search button doesn't call JavaScript, I figured I just add an example of how to make the plug-in trigger the correct JavaScript event. Usually, JavaScript method calls return immediately, making the script go even though the action hasn't resulted in a response yet. Thus, usually, when calling JavaScript it's best to add a functionDelay to the tag calling the script. If you tell it wait for 300 milliseconds (maybe less), then by the time the next functional point gets called, it will be waiting for the server to respond with the new results.