Create a Scenario

You now have a Twist project created. Notice that you have an empty scenario in this project. The next step is to describe this scenario.

A Twist Scenario allows a user to express acceptance criteria using the language of the domain. A scenario expresses test intent, while its implementation describes how the scenario is actually executed. The underlying implementation is written in Groovy or Java code. Twist's Scenario Editor allows you to navigate from a scenario to its underlying implementation and back.

  1. Let us type in a simple description for the scenario. Now let us insert a Business Workflow to describe the test intent. Hit Ctrl+Space on a new line, and select Insert a Business Workflow as shown below.

    describe scenario1
  2. Now rename the inserted Workflow to 'At Wikipedia'. Type in a couple of workflow steps as shown below. You will now have two unimplemented workflow steps.

    describe scenario2
  3. Let us now implement this workflow. Hit Ctrl+1 on the workflow name 'At Wikipedia' to create the underlying code.

    describe scenario3
  4. On selecting the create workflow fixture option, a fixture creation dialog appears. We can then set the source and package information as shown.

    class creation dialog
  5. Similarly, you can hit Ctrl+1 on each workflow step to create or record them.

  6. In the workflow fixture created, copy and paste the code snippet given below. This code implements the two workflow steps.

      public void searchFor(String searchString) throws Exception {
        browser.navigateTo("http://www.en.wikipedia.org");
        browser.textbox("search").setValue(searchString);
        browser.submit("searchButton").click();
      }
    
      public void verifyEntryPageForAppears(String link) throws Exception {
        assertTrue(browser.link(link).exists());
      }
    
  7. Include this import statement above your class.
    import static junit.framework.Assert.*;
    
    Your class should look like the following
    // JUnit Assert framework can be used for verification
    
    import net.sf.sahi.client.Browser;
    import static junit.framework.Assert.*;
    
    // JUnit Assert framework can be used for verification
    
    public class AtWikipedia {
    
      private Browser browser;
    
      public AtWikipedia(Browser browser) {
        this.browser = browser;
      }
      
      public void searchFor(String searchString) throws Exception {
        browser.navigateTo("http://www.en.wikipedia.org");
        browser.textbox("search").setValue(searchString);
        browser.submit("searchButton").click();
      }
    
      public void verifyEntryPageForAppears(String link) throws Exception {
        assertTrue(browser.link(link).exists());
      }
    }
    
    Save the scenario. You now have a fully functional simple scenario created successfully.

Let us now see how to Execute the Scenario