testsigma
Topics

What is Test Script? How to write with Example

Test Scripts are the scripts or documents that testers create and follow for executing specific tests for specific functionalities. Test Scripts can also be created using automated tools. Here, let's explore test scripts in detail.
header-banner-image

Test scripts play a major role in software testing which helps to test, verify, and evaluate software applications. Knowing how to write an effective test script is very important for testers because well-written test scripts help not only the other QA engineers but also all other project stakeholders to understand their software product and verify it when needed.  

In this article, we are going to get to know what are test scripts, their importance, and how to write test scripts using test scripts examples. Whether you are an experienced quality assurance professional or new to the industry, this guide will provide you with some insights, examples, and practical tips on mastering the way of writing effective test scripts.

What is a Test Script in Software Testing?

A test script should include all the steps to test a specific functionality or action in the required order of testing. In a test script, each test step should include necessary entries, like test data, and it should also specify the expected results. A test script can be documented or automated using any preferred programming language, such as Java, Python, etc.

Why use Test Script?

The use of test scripts is the most reliable way to ensure that nothing is skipped during testing. Test scripts become even more important when the user requirements are highly specific. Most importantly, they provide a standardized approach to conducting testing tasks, ensuring that the same steps are followed every time, leading to consistent results. Well-structured test scripts assist new QA engineers in a particular domain, preventing the need for domain experts to handhold them during testing. This principle applies not only to testers but also to developers and any other stakeholders seeking an understanding of specific functionalities.

Who writes test scripts?

Usually, test scripts are written by experienced testers or quality assurance professionals who know the testing domain very well. They follow specific instructions to write the test scripts based on the software requirements, acceptance criteria, user stories, and quality goals. Sometimes, developers and other business stakeholders might also help create test scripts for certain types of testing.

When to use the Test Script Approach?

The test script approach is ideal for accurate and repetitive testing, especially when dealing with larger and more complex software products. Picture testing a sizable software product with numerous modules to cover. It becomes much more manageable to maintain separate test scripts, preventing the oversight of test steps for each testable component. 

Automated test scripts are particularly beneficial for extensive projects under maintenance. Whenever a new bug fix or feature is introduced, QA engineers can run automated test scripts to validate the entire software product’s functionality, saving both time and effort. As mentioned earlier, this approach proves invaluable for software projects with a dynamic testing team, where QA engineers may change from time to time.

Example of a Test Script

Since we have already discussed what test scripts are, now we are going to get to know how to write test scripts using test scripts examples. For that, let us take a simple test case example. Below is a manual test script example which is created to test the file uploading functionality of a web application.

Test Script Title: Verify whether the user can upload a PDF file to the application

Preconditions: The user should have a valid login username (testUser) and password (testPassword).

Test Steps

  1. Load the web application from a web browser.
  2. Log in to the application.
  3. Navigate to the file upload section.
  4. Browse a PDF file and select.
  5. Click on the file upload button.
  6. Verify whether the success message is received.

Expected Results: The user should be able to upload a PDF file to the web application successfully.

Please note that the wording or the technical terms in the test scripts can be different from one software project to another due to various technical reasons and backgrounds. However, this manual test script example can be considered a dummy test script.

How to Write a Test Script?

From here onwards, we are going to guide you on how to write a simple automated test script using a test automation tool. Here we are going to use Testigma to write a test script for testing a simple login scenario.

  1. First log in to the Testigma application and you will be navigated to the Testigma dashboard.
Testsigma dashboard
  1. There you can hover on the “Create New” drop down which is located in the top left corner and click on the “Test Case” option.
  2. There you will be navigated to the “Create Test Case” screen. You can give a meaningful name for your test script. Here, you can give a name such as “Verify whether the user can log in to the application with a valid username and password”.
  3. Under the URL area, you can give the URL of the login page of your web application. (Please note that this is not mandatory since we can define the URL in the test steps as well.)
