{"id":2071,"date":"2024-02-06T07:37:05","date_gmt":"2024-02-06T07:37:05","guid":{"rendered":"https:\/\/blog.amt.in\/?p=2071"},"modified":"2024-02-06T07:37:05","modified_gmt":"2024-02-06T07:37:05","slug":"insights-on-test-scripts","status":"publish","type":"post","link":"https:\/\/blog.amt.in\/index.php\/2024\/02\/06\/insights-on-test-scripts\/","title":{"rendered":"Insights on Test scripts"},"content":{"rendered":"<p>Test scripts are essential components of software testing. They are sets of instructions, written in a programming language or in a human-readable format, that outline the steps to be taken to verify the functionality of a software application. Test scripts can be automated or manual, and they serve several purposes:<\/p>\n<p>Reproducibility: Test scripts ensure that tests can be executed consistently, allowing for the reproduction of bugs and issues.<\/p>\n<p>Verification: They verify that the software behaves as expected under various conditions and scenarios.<\/p>\n<p>Documentation: Test scripts serve as documentation for the testing process, making it easier for testers to understand what needs to be tested and how.<\/p>\n<p>Automation: Automated test scripts automate repetitive testing tasks, saving time and effort in the long run.<\/p>\n<p>Regression Testing: They are crucial for regression testing, ensuring that new changes or features don&#8217;t break existing functionality.<\/p>\n<p>Here&#8217;s a simple example of a manual test script for testing the login functionality of a web application:<br \/>\nTest Case ID: TC_Login_001<br \/>\nTest Case Description: Verify user can log in with valid credentials.<\/p>\n<p>Preconditions:<br \/>\n&#8211; User has valid credentials (username and password).<br \/>\n&#8211; Web browser is open and navigated to the login page of the application.<\/p>\n<p>Test Steps:<br \/>\n1. Enter valid username into the username field.<br \/>\n2. Enter valid password into the password field.<br \/>\n3. Click on the &#8220;Login&#8221; button.<\/p>\n<p>Expected Results:<br \/>\n&#8211; User should be redirected to the home page.<br \/>\n&#8211; The user&#8217;s name or profile icon should be displayed indicating successful login.<br \/>\n&#8211; No error messages should be displayed.<\/p>\n<p>Test Case Status: Pass\/Fail<br \/>\nThis is just a basic example. Test scripts can vary greatly in complexity depending on the application being tested and the testing methodology being followed. Automated test scripts might involve writing code using testing frameworks like Selenium for web applications or Appium for mobile applications.<\/p>\n<p>Here&#8217;s a more detailed example of a test script, this time focusing on a scenario where automated testing is utilized. Let&#8217;s consider a scenario where we want to test the functionality of adding items to a shopping cart on an e-commerce website:<\/p>\n<div class=\"dark bg-black rounded-md\">\n<div class=\"p-4 overflow-y-auto\"><code class=\"!whitespace-pre hljs language-python\"><code class=\"!whitespace-pre hljs language-python\"><span class=\"hljs-keyword\">import<\/span> unittest<br \/>\n<span class=\"hljs-keyword\">from<\/span> selenium <span class=\"hljs-keyword\">import<\/span> webdriver<\/code><\/code><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">ShoppingCartTest<\/span>(unittest.TestCase):<br \/>\n<span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title function_\">setUp<\/span>(<span class=\"hljs-params\">self<\/span>):<br \/>\n<span class=\"hljs-comment\"># Setup method to initialize the webdriver and open the browser<\/span><br \/>\nself.driver = webdriver.Chrome()<br \/>\nself.driver.maximize_window()<br \/>\nself.driver.get(<span class=\"hljs-string\">&#8220;http:\/\/www.example.com&#8221;<\/span>) <span class=\"hljs-comment\"># Replace with the URL of the e-commerce website<\/span><code class=\"!whitespace-pre hljs language-python\"><code class=\"!whitespace-pre hljs language-python\"><\/code><\/code><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title function_\">test_add_to_cart<\/span>(<span class=\"hljs-params\">self<\/span>):<br \/>\n<span class=\"hljs-comment\"># Test method to verify adding items to the shopping cart<\/span><br \/>\nsearch_box = self.driver.find_element_by_id(<span class=\"hljs-string\">&#8220;search-box&#8221;<\/span>)<br \/>\nsearch_box.send_keys(<span class=\"hljs-string\">&#8220;Product Name&#8221;<\/span>) <span class=\"hljs-comment\"># Replace with the name of the product to be searched<\/span><br \/>\nsearch_button = self.driver.find_element_by_id(<span class=\"hljs-string\">&#8220;search-button&#8221;<\/span>)<br \/>\nsearch_button.click()<\/p>\n<p><code class=\"!whitespace-pre hljs language-python\"><code class=\"!whitespace-pre hljs language-python\"><\/code><\/code><span class=\"hljs-comment\"># Assuming the first search result is the desired product, click on its &#8216;Add to Cart&#8217; button<\/span><br \/>\nadd_to_cart_button = self.driver.find_element_by_xpath(<span class=\"hljs-string\">&#8220;\/\/button[@class=&#8217;add-to-cart-button&#8217;]&#8221;<\/span>)<br \/>\nadd_to_cart_button.click()<\/p>\n<p><code class=\"!whitespace-pre hljs language-python\"><code class=\"!whitespace-pre hljs language-python\"><\/code><\/code><span class=\"hljs-comment\"># Verify that the item has been added to the cart<\/span><br \/>\ncart_icon = self.driver.find_element_by_xpath(<span class=\"hljs-string\">&#8220;\/\/span[@class=&#8217;cart-icon&#8217;]&#8221;<\/span>)<br \/>\nself.assertTrue(cart_icon.is_displayed(), <span class=\"hljs-string\">&#8220;Item was not added to the shopping cart.&#8221;<\/span>)<\/p>\n<p><code class=\"!whitespace-pre hljs language-python\"><code class=\"!whitespace-pre hljs language-python\"><\/code><\/code><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title function_\">tearDown<\/span>(<span class=\"hljs-params\">self<\/span>):<br \/>\n<span class=\"hljs-comment\"># Teardown method to close the browser after each test<\/span><br \/>\nself.driver.quit()<\/p>\n<p><code class=\"!whitespace-pre hljs language-python\"><code class=\"!whitespace-pre hljs language-python\"><\/code><\/code><span class=\"hljs-keyword\">if<\/span> __name__ == <span class=\"hljs-string\">&#8220;__main__&#8221;<\/span>:<br \/>\nunittest.main()<\/p>\n<\/div>\n<\/div>\n<p>In this example:<\/p>\n<ul>\n<li>We use the <code>unittest<\/code> framework for organizing and running test cases.<\/li>\n<li>The <code>setUp<\/code> method is used to set up the preconditions for the test, such as initializing the WebDriver and opening the browser.<\/li>\n<li>The <code>test_add_to_cart<\/code> method represents the actual test case. It simulates searching for a product, clicking on the &#8216;Add to Cart&#8217; button, and then verifies that the item has been added to the shopping cart.<\/li>\n<li>The <code>tearDown<\/code> method is used to clean up after each test, closing the browser instance.<\/li>\n<li>We utilize the Selenium WebDriver library to interact with the web elements on the e-commerce website.<\/li>\n<\/ul>\n<p>This script is just an example and would need to be customized based on the specific elements and behavior of the e-commerce website being tested. Additionally, error handling and assertions can be expanded to cover more scenarios and edge cases.<\/p>\n<p>Above is brief about Test scripts. Watch this space for more update on the latest trends in Technology.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Test scripts are essential components<\/p>\n","protected":false},"author":1,"featured_media":2074,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[458,7,1083],"tags":[460,18,1084],"class_list":["post-2071","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software-testing","category-techtrends","category-test-scripts","tag-software-testing","tag-technology","tag-test-scripts"],"_links":{"self":[{"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/posts\/2071","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/comments?post=2071"}],"version-history":[{"count":3,"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/posts\/2071\/revisions"}],"predecessor-version":[{"id":2075,"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/posts\/2071\/revisions\/2075"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/media\/2074"}],"wp:attachment":[{"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/media?parent=2071"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/categories?post=2071"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/tags?post=2071"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}