There is no one or absolute way for building test automation. I use the following approach to choose the technology or tool I use to build my test automation framework:

  • Open source
  • Most popular in the community
  • Regular maintenance by community
  • Able to solve my problem
Below is an example of the approach or tools I use to write a regression test suite for a customised exporter script in my company.
The behaviour of the exporter script is as below:
  • Log into a web interface
  • Fill in details as SQL statement to be run into a web form
  • Kicking off the exporter script via web form
  • Exporter script will execute the SQL statement and generate the output as text file
  • The text file will be sent to a FTP account
Below is how I build the test automation suite:
  • SpecFlow

I use this BDD tool for user readability purpose to explain the flow of the test scenarios

  • Selenium web driver in .NET

This is used to do the web interface interactions such as log in, filling in SQL details, and kicking off the tests

  • WinSCP

To log into the FTP server

  • Batch script

To run WinSCP.exe in order to delete and download files from FTP server

  • C# code

Using the Process class to run the batch script. It is also used to verify and display the output.

  • NUnit

To verify output

Below is the example of going down into each level of 1 step in the scenario:
The SpecFlow scenario looks like this:
Scenario: Kicking off PageUp Exporter
    Given I delete the output file
When I log into Feature Manager
And I kick off an Exporter process with query “SELECT * from dbo.applicant where semail like ‘%test%’ and linstid = ‘543’”
Then I verify that the file is exported
And we verify that the file has “60” rows
And we verify that the file has “100” delimiters
And we verify that the email address contains “test”
And we verify that the file size is “19484”

The step definitions for the 1st step consists of C# code that calls the batch file:

 [Given(@”I delete the output file”)]
        public void GivenIDeleteTheOutputFile()
        {
            string fileName = @”c:PageUpOutexporterTest..txt”;
            File.Delete(fileName);
            Process p = new Process();
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.FileName = “C:\exporter_delete.bat”;
            p.Start();
        }

The batch file calls a text file which WinSCP needs:

@ECHO OFF
cd c:Program Files (x86)WinSCP
start WinSCP.exe /console /script=c:exporter_delete.txt
:END

The text file consists of more MS DOS commands to perform the operation on the FTP server:

# Automatically abort script on errors
option batch abort
# Disable overwrite confirmations that conflict with the previous
option confirm off
# Connect using a password
# open sftp://user:password@example.com -hostkey=”ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx”
# Connect
open sftp://tuneup:iScWxPjvi7Oal6m@securestorage.pageuppeople.com -hostkey=”ssh-dss 1024 9e:bd:6f:c8:f9:68:18:81:f0:50:ce:71:dd:d6:53:2e”
cd /
# Download file to the local directory d:
rm *.txt
# Disconnect
close
# Exit WinSCP
exit