Skip to content
Related Articles
Open in App
Not now

Related Articles

Software Testing – Test Script

Improve Article
Save Article
  • Last Updated : 27 Mar, 2022
Improve Article
Save Article

Active software projects are constantly changing – pages are being redesigned, user information is changing, and new functionality is being added. For it to work overtime, testers must make a constant effort to update the documents to match the new product. This can take a long time to test. Another challenge is that written tests are often designed to test the same thing over and over again, using the same steps and the same data each time testing. This means that if there are any bugs lying outside the guides provided in the test script, they will not be found unless the tester strays from the script. Written tests do not always encourage testers to use the intelligence and technical skills needed to detect hidden bugs. Here, we will discuss the following points:

  1. What is a Test Script?
  2. Writing a Test Script.
  3. How Efficient Should a Test Script Be?
  4. Information in Test Script.
  5. When to Use Test Script.

Let’s discuss each of these topics in detail.

What is a Test Script?

Test Scripts are a line-by-line description that contains information about system functions that must be performed to verify an application or system under test. The test document should outline each step to be taken with the expected results. This automated script enables the software explorer to scan each level of a wide range of devices systematically. The test script should contain the entries to be included, as well as the expected results. The automated Scripts can be written using any programming language (C/C++/Python/Perl/ Batch Scripts).

Writing a Test Script

The following are some of the approaches used by the tester to write test scripts:

  1. Record/ play: In this way, the tester needs to write any code instead of recording user actions. However, the inspector will need to generate code to fix the faults or correct the default behavior. This method is easier than writing a complete test script from scratch because you already have the full code. It is widely used in simplified editing language such as VBScript.
  2. Keyword/ data-driven text: In this approach, there is a clear distinction between testers and developers. In the data-driven text, the tester describes the test using keywords without the knowledge of the source code. Here, the job of the developer is to apply the keyword check code and update this code where necessary. So in this method, the tester does not have to worry about the system. However, they will rely heavily on development tools for any new functionality you want to check automatically.
  3. Using Programming: If you like to create test text using this method, you will usually still be able to record or play again and produce a simple script. Although, as a reviewer, you eventually need to skip the record/play and learn how to write simple codes. It is important to understand that you can choose your programming language even if your application is written in Java. However, this does not mean that you need to write your test scripts in Java, which can be difficult to read. Instead, you can write your test texts in simple languages like Python, or even we can write a batch file.

Below is a sample Batch File to run web browsing:

set / a count = 0
: in
am start – a android.intent.action.VIEW – d http: //
set / a count += 1
timeout / t 15

@goto in

How Efficient Should a Test Script Be?

Here are some important tips for creating a test script:

  1. The test script should be clear and should cover the scenario. If the tester always needs to ask the project manager to provide details about the application. This certainly wastes time and resources. To avoid this, you always need to make sure that each step in the test script is clear, concise, and consistent. This helps to keep the testing process smooth.
  2. Create a test script that must contain just one specific action that the testers will take. This ensures that each job is properly evaluated and that testers do not miss steps in the software testing process.
  3. To write a test text, one needs to place it in the user interface to determine which methods to test. Predict all the different methods users can use while using the system or application.

Although different test engineers will have different preferences regarding style, structure, and content of the text, compliance with the guidelines set by automated testing experts can be considered as a guide. Test documents should have the following properties:

  1. Clear Definitions: Directing both the user and the person keeping them.
  2. Active: Performs a single function and promotes reuse.
  3. Well-Designed: For ease of reading, comprehension, and maintenance.
  4. Easy understandable: It should be easily understandable for ease of maintenance.
  5. Clearly Written: It should be clearly written to facilitate use and storage.

Information in Test Script

A good script is always backed up with really useful information. The purpose of the script is what the text does or the actions we do. Potential information includes the following:

  1. The raw content of the script i.e. inputs and sometimes expected results.
  2. User information i.e. what information should be transferred to the script, what information should be restored, what state of the software being tested should be in when the script is called, and in what condition the software will remain at the end of the text.
  3. Usage information i.e. additional information that is useful to caregivers, such as an explanation of why it is used in a particular way or references to similar texts that may need to be changed.
  4. Annotation i.e. comments embedded in the entire script to indicate what happens in each logical step in terms of actions performed with the software being tested.

When to Use Test Script

  1. Using the test script is the most reliable way to ensure that there are no omissions and that the results are as accurate as of the wish test program.
  2. If the test script is fixed, It leaves a very small error space during the testing process.
  3. In some cases, inspectors are allowed to browse the product freely. They can miss some features.
  4. The periodic inspector also assumes that the work has the expected effect if you do not.
  5. It is especially useful when user functionality is important and clear.

Test Script vs Test Case

Below are the differences between test script and test case:

S No.

Test Case

Test Script

1. Scenarios that contain a set of actions to be performed to verify a feature or Performance. Set of Instructions to test a Scenario automatically.
2. Derived from Test Scenarios. Derived from Test Cases.
3. Verify the scenarios are compliant with IEEE/ 3GPP / Other Standards. Verify the Scenario passes or Fails.
4. Test Multiple Corner scenarios. Useful for repetitive testing.
5. Focuses mainly on the test scenario and procedure. Focuses on whether success or failure.
6. More resources are needed. Less time to run the script, but more effort needs to be put in to study and implement.
7. Allows Error detection and Defects. Automation of Test Cases.

Example: Suppose let’s say the task is to validate a file is JSON or not in a list of files. We can write a test script to check the same.


# Python code to check whether
# a file is JSON or not
import os
import sys
import json
if len(sys.argv) > 1:
    if os.path.exists(sys.argv[1]):
        file = open(sys.argv[1], "r")
        print("Validate JSON!")
        print(sys.argv[1] + " not found")
    print("Usage: <file>")

Output 1- Pass Case

C:\QC_Work\Projects\Geeks\GPL\Python>python sample1.json

Validate JSON!

Output 2- File to check is not entered


Usage: <file>

Output 3- Invalid File

C:\QC_Work\Projects\Geeks\GPL\Python>python sample3.json

sample3.json not found

Output 1

Fig 1.1 Test Script

Output 2

Fig 1.2 Valid JSON File

Output 3

Fig 1.3 Test Execution and Output

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!