{"id":333,"date":"2015-05-11T17:05:06","date_gmt":"2015-05-11T11:35:06","guid":{"rendered":"http:\/\/scrolltest.com\/?p=333"},"modified":"2026-06-29T20:58:22","modified_gmt":"2026-06-29T15:28:22","slug":"selenium-test-case-using-data-driven-testing-in-python","status":"publish","type":"post","link":"https:\/\/scrolltest.com\/selenium-test-case-using-data-driven-testing-in-python\/","title":{"rendered":"Selenium Test case using Data Driven Testing in Python"},"content":{"rendered":"<!-- tta-cta v1 -->\n<p>In this tutorial, We are going to create a Data driven\u00a0framework in Selenium Python from start to end.<\/p>\n\n\n<p class=\"wp-block-paragraph\"><em>\ud83c\udfad <strong>Want to master this with real projects?<\/strong> Join the <a href=\"https:\/\/class.thetestingacademy.com\/playwright-automation-mastery-course\" target=\"_blank\" rel=\"noopener\"><strong>Playwright Automation Mastery<\/strong><\/a> course at The Testing Academy.<\/em><\/p>\n\n\n<p>Before that let&#8217;s understand what is Data Driven Testing? and Why it is required.<\/p><p>&nbsp;<\/p><h2>What is Data Driven Testing?<\/h2><p>In data-driven testing approach, we can use a single test to verify different sets of test cases or test data by driving the test with input and expected values from an external data source instead of using the hard-coded values every time a test is run.<\/p><h2>Why it is Required?<\/h2><p>Its very useful when we have similar tests that consist of the same steps but differ in the input data and expected value or the application state.<\/p><p>We need to install <a href=\"http:\/\/scrolltest.com\/7-minutes-to-learn-python-programming-right-now\/\" target=\"_blank\" rel=\"noopener noreferrer\">DDT in python <\/a>to work with Data driven Testing<\/p>\n<div class=\"wp-block-group has-background\" style=\"border-radius:14px;background-color:#0f172a;padding:28px\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-container-core-group-is-layout-0cb15eab wp-block-group-is-layout-constrained\">\n\n<h3 class=\"has-text-color wp-block-heading\" style=\"color:#ffffff\">\ud83d\ude80 Level Up Your Playwright<\/h3>\n\n\n<p class=\"has-text-color wp-block-paragraph\" style=\"color:#cbd5e1\">From locators to CI pipelines \u2014 build a production-grade Playwright + TypeScript framework step by step.<\/p>\n\n\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link has-text-color has-background\" style=\"border-radius:9px;background-color:#38bdf8;color:#06210f\" href=\"https:\/\/class.thetestingacademy.com\/playwright-automation-mastery-course\" target=\"_blank\" rel=\"noopener\">See the Playwright Course \u2192<\/a><\/div>\n\n<\/div>\n\n<\/div><\/div>\n\n\n<h2><span style=\"text-decoration: underline;\"><strong>Installing DDT<\/strong><\/span><\/h2><p>We can download and install ddt using the following command line:<\/p><p>&nbsp;&nbsp;<\/p><p>PS.\u00a0&#8211; Assuming that you have <a href=\"http:\/\/scrolltest.com\/selenium-testcase-with-nose-in-python\/\" target=\"_blank\" rel=\"noopener noreferrer\">unittest,selenium and nose installed<\/a>. If not go here.<\/p><p>If you are new to the Selenium Python &#8211; Checkout out below post.<\/p><ol><li><a href=\"https:\/\/scrolltest.com\/2016\/12\/12\/step-step-selenium-python-part-1\/\" target=\"_blank\" rel=\"noopener noreferrer\">Step by Step Selenium With Python \u2013 Part 1<\/a><\/li><li><a href=\"https:\/\/scrolltest.com\/2018\/04\/29\/getting-started-with-selenium-python-part-2-unittest-module\/\" target=\"_blank\" rel=\"noopener noreferrer\">Getting Started with Selenium Python \u2013 Part 2 (Unittest module)<\/a><\/li><li><a href=\"https:\/\/scrolltest.com\/2018\/05\/12\/getting-started-with-selenium-testcases-in-python-part-3\/\" target=\"_blank\" rel=\"noopener noreferrer\">Getting Started with Selenium Testcases in Python \u2013 Part 3<\/a><\/li><li><a href=\"https:\/\/scrolltest.com\/2018\/05\/13\/getting-started-with-selenium-test-cases-in-python%e2%80%8a-%e2%80%8apart-4\/\" target=\"_blank\" rel=\"noopener noreferrer\">Getting Started with Selenium Test cases in Python &#8211; Part 4<\/a><\/li><\/ol><h2><span style=\"text-decoration: underline;\"><strong>Steps to Create the DDT using unittest , nose with external <a href=\"http:\/\/scrolltest.com\/working-with-excel-files-in-python\/\" target=\"_blank\" rel=\"noopener noreferrer\">data sources(Excel)<\/a>:<\/strong><\/span><\/h2><p>1.\u00a0 Use the @ddt decorator for the test class.2.\u00a0 Use the @data decorator on the data-driven test methods.3.\u00a0 Use the @unpack decorator, which unpacks tuples or lists into multiple arguments.<\/p><h2><span style=\"text-decoration: underline;\"><strong>Project Structure:<\/strong><\/span><a><\/a><\/h2><h3><span style=\"text-decoration: underline;\"><strong>Importing ddt in the\u00a0 test<\/strong><\/span><\/h3><p>&nbsp;&nbsp;<\/p><p>Let&#8217;s write code for the Searching a Text on the \u201c<a title=\"http:\/\/demo.magentocommerce.com\" href=\"http:\/\/demo.magentocommerce.com\/\" target=\"_blank\" rel=\"noopener\">http:\/\/demo.magentocommerce.com<\/a>\u201d site and getting expected results. I have written a <a href=\"http:\/\/scrolltest.com\/the-ultimate-cheat-sheet-on-xpath-in-python\/\" target=\"_blank\" rel=\"noopener noreferrer\">search test<\/a>, which accepts a pair of arguments for different search value and expected value.&nbsp;<\/p><h3><span style=\"text-decoration: underline;\"><strong>Running the test case with Nose<\/strong><\/span><a><\/a><\/h3><p style=\"text-align: center;\">DDT will generate new test methods giving them meaningful names by converting the data values to valid Python identifier.<span style=\"text-decoration: underline;\"><strong><a href=\"http:\/\/code.scrolltest.com\/DDT_Selenium.zip\" target=\"_blank\" rel=\"noopener noreferrer\">Final Code Here<\/a><\/strong><\/span><\/p><p>Check out my other tutorials in the API Testing and Local Testing below<\/p><p><a href=\"https:\/\/scrolltest.com\/2018\/12\/15\/api-testing-tutorial\/\">The Definitive Guide to Do API Testing in 2019<\/a><\/p><p><a href=\"https:\/\/scrolltest.com\/2018\/11\/30\/how-to-do-local-testing-and-what-is-it\/\">How to do Local testing and what is it?<\/a><\/p><span><img loading=\"lazy\" decoding=\"async\" alt=\"\" data-id=\"2324\" width=\"480\" height=\"270\" title=\"Selenium Python Course\" src=\"https:\/\/scrolltest.com\/wp-content\/uploads\/2019\/12\/Selenium-Python-Course.jpg\" style=\"\"><\/span>\n\n\n<div class=\"wp-block-group has-background\" style=\"border-radius:14px;background-color:#0f172a;padding:28px\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-container-core-group-is-layout-0cb15eab wp-block-group-is-layout-constrained\">\n\n<h3 class=\"has-text-color wp-block-heading\" style=\"color:#ffffff\">\ud83c\udf93 Master Playwright End to End<\/h3>\n\n\n<p class=\"has-text-color wp-block-paragraph\" style=\"color:#cbd5e1\">Join hundreds of SDETs building real automation frameworks. Lifetime access, hands-on projects, and a job-ready portfolio.<\/p>\n\n\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link has-text-color has-background\" style=\"border-radius:9px;background-color:#22c55e;color:#06210f\" href=\"https:\/\/class.thetestingacademy.com\/playwright-automation-mastery-course\" target=\"_blank\" rel=\"noopener\">Enroll in Playwright Automation Mastery \u2192<\/a><\/div>\n\n<\/div>\n\n<\/div><\/div>\n\n\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, We are going to create a Data driven\u00a0framework in Selenium Python from start to end. \ud83c\udfad Want to master this with real projects? Join the Playwright Automation Mastery course at The Testing Academy. Before that let&#8217;s understand what is Data Driven Testing? and Why it is required. &nbsp; What is Data Driven&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_blocks_custom_css":"","_kad_blocks_head_custom_js":"","_kad_blocks_body_custom_js":"","_kad_blocks_footer_custom_js":"","_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"footnotes":""},"categories":[5,6],"tags":[561,14,16,563,273,562],"class_list":["post-333","post","type-post","status-publish","format-standard","hentry","category-python","category-selenium","tag-data-driven-framework-in-selenium-python","tag-python","tag-selenium","tag-selenium-python-example","tag-selenium-python-tutorial","tag-selenium-python-webdriver"],"taxonomy_info":{"category":[{"value":5,"label":"Python"},{"value":6,"label":"Selenium"}],"post_tag":[{"value":561,"label":"data driven framework in selenium python"},{"value":14,"label":"python"},{"value":16,"label":"selenium"},{"value":563,"label":"selenium python example"},{"value":273,"label":"selenium python tutorial"},{"value":562,"label":"selenium python webdriver"}]},"featured_image_src_large":false,"author_info":{"display_name":"Promode","author_link":"https:\/\/scrolltest.com\/author\/admin\/"},"comment_info":6,"category_info":[{"term_id":5,"name":"Python","slug":"python","term_group":0,"term_taxonomy_id":5,"taxonomy":"category","description":"","parent":0,"count":36,"filter":"raw","cat_ID":5,"category_count":36,"category_description":"","cat_name":"Python","category_nicename":"python","category_parent":0},{"term_id":6,"name":"Selenium","slug":"selenium","term_group":0,"term_taxonomy_id":6,"taxonomy":"category","description":"","parent":0,"count":72,"filter":"raw","cat_ID":6,"category_count":72,"category_description":"","cat_name":"Selenium","category_nicename":"selenium","category_parent":0}],"tag_info":[{"term_id":561,"name":"data driven framework in selenium python","slug":"data-driven-framework-in-selenium-python","term_group":0,"term_taxonomy_id":561,"taxonomy":"post_tag","description":"","parent":0,"count":1,"filter":"raw"},{"term_id":14,"name":"python","slug":"python","term_group":0,"term_taxonomy_id":14,"taxonomy":"post_tag","description":"","parent":0,"count":20,"filter":"raw"},{"term_id":16,"name":"selenium","slug":"selenium","term_group":0,"term_taxonomy_id":16,"taxonomy":"post_tag","description":"","parent":0,"count":45,"filter":"raw"},{"term_id":563,"name":"selenium python example","slug":"selenium-python-example","term_group":0,"term_taxonomy_id":563,"taxonomy":"post_tag","description":"","parent":0,"count":1,"filter":"raw"},{"term_id":273,"name":"selenium python tutorial","slug":"selenium-python-tutorial","term_group":0,"term_taxonomy_id":273,"taxonomy":"post_tag","description":"","parent":0,"count":2,"filter":"raw"},{"term_id":562,"name":"selenium python webdriver","slug":"selenium-python-webdriver","term_group":0,"term_taxonomy_id":562,"taxonomy":"post_tag","description":"","parent":0,"count":1,"filter":"raw"}],"_links":{"self":[{"href":"https:\/\/scrolltest.com\/wp-json\/wp\/v2\/posts\/333","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/scrolltest.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/scrolltest.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/scrolltest.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/scrolltest.com\/wp-json\/wp\/v2\/comments?post=333"}],"version-history":[{"count":1,"href":"https:\/\/scrolltest.com\/wp-json\/wp\/v2\/posts\/333\/revisions"}],"predecessor-version":[{"id":9292,"href":"https:\/\/scrolltest.com\/wp-json\/wp\/v2\/posts\/333\/revisions\/9292"}],"wp:attachment":[{"href":"https:\/\/scrolltest.com\/wp-json\/wp\/v2\/media?parent=333"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/scrolltest.com\/wp-json\/wp\/v2\/categories?post=333"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/scrolltest.com\/wp-json\/wp\/v2\/tags?post=333"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}