What is Test Script? How to write (Example)

What is a Test Script in Software Testing?

Test Scripts are a line-by-line description containing the information about the system transactions that should be performed to validate the application or system under test. Test script should list out each step that should be taken with the expected results.

This automation script helps software tester to test each level on a wide range of devices systematically. The test script must contain the actual entries to be executed, and the expected results.

How to Write a Test Script

Test script
Test script

There are three different ways to create a test script:

Record/playback:

In this method, the tester needs to write any code instead of just to record the user’s actions. However, the tester will need to do coding to fix things that go wrong or fine-tune the automation behavior.

This method is easier than writing a complete test script from scratch because you already have the complete code. It is mostly used in a simplified programming language such as VBScript.

Keyword/data-driven scripting:

In this method, there is a clear separation between testers and developers. In data-driven scripting, the tester defines the test using keywords without knowledge of the underlying code.

Here, the developers’ job is to implement the test script code for the keywords and update this code when needed. So in this method, the tester need not worry about the system. However, they will highly rely upon development resources for any new functionality you want to test automatically.

Writing Code Using the Programming Language:

If you like to create test script using this method, you will typically still have the ability to record or playback and generate a simple script.

Although, as a tester, you finally need to go beyond record/playback and learn how to code simple scripts. It is important to understand that you can choose your Programming Language even if your application is written in Java.

However, it does not mean that you need to write your test scripts in Java, which can be difficult to learn. Instead, you can write your test scripts in an easier language like JavaScript or Ruby (or any easier language you wish to use).

Example of a Test Script

For example, to check the login function on a website, your test script might do the following:

  • Specify how the automation tool can locate the “Username” and “Password” fields in the login screen. Let us say, by their CSS element IDs.
  • Load the website homepage, then click on the “login” link. Verify that the Login screen that appears and the “Username” and “Password” fields are visible.
  • Next, type the username “Charles” and password “123456” identify the “Confirm” button and click it.
  • They need to specify how a user can locate the title of the Welcome screen that appears after login- say, by its CSS element ID.
  • Verify that the title of the Welcome screen is visible.
  • Read the title of the welcome screen.
  • Insert that the title text is “Welcome Charles”.
  • If the title text is as per the expectation, a record that the test passed. Otherwise, an album that the test failed.

Tips for creating a Test Script

Here are some important tips for creating a test script:

Clear:

Your test script should be clear. If the tester need to constantly ask the project in-charge person to give details about the application. This certainly wastes time and resources.

To avoid this , you need to constantly verify that each step in the test script is clear, concise, and coherent. This helps to keep the testing process smooth.

Simple:

You should create a test script that should contain just one specific action for testers to take. This makes sure that each function is tested correctly and that testers do not miss steps in the software testing process.

Well-thought-out:

To write the test script, you need to put yourself in the user’s place to decide which paths to test. You should be creative enough to predict all the different paths that users would use while running a system or application.

When to use the Test Script Approach?

Here are the reasons for using the Test Script.

  • Using a test script is the most reliable approach to verify that nothing is skipped and that the results are true as the desire testing plan.
  • If the test script is prepared, It leaves a lot less room for error during the testing process.
  • Sometimes, testers are allowed to browse through the product freely. They can miss certain features.
  • Sometime tester also assumes that a function has the expected result when it does not.
  • It is particularly useful when the user performance is important and specific.

What is a Test Script Template?

Test Script Template is a reusable formatted document that contains pre-selected information important for creating a usable test script. This document determines how detailed your tests are and what information should be included in each test case.

Difference Between Test Case And Test Script

Here are the main difference between Test Cast and Test Script:

Test Case Test Script
Test case is a step by step procedure that is used to test an application. The test script is a set of instructions to test an application automatically.
Test Cases are used for manual testing environment. Test Script is used in the automation testing environment.
It is done manually. It is done according to the scripting format.
The test case template includes Test ID, test data, test procedure, actual and expected results, etc. In the Test Script, we can use different commands to develop a script.

Summary

  • Test Scripts means a line-by-line description containing the information about the system transactions that should be performed to validate the application or system under test.
  • Test case is a step by step procedure that is used to test an application whereas the test script is a set of instructions to test an application automatically.
  • Three ways to create test script are 1) Record/playback 2) Keyword/data-driven scripting, 3) Writing Code Using the Programming Language.
  • Your test script should be clear and you should create a test script that should contain just one specific action for testers to take.
  • Using a test script is the most reliable approach to verify that nothing is skipped and that the results are true as the desire testing plan.
  • Test Script Template is a reusable formatted document that contains pre-selected information important for creating a usable test script.