Testsigma Dashboard
  1. If you are going to write a test script manually, you can click on the button which is displayed as “Write Test Manually”. (If you want to record the test steps, click on the “Record” button)
  2. With that, you will be navigated to a separate screen which we need to define the respective test steps. There you can write the test steps one by one and click on the “Create” button after writing each test step. For example, the test steps will be,
    1. Navigate to <Application URL>.
    2. Insert username <Valid Username>.
    3. Insert password <Valid Password>.
    4. Click on the Login button.
    5. Validate the successful login page.
  3. In Testigma, there are several ways for you to define test steps. Using them it is easy to configure the test steps when it comes to running the test script. For example, let us take the second test step which is inserting a valid username. There, you can define the test step like “Enter <Valid Username> in the <Element> field. You don’t have to remember the ways to define test steps because Testigma provides automatic suggestions.
Test steps
  1. When clicking on the element in your test step, the “Select Element” section will appear in the screen. There you can navigate to the “Create Element” tab.
  2. In the “Create Element” tab, you need to give the information of the element you are going to refer to. Let’s assume that we are going to refer to the XPath of the element called “TxtUsername”. We can give “TxtUsername” for the Name, define the screen as “Login” and select XPath from the “Element Type” dropdown. Under the “Enter Value” section, the value of the XPath can be given.
Testsigma Record element
  1. The password insertion step can be handled in the same way.
  2. Next, you can define the test step as “Click on Element” and define the login button as the element. Create element action can be done in the same way as previous. You have to simply give the element name, screen, element type, and the element value.
  3. It is very important to have assertions when it comes to test scripting otherwise we might not be able to verify whether we have navigated to the correct destination. This is why we have added the last test step.
  4. There, you can add a test step in Testigma like “Verify that the current page title contains <Successful Login>”. (Please note that Testigma has a lot of suggestions when it comes to assertion test steps.)
  5. Now, we are done with the test scripting part. Let’s click on the “Run” button at the top.
  6. After clicking on the Run button, the Ad-hoc Run section will appear. There, you can configure the run settings by changing information such as Test Running Environment, Operating System, OS Version, Browser, Browser Version, Resolution, Headless Run, etc.
Testsigma Ad-hoc Run
  1. After configuring those settings and executing the script, you will be able to see the results of your automated test script.

Although we’ve manually added the test steps to our test script in this approach, Testigma offers a simpler way of test scripting through a recording feature.

In Testigma, you can view the status (Pass/Fail) of each test step in your test script, along with individual execution times, logs, and screenshots.



Tips for Creating a Test Script

Here are some tips which will be helpful when writing an effective test script,

  • Give clear objectives: To start writing a test script, ensure that its objectives and goals are clearly defined. Specify what you intend to test and the expected outcomes by providing a descriptive title for your test script.
  • Document in a well-detailed manner: Ensure that a test script is extensively documented, using clear and understandable language. Include details such as preconditions, test data, test steps, expected results, and any dependencies. This thorough documentation is essential because individuals with limited domain knowledge may refer to your test scripts. That’s why many experienced QA engineers advise, “Always write your test steps at a level that can be understood by your parents for them to run the tests independently.”
  • Use of data-driven testing approaches: It’s a beneficial data management tactic that tests various scenarios by changing only the input test data. Conversely, isolating test data from production environments helps prevent unintended data changes during testing. For instance, you can manage distinct data sets for test scripts, conducting tests in the QA environment, staging environment, and production environment.
  • Always add assertions: In automated test scripting, adding assertions is important, particularly in scenarios like login verification. For instance, in a login scenario, it’s essential to confirm that the page following a successful login is reached. These validations can be achieved using straightforward success messages or even page responses during automation. However, it’s always advisable to include assertions as extensively as possible in your test script.
  • Include proper error-handling: Including proper error-handling mechanisms in your test scripts will handle unexpected situations and check whether there are meaningful error messages as well. This is as important as the assertions.
  • Divide test scripts into small modules & use a proper naming convention: Instead of putting all the test scripts as a single bunch, it is easy to maintain them if you break down those into modular components when testing a large and complex software application. It is easy to maintain the test scripts by using descriptive naming conventions and comments for more clarity.
  • Update test scripts regularly: Changing the client requirements from time to time is the nature of a normal software project. Even though it is annoying, it is always better to review your test scripts and update them from time to time according to those requirement changes.

