Chuan Chuan Law

DevOps | Software Automation | Continuous Integration

Tag: Automation

Automatically Runs Tests And Email Report From Your PC

I have set up my own PC as a build machine that runs regression tests automatically at night and then emails me the test result upon completion so that I can check it when I get in the morning.

The mechanism I use to do is:

  • Windows Task Sceduler to run the test automatically at certain time

 

  • Bat script to run the tests, generate Specflow report, and email the report. Note that I have included %date% and %time% variables to automatically include the date and time in the email subject

“C:Program Files (x86)NUnit 2.6.2binnunit-console.exe” /labels /out=TestResult.txt /xml=TestResult.xml C:gitPmasterbinDebugTestsRegressionRegression.dll
“C:Program Files (x86)TechTalkSpecFlowspecflow.exe” nunitexecutionreport C:gitPmasterTestsRegressionRegressionRegression.csproj /out:TestResult.html
“c:blat” c:gitPmasterTestsRegressionTestResult.html -s “TestResult at %time% on %date%” -to chuanl@pageuppeople.com

 

  • Blat

As you can see in the Bat script, I have used a 3rd party open source tool Blat to send email. This blog gives comprehensive information on how to set up Blat.

Database Migration Test Script

To assist the testing in database migration or database changes, I have built a script that does the following:

  1. Pass in the connection of the 2 databases that you want to compare
  2. For each database, list out all the tables in alphabetical order
  3. For each table, print out the number of columns and the number of rows
  4. Print out the tables that exist in Database A but not not Database B and vice versa
  5. For tables that exist in both databases, compare the number of columns, number of rows, and database schema (e.g.: varchar or nvarchar)
  6. If database schema is different, print out the schema in both databases

The Art of Test Automation

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

Open Source Mobile Test Automation Framework

The popular ones in the market are as below:

Frank

  • Developed by Thoughtworks
  • Can only be used on iOS applications
Robotium

 

  • Can only be used by Android applications
Sikuli
  • Easiest to use among all because no scripting is needed
  • It works based on screen capture
  • Need to have separate tests for iOS and Android applications because of the different UI
Selenium
  • Most flexible. Can be used on both iOS and Android applications
  • Hardest to set up among all

© 2019 Chuan Chuan Law

Theme by Anders NorenUp ↑