{"id":393,"date":"2021-05-20T12:00:00","date_gmt":"2021-05-20T12:00:00","guid":{"rendered":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/2021\/05\/20\/testng-test-priority-in-selenium\/"},"modified":"2021-05-20T12:00:00","modified_gmt":"2021-05-20T12:00:00","slug":"testng-test-priority-in-selenium","status":"publish","type":"post","link":"https:\/\/rahulshettyacademy.com\/blog\/2021\/05\/20\/testng-test-priority-in-selenium\/","title":{"rendered":"TestNG @Test Priority in Selenium"},"content":{"rendered":"<p><html><body><\/p>\n<section class=\"tcb-post-content tcb-shortcode thrv_wrapper\" data-css=\"tve-u-16ec5d248bb\">\n<div class=\"tve_flt tcb-style-wrap\" id=\"tve_flt\">\n<div class=\"tve_shortcode_editor tar-main-content\" data-post-id=\"393\" id=\"tve_editor\">\n<div class=\"thrv_wrapper thrv_text_element\">\n<p>TestNG is a Testing framework, that covers different types of test designs like a unit test, functional test, end to end test, UI test and integration test. You can run a single or multiple test cases in your Testng code.<\/p>\n<div class=\"code-block code-block-2\" style=\"margin: 8px auto; text-align: center; display: block; clear: both;\">\n<p><!-- horizontal responsive 2 --><br \/>\n<ins class=\"adsbygoogle\" data-ad-client=\"ca-pub-3231318496783163\" data-ad-format=\"auto\" data-ad-slot=\"2788468763\" data-full-width-responsive=\"true\" style=\"display:block\"><\/ins>\n<\/div>\n<p>If test priority is not defined while, running multiple test cases, TestNG assigns all @Test a priority as zero(0).<\/p>\n<p>Now, while running; lower priorities will be scheduled first.<\/p>\n<\/div>\n<div class=\"thrv_wrapper tve-toc tve-elem-scroll tve-toc-expandable tcb-local-vars-root\" data-animation=\"slide\" data-bullet-style='{\"0\":\"tve-u-17399ff41d4\",\"1\":\"tve-u-17399ffc502\",\"2\":\"tve-u-17399ffedb7\"}' data-columns=\"1\" data-css=\"tve-u-1798a4861de\" data-ct=\"toc-60733\" data-ct-name=\"Table of Contents 13\" data-distribute=\"false\" data-element-name=\"Table of Contents\" data-headers=\"h1,h3,h5\" data-heading-style='{\"0\":\"tve-u-1798a4861e7\",\"1\":\"tve-u-1798a4861e8\",\"2\":\"tve-u-1798a4861e9\"}' data-highlight=\"heading\" data-number-style='{\"0\":\"tve-u-17399fecc2c\",\"1\":\"tve-u-173dc8687ce\",\"2\":\"tve-u-173dc86929b\"}' data-numbering=\"none\" data-state-default=\"expanded\" data-state-default-d=\"expanded\" data-transition=\"slide\" style=\"\">\n<div class=\"thrive-colors-palette-config\" style=\"display: none !important\"><\/div>\n<div class=\"tve-toc-divider\" style=\"position: absolute; width: 0; height: 0; overflow: hidden;\">\n<div class=\"thrv_wrapper thrv-divider tve-vert-divider\" data-color-d=\"rgb(217, 217, 217)\" data-style=\"tve_sep-1\">\n<hr class=\"tve_sep tve_sep-1\" style=\"\"\/><\/div>\n<\/div>\n<p><svg class=\"toc-icons\" style=\"position: absolute; width: 0; height: 0; overflow: hidden;\" version=\"1.1\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\"><symbol data-id=\"icon-chevron_right-duotone\" id=\"toc-bullet-0\" viewbox=\"0 0 24 24\"><path d=\"M0 0h24v24H0V0z\" fill=\"none\"><\/path><path d=\"M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6-6-6z\"><\/path><\/symbol><symbol data-id=\"icon-chevron_right-duotone\" id=\"toc-bullet-1\" viewbox=\"0 0 24 24\"><path d=\"M0 0h24v24H0V0z\" fill=\"none\"><\/path><path d=\"M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6-6-6z\"><\/path><\/symbol><symbol data-id=\"icon-chevron_right-duotone\" id=\"toc-bullet-2\" viewbox=\"0 0 24 24\"><path d=\"M0 0h24v24H0V0z\" fill=\"none\"><\/path><path d=\"M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6-6-6z\"><\/path><\/symbol><\/svg><\/p>\n<div class=\"tve-content-box-background\" data-css=\"tve-u-1798a4861e0\" style=\"\"><\/div>\n<div class=\"thrv_wrapper tve-toc-title tcb-icon-display reverse tve-no-dropzone tve-prevent-content-edit\" data-css=\"tve-u-1798a4861e1\" style=\"\">\n<div class=\"tve-content-box-background\" style=\"\"><\/div>\n<div class=\"tve-cb\" style=\"\">\n<div class=\"tve-toc-title-icon\" data-icon-code=\"icon-chevron-down-solid\" style=\"\"><svg class=\"tcb-icon\" data-id=\"icon-chevron-down-solid\" data-name=\"\" viewbox=\"0 0 24 24\"><path d=\"M7.41,8.58L12,13.17L16.59,8.58L18,10L12,16L6,10L7.41,8.58Z\"><\/path><\/svg><\/div>\n<div class=\"thrv_wrapper thrv_text_element tve_no_icons\">\n<div class=\"tcb-plain-text\" data-css=\"tve-u-1798a4861e2\" style=\"\">table of contents<\/div>\n<\/p><\/div>\n<\/div>\n<\/div>\n<div class=\"tve-cb tve-toc-content tve-prevent-content-edit\" style=\"\">\n<div class=\"thrv_wrapper thrv_contentbox_shortcode thrv-content-box tve-elem-default-pad\" data-css=\"tve-u-1798a4861e3\" style=\"\">\n<div class=\"tve-content-box-background\" data-css=\"tve-u-1798a4861e4\" style=\"\"><\/div>\n<div class=\"tve-cb\"><\/div>\n<\/div>\n<div class=\"thrv_wrapper tve-toc-list tcb-no-delete tcb-no-save tcb-no-clone tve-no-dropzone\" data-css=\"tve-u-1798a4861e5\" style=\"\">\n<div class=\"tve-content-box-background\" data-css=\"tve-u-1798a4861e6\" style=\"\"><\/div>\n<div class=\"tve-cb\">\n<div class=\"tve_ct_content tve_clearfix\">\n<div class=\"ct_column\">\n<div class=\"thrv_wrapper tve-toc-heading tve-toc-heading-level1 tve_no_icons\" data-css=\"tve-u-1798a4861e8\" data-element-name=\"Heading Level 2\" data-tag=\"H3\"><a class=\"tve-toc-anchor tve-jump-scroll\" href=\"#t-1621522594821\" jump-animation=\"smooth\">Demo of TestNG code without Priority<\/a><\/div>\n<div class=\"thrv_wrapper tve-toc-heading tve-toc-heading-level2 tve_no_icons\" data-css=\"tve-u-1798a4861e9\" data-element-name=\"Heading Level 3\" data-tag=\"H5\"><a class=\"tve-toc-anchor tve-jump-scroll\" href=\"#t-1621522594822\" jump-animation=\"smooth\">Explanation of Code<\/a><\/div>\n<div class=\"thrv_wrapper tve-toc-heading tve-toc-heading-level1 tve_no_icons\" data-css=\"tve-u-1798a4861e8\" data-element-name=\"Heading Level 2\" data-tag=\"H3\"><a class=\"tve-toc-anchor tve-jump-scroll\" href=\"#t-1621522594823\" jump-animation=\"smooth\">Demo of TestNG code without Priority in Alphabetical Order<\/a><\/div>\n<div class=\"thrv_wrapper tve-toc-heading tve-toc-heading-level2 tve_no_icons\" data-css=\"tve-u-1798a4861e9\" data-element-name=\"Heading Level 3\" data-tag=\"H5\"><a class=\"tve-toc-anchor tve-jump-scroll\" href=\"#t-1621522594824\" jump-animation=\"smooth\">Output of code<\/a><\/div>\n<div class=\"thrv_wrapper tve-toc-heading tve-toc-heading-level1 tve_no_icons\" data-css=\"tve-u-1798a4861e8\" data-element-name=\"Heading Level 2\" data-tag=\"H3\"><a class=\"tve-toc-anchor tve-jump-scroll\" href=\"#t-1621522594825\" jump-animation=\"smooth\">How to set Priority in TestNG<\/a><\/div>\n<div class=\"thrv_wrapper tve-toc-heading tve-toc-heading-level2 tve_no_icons\" data-css=\"tve-u-1798a4861e9\" data-element-name=\"Heading Level 3\" data-tag=\"H5\"><a class=\"tve-toc-anchor tve-jump-scroll\" href=\"#t-1621522594826\" jump-animation=\"smooth\">Output of code<\/a><\/div>\n<div class=\"thrv_wrapper tve-toc-heading tve-toc-heading-level1 tve_no_icons\" data-css=\"tve-u-1798a4861e8\" data-element-name=\"Heading Level 2\" data-tag=\"H3\"><a class=\"tve-toc-anchor tve-jump-scroll\" href=\"#t-1621522594827\" jump-animation=\"smooth\">Methods with Same Priority<\/a><\/div>\n<div class=\"thrv_wrapper tve-toc-heading tve-toc-heading-level2 tve_no_icons\" data-css=\"tve-u-1798a4861e9\" data-element-name=\"Heading Level 3\" data-tag=\"H5\"><a class=\"tve-toc-anchor tve-jump-scroll\" href=\"#t-1621522594828\" jump-animation=\"smooth\">Output of code<\/a><\/div>\n<div class=\"thrv_wrapper tve-toc-heading tve-toc-heading-level1 tve_no_icons\" data-css=\"tve-u-1798a4861e8\" data-element-name=\"Heading Level 2\" data-tag=\"H3\"><a class=\"tve-toc-anchor tve-jump-scroll\" href=\"#t-1621522594829\" jump-animation=\"smooth\">Combining both prioritized(having same priority) and non-prioritized methods<\/a><\/div>\n<div class=\"thrv_wrapper tve-toc-heading tve-toc-heading-level2 tve_no_icons\" data-css=\"tve-u-1798a4861e9\" data-element-name=\"Heading Level 3\" data-tag=\"H5\"><a class=\"tve-toc-anchor tve-jump-scroll\" href=\"#t-1621522594830\" jump-animation=\"smooth\">Output of Code<\/a><\/div>\n<div class=\"thrv_wrapper tve-toc-heading tve-toc-heading-level1 tve_no_icons\" data-css=\"tve-u-1798a4861e8\" data-element-name=\"Heading Level 2\" data-tag=\"H3\"><a class=\"tve-toc-anchor tve-jump-scroll\" href=\"#t-1621522594831\" jump-animation=\"smooth\">Case-sensitive in TestNG<\/a><\/div>\n<div class=\"thrv_wrapper tve-toc-heading tve-toc-heading-level1 tve_no_icons\" data-css=\"tve-u-1798a4861e8\" data-element-name=\"Heading Level 2\" data-tag=\"H3\"><a class=\"tve-toc-anchor tve-jump-scroll\" href=\"#t-1621522594832\" jump-animation=\"smooth\">Conclusion<\/a><\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv-divider tve-vert-divider\" data-color-d=\"rgb(217, 217, 217)\" data-style=\"tve_sep-1\">\n<hr class=\"tve_sep tve_sep-1\" style=\"\"\/><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<h3 class=\"\"><strong>Demo of TestNG code without Priority<\/strong><\/h3>\n<p>Let us take a scenario where sequencing will be required in order to pass all test cases:<\/p>\n<p><strong>Scenario:<\/strong> Generate a code where you are required to perform a Google search with a specific keyword say &#8220;Facebook&#8221;. Now, verify that Browser title is changed to &#8220;Facebook &#8211; Google Search&#8221;.<\/p>\n<p>Note: Each step which you code should be in separate methods<\/p>\n<p><strong>Method 1<\/strong>: Open Browser say chrome (openBrowser())<\/p>\n<p><strong>Method 2<\/strong>: Launch Google.com (launchGoogle())<\/p>\n<p><strong>Method 3<\/strong>: Perform a search using &#8220;Facebook&#8221; (performSearchAndClickFirstLink())<\/p>\n<p><strong>Method 4<\/strong>: Verify Google search page title (faceBookPageTitleVerification())<\/p>\n<\/div>\n<div class=\"thrv_wrapper thrv_contentbox_shortcode thrv-content-box tve-elem-default-pad\">\n<div class=\"tve-content-box-background\" style=\"background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)) !important; background-size: auto !important; background-position: 50% 50% !important; background-attachment: scroll !important; background-repeat: no-repeat !important; --background-image:linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5))  !important; --background-size:auto auto  !important; --background-position:50% 50%  !important; --background-attachment:scroll  !important; --background-repeat:no-repeat  !important;\"><\/div>\n<div class=\"tve-cb\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-1798a4900d1\" style=\"\">\n<p data-css=\"tve-u-1798a495bb3\" style=\"\"><strong>package<\/strong> firsttestngpackage;<\/p>\n<p data-css=\"tve-u-1798a495bb5\" style=\"\"><strong>import<\/strong> org.openqa.selenium.By;<\/p>\n<p data-css=\"tve-u-1798a495bb6\" style=\"\"><strong>import<\/strong> org.openqa.selenium.WebDriver;<\/p>\n<p data-css=\"tve-u-1798a495bb7\" style=\"\"><strong>import<\/strong> org.openqa.selenium.chrome.ChromeDriver;<\/p>\n<p data-css=\"tve-u-1798a495bb9\" style=\"\"><strong>import<\/strong> org.testng.Assert;<\/p>\n<p data-css=\"tve-u-1798a495bba\" style=\"\"><strong>import<\/strong> org.testng.annotations.Test;<\/p>\n<p data-css=\"tve-u-1798a495bbb\" style=\"\"><strong>public<\/strong><br \/>\n<strong>class<\/strong> PriorityDemo {<\/p>\n<p data-css=\"tve-u-1798a495bbc\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 WebDriver driver;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/p>\n<p data-css=\"tve-u-1798a495bbe\" style=\"\">\u00a0\u00a0\u00a0 \/\/ Method 1: Open <u>Brower<\/u> say <u>Firefox<\/u>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/p>\n<p data-css=\"tve-u-1798a495bbf\" style=\"\">\u00a0\u00a0\u00a0 @Test\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/p>\n<p data-css=\"tve-u-1798a495bc0\" style=\"\">\u00a0\u00a0\u00a0 <strong>public<\/strong><br \/>\n<strong>void<\/strong> openBrowser() {\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/p>\n<p data-css=\"tve-u-1798a495bc1\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 driver = <strong>new<\/strong> ChromeDriver();\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/p>\n<p data-css=\"tve-u-1798a495bc3\" style=\"\">\u00a0\u00a0\u00a0 }\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/p>\n<p data-css=\"tve-u-1798a495bc4\" style=\"\">\u00a0\u00a0\u00a0 \/\/ Method 2: Launch Google.com\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/p>\n<p data-css=\"tve-u-1798a495bc5\" style=\"\">\u00a0\u00a0\u00a0 @Test\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/p>\n<p data-css=\"tve-u-1798a495bc6\" style=\"\">\u00a0\u00a0\u00a0 <strong>public<\/strong><br \/>\n<strong>void<\/strong> launchGoogle() {\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/p>\n<p data-css=\"tve-u-1798a495bc8\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 driver.get(&#8220;http:\/\/www.google.co.in&#8221;);\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/p>\n<p data-css=\"tve-u-1798a495bc9\" style=\"\">\u00a0\u00a0\u00a0 }\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/p>\n<p data-css=\"tve-u-1798a495bca\" style=\"\">\u00a0\u00a0\u00a0<\/p>\n<p data-css=\"tve-u-1798a495bcb\" style=\"\">\u00a0\u00a0\u00a0 \/\/ Method 3: Perform a search using &#8220;<u>Facebook<\/u>&#8221;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/p>\n<p data-css=\"tve-u-1798a495bcd\" style=\"\">\u00a0\u00a0\u00a0 @Test\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/p>\n<p data-css=\"tve-u-1798a495bce\" style=\"\">\u00a0\u00a0\u00a0 <strong>public<\/strong><br \/>\n<strong>void<\/strong> peformSeachAndClickFirstLink() {\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/p>\n<p data-css=\"tve-u-1798a495bcf\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 driver.findElement(By.<em>xpath<\/em>(&#8220;.\/\/*[@title=&#8217;Search&#8217;]&#8221;)).sendKeys(&#8220;Facebook&#8221;);\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/p>\n<p data-css=\"tve-u-1798a495bd0\" style=\"\">\u00a0\u00a0\u00a0 }\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/p>\n<p data-css=\"tve-u-1798a495bd2\" style=\"\">\u00a0\u00a0\u00a0 \/\/ Method 4: Verify Google search page title.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/p>\n<p data-css=\"tve-u-1798a495bd3\" style=\"\">\u00a0\u00a0\u00a0 @Test\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/p>\n<p data-css=\"tve-u-1798a495bd4\" style=\"\">\u00a0\u00a0\u00a0 <strong>public<\/strong><br \/>\n<strong>void<\/strong> faceBookPageTitleVerification() <strong>throws<\/strong> Exception {\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/p>\n<p data-css=\"tve-u-1798a495bd5\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 driver.findElement(By.<em>xpath<\/em>(&#8220;.\/\/*[@value=&#8217;Search&#8217;]&#8221;)).click();\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/p>\n<p data-css=\"tve-u-1798a495bd6\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Thread.<em>sleep<\/em>(3000);\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/p>\n<p data-css=\"tve-u-1798a495bd8\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Assert.<em>assertEquals<\/em>(driver.getTitle().contains(&#8220;Facebook &#8211; Google Search&#8221;), <strong>true<\/strong>);\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/p>\n<p data-css=\"tve-u-1798a495bd9\" style=\"\">\u00a0\u00a0\u00a0 }\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/p>\n<p data-css=\"tve-u-1798a495bda\" style=\"\">}<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<h5 class=\"\"><strong>Explanation of Code<\/strong><\/h5>\n<p>As mentioned above we have created 4 test cases for performing each action in an independent method.<\/p>\n<ul type=\"disc\">\n<li>The first method <strong>(openBrowser)<\/strong> states to initialize Firefox browser.<\/li>\n<li>The second method<strong> (launchGoogle)<\/strong> states that launch Google.com is in the initialized browser.<\/li>\n<li>The third method<strong> (peformSeachAndClickFirstLink)<\/strong>states that perform a search in the search box (with xpath<strong> (&#8220;.\/\/*[@title=&#8217;Search&#8217;]&#8221;)<\/strong> with a search term as<strong> Facebook<\/strong> and<\/li>\n<li>The fourth and last method<strong> (faceBookPageTitleVerification)<\/strong> states that click on search icon of Google and verify that browser title has been changed to<strong> Facebook &#8211; Google Search.<\/strong><\/li>\n<\/ul>\n<p>Now run this code using testNG as shown in the video you will find all the<u> Test Case <\/u>are failing. The reason for failure: as there is a dependency of previous test case to pass, only than current running test case will be passed.<\/p>\n<p>In this case,<\/p>\n<ul type=\"disc\">\n<li>First method which is executed is<strong> openBrowser().<\/strong> It got passed because it does not have any dependency.<\/li>\n<li>Second method executed is <strong>faceBookPageTitleVerification(); <\/strong>it is failing because we are trying to click search button and verifying browser title.<\/li>\n<li>You can see that if search activity is not process then how any other step can get passed. Hence, this is the reason my test cases are failing.<\/li>\n<\/ul>\n<p><strong>PASSED<\/strong>: openBrowser<\/p>\n<p><strong>FAILED<\/strong>: faceBookPageTitleVerification<\/p>\n<p><strong>FAILED<\/strong>: launchGoogle<\/p>\n<p><strong>FAILED<\/strong>: peformSeachAndClickFirstLink<\/p>\n<h3 class=\"\"><strong>Demo of TestNG code without Priority in Alphabetical Order<\/strong><\/h3>\n<p>If we do not mention any priority, testng will execute the @Test methods based on alphabetical order of their method names irrespective of their place of implementation in the code.<\/p>\n<\/div>\n<div class=\"thrv_wrapper thrv_contentbox_shortcode thrv-content-box tve-elem-default-pad\">\n<div class=\"tve-content-box-background\" style=\"background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)) !important; background-size: auto !important; background-position: 50% 50% !important; background-attachment: scroll !important; background-repeat: no-repeat !important; --background-image:linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5))  !important; --background-size:auto auto  !important; --background-position:50% 50%  !important; --background-attachment:scroll  !important; --background-repeat:no-repeat  !important;\"><\/div>\n<div class=\"tve-cb\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-1798a4a629a\" style=\"\">\n<p data-css=\"tve-u-1798a4b41d2\" style=\"\"><strong>package<\/strong> firsttestngpackage;<\/p>\n<p data-css=\"tve-u-1798a4b41d4\" style=\"\"><strong>import<\/strong> org.testng.annotations.Test;<\/p>\n<p data-css=\"tve-u-1798a4b41d6\" style=\"\"><strong>public<\/strong><br \/>\n<strong>class<\/strong> PriorityDemo {<\/p>\n<p data-css=\"tve-u-1798a4b41d7\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 @Test<\/p>\n<p data-css=\"tve-u-1798a4b41d8\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>public<\/strong><br \/>\n<strong>void<\/strong> method_c(){<\/p>\n<p data-css=\"tve-u-1798a4b41d9\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.<strong><em>out<\/em><\/strong>.println(&#8220;I&#8217;m in method C&#8221;);<\/p>\n<p data-css=\"tve-u-1798a4b41db\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/p>\n<p data-css=\"tve-u-1798a4b41dc\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 @Test<\/p>\n<p data-css=\"tve-u-1798a4b41de\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>public<\/strong><br \/>\n<strong>void<\/strong> method_b(){<\/p>\n<p data-css=\"tve-u-1798a4b41df\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.<strong><em>out<\/em><\/strong>.println(&#8220;I&#8217;m in method B&#8221;);<\/p>\n<p data-css=\"tve-u-1798a4b41e0\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/p>\n<p data-css=\"tve-u-1798a4b41e2\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 @Test<\/p>\n<p data-css=\"tve-u-1798a4b41e3\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>public<\/strong><br \/>\n<strong>void<\/strong> method_a(){<\/p>\n<p data-css=\"tve-u-1798a4b41e4\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.<strong><em>out<\/em><\/strong>.println(&#8220;I&#8217;m in method A&#8221;);<\/p>\n<p data-css=\"tve-u-1798a4b41e5\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/p>\n<p data-css=\"tve-u-1798a4b41e7\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 @Test<\/p>\n<p data-css=\"tve-u-1798a4b41e8\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>public<\/strong><br \/>\n<strong>void<\/strong> method_e(){<\/p>\n<p data-css=\"tve-u-1798a4b41e9\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.<strong><em>out<\/em><\/strong>.println(&#8220;I&#8217;m in method E&#8221;);<\/p>\n<p data-css=\"tve-u-1798a4b41ea\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/p>\n<p data-css=\"tve-u-1798a4b41ec\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 @Test<\/p>\n<p data-css=\"tve-u-1798a4b41ed\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>public<\/strong><br \/>\n<strong>void<\/strong> method_d(){<\/p>\n<p data-css=\"tve-u-1798a4b41ee\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.<strong><em>out<\/em><\/strong>.println(&#8220;I&#8217;m in method D&#8221;);<\/p>\n<p data-css=\"tve-u-1798a4b41ef\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/p>\n<p data-css=\"tve-u-1798a4b41f1\" style=\"\">}<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<h5 class=\"\">Output of code<\/h5>\n<p>[RemoteTestNG] detected TestNG version 7.3.0<\/p>\n<p>I&#8217;m in method A<\/p>\n<p>I&#8217;m in method B<\/p>\n<p>I&#8217;m in method C<\/p>\n<p>I&#8217;m in method D<\/p>\n<p>I&#8217;m in method E<\/p>\n<p><strong>PASSED<\/strong>: method_a<\/p>\n<p><strong>PASSED<\/strong>: method_b<\/p>\n<p><strong>PASSED<\/strong>: method_c<\/p>\n<p><strong>PASSED<\/strong>: method_d<\/p>\n<p><strong>PASSED<\/strong>: method_e<\/p>\n<p>Though we defined the methods in a random manner (c, b, a, e, d), testng executed the methods based on their method names by considering alphabetical order and the same was reflected in the output as well.<\/p>\n<h3 class=\"\"><strong>How to set Priority in TestNG<\/strong><\/h3>\n<p>As you have seen in the previous example that sequencing required in order to pass this scenario, so we will be modifying the previous piece of code with <strong>Priority Parameter<\/strong> so that each test should run against to the priority assigned to them.<\/p>\n<p>Now as you can see we have assigned the Priority to each test case means test case will the lower priority value will be executed first.<\/p>\n<\/div>\n<div class=\"thrv_wrapper thrv_contentbox_shortcode thrv-content-box tve-elem-default-pad\">\n<div class=\"tve-content-box-background\" style=\"background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)) !important; background-size: auto !important; background-position: 50% 50% !important; background-attachment: scroll !important; background-repeat: no-repeat !important; --background-image:linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5))  !important; --background-size:auto auto  !important; --background-position:50% 50%  !important; --background-attachment:scroll  !important; --background-repeat:no-repeat  !important;\"><\/div>\n<div class=\"tve-cb\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-1798a4c4cf6\" style=\"\">\n<p data-css=\"tve-u-1798a4cb2ab\" style=\"\"><strong>package<\/strong> firsttestngpackage;<\/p>\n<p data-css=\"tve-u-1798a4cb2ad\" style=\"\"><strong>import<\/strong> org.testng.annotations.Test;<\/p>\n<p data-css=\"tve-u-1798a4cb2af\" style=\"\"><strong>public<\/strong><br \/>\n<strong>class<\/strong> PriorityDemo {<\/p>\n<p data-css=\"tve-u-1798a4cb2b0\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 @Test(priority = 0)<\/p>\n<p data-css=\"tve-u-1798a4cb2b1\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>public<\/strong><br \/>\n<strong>void<\/strong> method_c(){<\/p>\n<p data-css=\"tve-u-1798a4cb2b3\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.<strong><em>out<\/em><\/strong>.println(&#8220;I&#8217;m in method C&#8221;);<\/p>\n<p data-css=\"tve-u-1798a4cb2b4\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/p>\n<p data-css=\"tve-u-1798a4cb2b5\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 @Test(priority = 3)<\/p>\n<p data-css=\"tve-u-1798a4cb2b6\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>public<\/strong><br \/>\n<strong>void<\/strong> method_b(){<\/p>\n<p data-css=\"tve-u-1798a4cb2b8\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.<strong><em>out<\/em><\/strong>.println(&#8220;I&#8217;m in method B&#8221;);<\/p>\n<p data-css=\"tve-u-1798a4cb2b9\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/p>\n<p data-css=\"tve-u-1798a4cb2ba\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 @Test(priority = 2)<\/p>\n<p data-css=\"tve-u-1798a4cb2bb\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>public<\/strong><br \/>\n<strong>void<\/strong> method_a(){<\/p>\n<p data-css=\"tve-u-1798a4cb2bd\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.<strong><em>out<\/em><\/strong>.println(&#8220;I&#8217;m in method A&#8221;);<\/p>\n<p data-css=\"tve-u-1798a4cb2be\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/p>\n<p data-css=\"tve-u-1798a4cb2bf\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 @Test(priority = 1)<\/p>\n<p data-css=\"tve-u-1798a4cb2c0\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>public<\/strong><br \/>\n<strong>void<\/strong> method_e(){<\/p>\n<p data-css=\"tve-u-1798a4cb2c2\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.<strong><em>out<\/em><\/strong>.println(&#8220;I&#8217;m in method E&#8221;);<\/p>\n<p data-css=\"tve-u-1798a4cb2c3\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/p>\n<p data-css=\"tve-u-1798a4cb2c4\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 @Test(priority = 4)<\/p>\n<p data-css=\"tve-u-1798a4cb2c5\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>public<\/strong><br \/>\n<strong>void<\/strong> method_d(){<\/p>\n<p data-css=\"tve-u-1798a4cb2c7\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.<strong><em>out<\/em><\/strong>.println(&#8220;I&#8217;m in method D&#8221;);<\/p>\n<p data-css=\"tve-u-1798a4cb2c8\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/p>\n<p data-css=\"tve-u-1798a4cb2c9\" style=\"\">}<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<h5 class=\"\">Output of code<\/h5>\n<p>[RemoteTestNG] detected TestNG version 7.3.0<\/p>\n<p>I&#8217;m in method C<\/p>\n<p>I&#8217;m in method E<\/p>\n<p>I&#8217;m in method A<\/p>\n<p>I&#8217;m in method B<\/p>\n<p>I&#8217;m in method D<\/p>\n<p><strong>PASSED<\/strong>: method_c<\/p>\n<p><strong>PASSED<\/strong>: method_e<\/p>\n<p><strong>PASSED<\/strong>: method_a<\/p>\n<p><strong>PASSED<\/strong>: method_b<\/p>\n<p><strong>PASSED<\/strong>: method_d<\/p>\n<h3 class=\"\"><strong>Methods with Same Priority<\/strong><\/h3>\n<p>There may be a chance that methods may contain same priority. In those cases, testng considers the alphabetical order of the method names whose priority is same.<\/p>\n<\/div>\n<div class=\"thrv_wrapper thrv_contentbox_shortcode thrv-content-box tve-elem-default-pad\">\n<div class=\"tve-content-box-background\" style=\"background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)) !important; background-size: auto !important; background-position: 50% 50% !important; background-attachment: scroll !important; background-repeat: no-repeat !important; --background-image:linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5))  !important; --background-size:auto auto  !important; --background-position:50% 50%  !important; --background-attachment:scroll  !important; --background-repeat:no-repeat  !important;\"><\/div>\n<div class=\"tve-cb\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-1798a4dd832\" style=\"\">\n<p data-css=\"tve-u-1798a4e04e6\" style=\"\"><strong>package<\/strong> firsttestngpackage;<\/p>\n<p data-css=\"tve-u-1798a4e04e9\" style=\"\"><strong>import<\/strong> org.testng.annotations.Test;<\/p>\n<p data-css=\"tve-u-1798a4e04ea\" style=\"\"><strong>public<\/strong><br \/>\n<strong>class<\/strong> PriorityDemo {<\/p>\n<p data-css=\"tve-u-1798a4e04eb\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 @Test(priority = 0)<\/p>\n<p data-css=\"tve-u-1798a4e04ed\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>public<\/strong><br \/>\n<strong>void<\/strong> method_c(){<\/p>\n<p data-css=\"tve-u-1798a4e04ee\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.<strong><em>out<\/em><\/strong>.println(&#8220;I&#8217;m in method C&#8221;);<\/p>\n<p data-css=\"tve-u-1798a4e04ef\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/p>\n<p data-css=\"tve-u-1798a4e04f1\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 @Test(priority = 3)<\/p>\n<p data-css=\"tve-u-1798a4e04f2\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>public<\/strong><br \/>\n<strong>void<\/strong> method_b(){<\/p>\n<p data-css=\"tve-u-1798a4e04f3\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.<strong><em>out<\/em><\/strong>.println(&#8220;I&#8217;m in method B&#8221;);<\/p>\n<p data-css=\"tve-u-1798a4e04f4\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/p>\n<p data-css=\"tve-u-1798a4e04f6\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 @Test(priority = 2)<\/p>\n<p data-css=\"tve-u-1798a4e04f7\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>public<\/strong><br \/>\n<strong>void<\/strong> method_a(){<\/p>\n<p data-css=\"tve-u-1798a4e04f8\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.<strong><em>out<\/em><\/strong>.println(&#8220;I&#8217;m in method A&#8221;);<\/p>\n<p data-css=\"tve-u-1798a4e04fa\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/p>\n<p data-css=\"tve-u-1798a4e04fb\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 @Test(priority = 1)<\/p>\n<p data-css=\"tve-u-1798a4e04fc\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>public<\/strong><br \/>\n<strong>void<\/strong> method_e(){<\/p>\n<p data-css=\"tve-u-1798a4e04fe\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.<strong><em>out<\/em><\/strong>.println(&#8220;I&#8217;m in method E&#8221;);<\/p>\n<p data-css=\"tve-u-1798a4e04ff\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/p>\n<p data-css=\"tve-u-1798a4e0500\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 @Test(priority = 2)<\/p>\n<p data-css=\"tve-u-1798a4e0501\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>public<\/strong><br \/>\n<strong>void<\/strong> method_d(){<\/p>\n<p data-css=\"tve-u-1798a4e0503\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.<strong><em>out<\/em><\/strong>.println(&#8220;I&#8217;m in method D&#8221;);<\/p>\n<p data-css=\"tve-u-1798a4e0504\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/p>\n<p data-css=\"tve-u-1798a4e0505\" style=\"\">}<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<h5>Output of code<\/h5>\n<p>[RemoteTestNG] detected TestNG version 7.3.0<\/p>\n<p>I&#8217;m in method C<\/p>\n<p>I&#8217;m in method E<\/p>\n<p>I&#8217;m in method A<\/p>\n<p>I&#8217;m in method D<\/p>\n<p>I&#8217;m in method B<\/p>\n<p><strong>PASSED<\/strong>: method_c<\/p>\n<p><strong>PASSED<\/strong>: method_e<\/p>\n<p><strong>PASSED<\/strong>: method_a<\/p>\n<p><strong>PASSED<\/strong>: method_d<\/p>\n<p><strong>PASSED<\/strong>: method_b<\/p>\n<h3 class=\"\"><strong>Combining both prioritized(having same priority) and non-prioritized methods<\/strong><\/h3>\n<p>In this case, we will cover two cases in one testng class.<\/p>\n<ol start=\"1\" type=\"1\">\n<li>Methods having same priority value.<\/li>\n<li>More than one non-prioritized methods.<\/li>\n<\/ol>\n<\/div>\n<div class=\"thrv_wrapper thrv_contentbox_shortcode thrv-content-box tve-elem-default-pad\">\n<div class=\"tve-content-box-background\" style=\"background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)) !important; background-size: auto !important; background-position: 50% 50% !important; background-attachment: scroll !important; background-repeat: no-repeat !important; --background-image:linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5))  !important; --background-size:auto auto  !important; --background-position:50% 50%  !important; --background-attachment:scroll  !important; --background-repeat:no-repeat  !important;\"><\/div>\n<div class=\"tve-cb\">\n<div class=\"thrv_wrapper thrv_text_element\" data-css=\"tve-u-1798a4f2414\" style=\"\">\n<p data-css=\"tve-u-1798a4f588f\" style=\"\"><strong>package<\/strong> firsttestngpackage;<\/p>\n<p data-css=\"tve-u-1798a4f5891\" style=\"\"><strong>import<\/strong> org.testng.annotations.Test;<\/p>\n<p data-css=\"tve-u-1798a4f5893\" style=\"\"><strong>public<\/strong><br \/>\n<strong>class<\/strong> PriorityDemo {<\/p>\n<p data-css=\"tve-u-1798a4f5894\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 @Test<\/p>\n<p data-css=\"tve-u-1798a4f5895\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>public<\/strong><br \/>\n<strong>void<\/strong> method_c(){<\/p>\n<p data-css=\"tve-u-1798a4f5897\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.<strong><em>out<\/em><\/strong>.println(&#8220;I&#8217;m in method C&#8221;);<\/p>\n<p data-css=\"tve-u-1798a4f5899\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/p>\n<p data-css=\"tve-u-1798a4f589a\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 @Test(priority = 3)<\/p>\n<p data-css=\"tve-u-1798a4f589b\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>public<\/strong><br \/>\n<strong>void<\/strong> method_b(){<\/p>\n<p data-css=\"tve-u-1798a4f589d\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.<strong><em>out<\/em><\/strong>.println(&#8220;I&#8217;m in method B&#8221;);<\/p>\n<p data-css=\"tve-u-1798a4f589e\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/p>\n<p data-css=\"tve-u-1798a4f589f\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 @Test<\/p>\n<p data-css=\"tve-u-1798a4f58a0\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>public<\/strong><br \/>\n<strong>void<\/strong> method_a(){<\/p>\n<p data-css=\"tve-u-1798a4f58a2\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.<strong><em>out<\/em><\/strong>.println(&#8220;I&#8217;m in method A&#8221;);<\/p>\n<p data-css=\"tve-u-1798a4f58a3\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/p>\n<p data-css=\"tve-u-1798a4f58a4\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 @Test(priority = 1)<\/p>\n<p data-css=\"tve-u-1798a4f58a5\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>public<\/strong><br \/>\n<strong>void<\/strong> method_e(){<\/p>\n<p data-css=\"tve-u-1798a4f58a7\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.<strong><em>out<\/em><\/strong>.println(&#8220;I&#8217;m in method E&#8221;);<\/p>\n<p data-css=\"tve-u-1798a4f58a8\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/p>\n<p data-css=\"tve-u-1798a4f58a9\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 @Test(priority = 1)<\/p>\n<p data-css=\"tve-u-1798a4f58ab\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <strong>public<\/strong><br \/>\n<strong>void<\/strong> method_d(){<\/p>\n<p data-css=\"tve-u-1798a4f58ac\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.<strong><em>out<\/em><\/strong>.println(&#8220;I&#8217;m in method D&#8221;);<\/p>\n<p data-css=\"tve-u-1798a4f58ad\" style=\"\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/p>\n<p data-css=\"tve-u-1798a4f58ae\" style=\"\">}<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"thrv_wrapper thrv_text_element\">\n<h5 class=\"\">Output of Code<\/h5>\n<p>[RemoteTestNG] detected TestNG version 7.3.0<\/p>\n<p>I&#8217;m in method A<\/p>\n<p>I&#8217;m in method C<\/p>\n<p>I&#8217;m in method D<\/p>\n<p>I&#8217;m in method E<\/p>\n<p>I&#8217;m in method B<\/p>\n<p><strong>PASSED<\/strong>: method_a<\/p>\n<p><strong>PASSED<\/strong>: method_c<\/p>\n<p><strong>PASSED<\/strong>: method_d<\/p>\n<p><strong>PASSED<\/strong>: method_e<\/p>\n<p><strong>PASSED<\/strong>: method_b<\/p>\n<p><strong>First preference: <\/strong>Non-prioritized methods: \u2018c\u2019 and \u2018a\u2019: Based on alphabetical order \u2018a\u2019 was executed first and then \u2018c\u2019.<\/p>\n<p><strong>Second preference: <\/strong>Prioritized methods: \u2018b\u2019, \u2018e\u2019 and \u2018d\u2019, d and e have same priority so they will be executed based on alphabet and later b will be executed.<\/p>\n<h3 class=\"\"><strong>Case-sensitive in TestNG<\/strong><\/h3>\n<p>Just for your information there is a standard syntax for defining priority in testNG i.e. <strong>@Test (priority=4)<\/strong>,<strong> <\/strong>suppose you are defining it in some other syntax say<strong> @Test (PRIORITY=1) <\/strong>then your IDE will show it as a compilation error<\/p>\n<h3 class=\"\"><strong>Conclusion<\/strong><\/h3>\n<p>As you have seen that if there is a requirement to run a set of test-case in specific sequence then it can be easily done using <strong>Priority<\/strong> using testNG as a run tool.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"tcb_flag\" style=\"display: none\"><\/div>\n<p><!-- AI CONTENT END 1 --><br \/>\n<\/section>\n<p><\/body><\/html><\/p>\n","protected":false},"excerpt":{"rendered":"<p>TestNG is a Testing framework, that covers different types of test designs like a unit test, functional test, end to end test, UI test and integration test. You can run a single or multiple test cases in your Testng code. If test priority is not defined while, running multiple test cases, TestNG assigns all @Test [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,3],"tags":[],"class_list":["post-393","post","type-post","status-publish","format-standard","hentry","category-selenium","category-testng","post-wrapper","thrv_wrapper"],"_links":{"self":[{"href":"https:\/\/rahulshettyacademy.com\/blog\/wp-json\/wp\/v2\/posts\/393","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rahulshettyacademy.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rahulshettyacademy.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/wp-json\/wp\/v2\/comments?post=393"}],"version-history":[{"count":0,"href":"https:\/\/rahulshettyacademy.com\/blog\/wp-json\/wp\/v2\/posts\/393\/revisions"}],"wp:attachment":[{"href":"https:\/\/rahulshettyacademy.com\/blog\/wp-json\/wp\/v2\/media?parent=393"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/wp-json\/wp\/v2\/categories?post=393"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/wp-json\/wp\/v2\/tags?post=393"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}