Benefits of a Test Script

Here are some of the benefits of using test scripts in software testing,

  • Clear documentation: Test scripts can be considered as the most clear documentation of test cases which makes life easier for both new and experienced testers and the developers as well. Sometimes, even business analysts and other stakeholders refer to the test scripts to get an idea about the existing behaviors in software applications.
  • Early bug detection: Having test scripts automated plays a huge role when it comes to early bug detection since those automation suits can be run from time to time even at the earliest of the development cycle while reducing the cost and the effort of fixing issues. It ultimately helps to save time and effort when it comes to sudden changes in features since the QA engineers can simply run their automated test scripts to verify that the software product is not broken.
  • Efficiency: The automation of repetitive tests through test scripts saves time, money, effort, and resource utilization compared to manual testing, while allowing the testers to focus more on complex test scenarios.
  • Increased test coverage: When it comes to large and complex software applications, there is a high possibility of missing test cases while testing. This can be avoided through test scripts, especially automated test scripts.
  • Reusability: Test scripts can be reused under various test cycles. As an example, a particular test script can be used in regression testing as well as smoke test suit and build acceptance test suit while testing. If the testers have effectively done parameterization, the same test scripts can be run on several different testing environments such as the staging environment and QA environment. This will ultimately reduce test creation efforts and time.
  • Consistency: With test scripts, the testers can ensure that the same test steps are executed all the time and make sure that the actual results are always the same. This helps them to increase the confidence that their software product is running stably.

Best Practices for Writing a Test Script

Now you know how to write a test script both manually and using an automation tool. However, it is more important to follow best practices while writing test scripts to get the maximum benefit of it. Here are some best practices,

  • Clearly-Written: The test scripts should be written in an easy-to-understand language so that no features and steps are missed in testing. If there is a need to ask a domain expert to provide the required details over and over again, it will certainly waste time and human resources. A test script should not be written to be understandable only for the QA engineers but also for any stakeholder of the software project.
  • Well-designed: A test script should always contain just one targeted action that the testers must take to verify. With that, it is easier to evaluate each test step properly and then the testers do not miss the particular steps in the testing process. As an example, if you are going to write a test script for a successful login scenario, it should not validate the failed login scenario with invalid credentials. It should be done via a separate test script.
  • Use the view of the user to write: To design an effective test script, it is better to think from the user’s mindset and think of all the possible happy and negative scenarios that the customer will try to perform and decide which paths should be verified. We always know that even though we have tested a feature considering the quality goals, users are always going to play around with the software product.
  • Commenting: It is always better to include comments within your test script to explain the purpose of each step and any required details which is helpful when it comes to testing. As same as software development, commenting plays a big role in test scripting as well.
  • Version control: We all know that version control is very important when it comes to software implementation and deployment. The same applies to test scripting as well. It is easier to track changes, collaborate with team members, and maintain test script integrity as well.
  • Parameterization: Parameterization helps a lot when it comes to saving time and effort in test runs since with proper parameterization, testers will be able to run the same set of test scripts in many different test environments just by changing a couple of values. This is more practical and beneficial when it comes to automated test scripts.

Conclusion

A test script cannot be considered as yet another useless documentation in a software development project because it plays a major role when it comes to sharing knowledge with the testers and developers and it always makes sure that the software product feature is thoroughly tested with no skippings of steps. Well-designed test scripts can be created manually or even using tools such as Testigma. It is always better to adhere to the best practices and tips when it comes to test scripting and it will help the QA engineers to get the maximum out of it. At the end of the day, we should know that the test scripts can be considered a powerful tool that makes the QA engineers’ lives easier.

Frequently Asked Questions

What is a test case and test script?

Is the test script and test plan the same?

How to write a test script in Selenium?