Tutorial

Writing tests

In order to create a new test, you need to create a new actiWATE test class or add a new test method to an existing actiWATE test class. The following instructions demonstrate how to develop actiWATE test. The sample test creates a new user using the form at http://www.actiwate.com/samples/livetestcase and verifies that the user is successfully created.

  1. Import required actiWATE classes and packages. In our case a single ActiwateTestCase class would suffice. Create a test class with a test method.
    import com.actimind.actiwate.testing.ActiwateTestCase;
    
    public class CreateUserTestCase extends ActiwateTestCase
    {
        public void testCreateUser()
        {
            ...
        }
    }
    
  2. Write the code that opens initial HTML page. Tests can use relative URLs. Base URL is specified in configuration file (see Configuration file).
    goTo("livetestcase");
  3. Write the code that fills out the form fields.
    setText(textField("username"), "jsmith");
    setText(passwordField("password1"), "123456");
    setText(passwordField("password2"), "123456");
    setText(textField("firstname"), "John");
    setText(textField("lastname"), "Smith");
    
    selectOption(singleSelect("month").optionByText("May"));
    selectOption(singleSelect("day").optionByText("28"));
    selectOption(singleSelect("year").optionByText("1977"));
    
    click(radioButton("gender", 0));
    
  4. Write the code that submits the form. Before the form submission the page shows confirmation dialog. Therefore prior to clicking the button test have to call the expectConfirm() method.
    expectConfirm("Do you want to create user 'jsmith' ?", PRESS_OK);
    click(buttonByText("Create User"));
    
  5. Write the code that verifies whether the user is successfully created.
    assertTitleEquals("actiWATE - Sample Form - Success");
    assertTextPresent("User has been successfully created");