{"id":4817,"date":"2021-08-16T04:04:16","date_gmt":"2021-08-16T04:04:16","guid":{"rendered":"https:\/\/studysection.com\/blog\/?p=4817"},"modified":"2021-08-16T04:52:54","modified_gmt":"2021-08-16T04:52:54","slug":"dependency-in-testng","status":"publish","type":"post","link":"https:\/\/studysection.com\/blog\/dependency-in-testng\/","title":{"rendered":"Dependency In TestNG"},"content":{"rendered":"<p>Test dependency is one of the beneficial features of the TestNG framework that allows us to make one test method dependent on one or multiple other test methods. Tests dependency only works if the dependent method is part of the same class or any of the inherited base classes.<\/p>\n<h2>TestNG allows you to specify dependencies in the following ways:<\/h2>\n<ol>\n<li>Using attribute dependsOnMethods in @Test annotations.<\/li>\n<li>Using attribute dependsOnGroups in @Test annotations.<\/li>\n<\/ol>\n<h3>Some points to remember about depends on the method:<\/h3>\n<ol>\n<li>On an execution test <a href=\"https:\/\/studysection.com\/blog\/class-composition-in-python\/\">class<\/a> or test suite, the parent test method will run before the dependent test.<\/li>\n<li>If we run the dependent test only even then the parent test method will run before the dependent test.<\/li>\n<li>If the parent test method gets failed then the dependent test method will not run and will be marked as skipped.<\/li>\n<\/ol>\n<h3>Here we are taking an example:<\/h3>\n<p>Firstly, a user login into the application and get the title of the homepage. Then we assert the home page title with the expected homepage title.<\/p>\n<p><strong>Code:<\/strong><br \/>\n<code>package Practise;<br \/>\nimport org.openqa.selenium.By;<br \/>\nimport org.openqa.selenium.PageLoadStrategy;<br \/>\nimport org.openqa.selenium.WebDriver;<br \/>\nimport org.openqa.selenium.chrome.ChromeDriver;<br \/>\nimport org.openqa.selenium.chrome.ChromeOptions;<br \/>\nimport org.testng.Assert;<br \/>\nimport org.testng.annotations.Test;<br \/>\nimport io.github.bonigarcia.wdm.WebDriverManager;<br \/>\npublic class dependencyTesting {<br \/>\n\tpublic WebDriver driver;<br \/>\n\t@Test (priority=1)<br \/>\n    public void openBrowser() throws InterruptedException {<br \/>\n\tWebDriverManager.chromedriver().setup();<br \/>\n\tChromeOptions options = new ChromeOptions();<br \/>\n\t \/\/ Open browser window in maximize mode<br \/>\n\toptions.addArguments(\"--start-maximized\");<br \/>\n\t \/\/ Add page load strategy<br \/>\n\toptions.setPageLoadStrategy(PageLoadStrategy.EAGER);<br \/>\n\tdriver = new ChromeDriver(options);<br \/>\n      driver.get(\"https:\/\/www.studysection.com\");<br \/>\n      Thread.sleep(3000);<br \/>\n     }<br \/>\n\t@Test(priority=2)<br \/>\n\tpublic void loginPage() throws InterruptedException {<br \/>\n\tdriver.get(\"https:\/\/www.studysection.com\/users\/login\");<br \/>\n     driver.findElement(By.id(\"UserEmail\")).sendKeys(\"email\");<br \/>\n\tdriver.findElement(By.id(\"UserPassword\")).sendKeys(\"password\");<br \/>\ndriver.findElement(By.xpath(\"\/\/*[@id=\\\"User\/loginForm\\\"]\/div[4]\/div\")).click();<br \/>\n\t String actualTitle  =  driver.getTitle();<br \/>\n\t System.out.println(actualTitle);<br \/>\n\t}<br \/>\n\t@Test(dependsOnMethods = {\"loginPage\"})<br \/>\n\tpublic void Homepage() {<br \/>\n        String expectedTitle = \"Your Attempts and Certificates\";<br \/>\n        String actualTitle = driver.getTitle();<br \/>\n        Assert.assertEquals(actualTitle, expectedTitle);<br \/>\n\t}<br \/>\n}<\/code><\/p>\n<p><strong>Result:<\/strong><br \/>\n<img decoding=\"async\" src=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/08\/output-certi.png\" \/><br \/>\nIn this example, If a user login credential is not matched with the system then the Login page method will not execute and the dependent Homepage method will also not execute.<\/p>\n<p><small><em>English is a commonly used language in almost all fields today. Having a certification in the English language can enhance your career aspects. StudySection offers both basic level and advanced level <a href=\"https:\/\/www.studysection.com\/english-language-advanced-diploma\">English Certification Exams<\/a> to test and certify the English language skills.<\/em><\/small><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Test dependency is one of the beneficial features of the TestNG framework that allows us to make one test method<\/p>\n","protected":false},"author":1,"featured_media":4818,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[693],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Dependency In TestNG Framework - StudySection Blog<\/title>\n<meta name=\"description\" content=\"Test dependency is one of the beneficial features of TestNG framework that allows us to make one test method dependent on other test methods.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/studysection.com\/blog\/dependency-in-testng\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Dependency In TestNG Framework - StudySection Blog\" \/>\n<meta property=\"og:description\" content=\"Test dependency is one of the beneficial features of TestNG framework that allows us to make one test method dependent on other test methods.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/studysection.com\/blog\/dependency-in-testng\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog Posts on famous people, innovations and educational topics\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/studysection\" \/>\n<meta property=\"article:published_time\" content=\"2021-08-16T04:04:16+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-08-16T04:52:54+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/08\/TestNG.png\" \/>\n\t<meta property=\"og:image:width\" content=\"300\" \/>\n\t<meta property=\"og:image:height\" content=\"200\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"admin-studysection-blog\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@studysection\" \/>\n<meta name=\"twitter:site\" content=\"@studysection\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin-studysection-blog\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/studysection.com\/blog\/dependency-in-testng\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/studysection.com\/blog\/dependency-in-testng\/\"},\"author\":{\"name\":\"admin-studysection-blog\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402\"},\"headline\":\"Dependency In TestNG\",\"datePublished\":\"2021-08-16T04:04:16+00:00\",\"dateModified\":\"2021-08-16T04:52:54+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/studysection.com\/blog\/dependency-in-testng\/\"},\"wordCount\":248,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/studysection.com\/blog\/#organization\"},\"keywords\":[\"TestNG\"],\"articleSection\":[\"Learn and Grow\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/studysection.com\/blog\/dependency-in-testng\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/studysection.com\/blog\/dependency-in-testng\/\",\"url\":\"https:\/\/studysection.com\/blog\/dependency-in-testng\/\",\"name\":\"Dependency In TestNG Framework - StudySection Blog\",\"isPartOf\":{\"@id\":\"https:\/\/studysection.com\/blog\/#website\"},\"datePublished\":\"2021-08-16T04:04:16+00:00\",\"dateModified\":\"2021-08-16T04:52:54+00:00\",\"description\":\"Test dependency is one of the beneficial features of TestNG framework that allows us to make one test method dependent on other test methods.\",\"breadcrumb\":{\"@id\":\"https:\/\/studysection.com\/blog\/dependency-in-testng\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/studysection.com\/blog\/dependency-in-testng\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/studysection.com\/blog\/dependency-in-testng\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/studysection.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Dependency In TestNG\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/studysection.com\/blog\/#website\",\"url\":\"https:\/\/studysection.com\/blog\/\",\"name\":\"Blog Posts on famous people, innovations and educational topics\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/studysection.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/studysection.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/studysection.com\/blog\/#organization\",\"name\":\"StudySection\",\"url\":\"https:\/\/studysection.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png\",\"contentUrl\":\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png\",\"width\":920,\"height\":440,\"caption\":\"StudySection\"},\"image\":{\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/studysection\",\"https:\/\/twitter.com\/studysection\",\"https:\/\/www.instagram.com\/study.section\/\",\"https:\/\/www.linkedin.com\/company\/studysection\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402\",\"name\":\"admin-studysection-blog\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g\",\"caption\":\"admin-studysection-blog\"},\"url\":\"https:\/\/studysection.com\/blog\/author\/admin-studysection-blog\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Dependency In TestNG Framework - StudySection Blog","description":"Test dependency is one of the beneficial features of TestNG framework that allows us to make one test method dependent on other test methods.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/studysection.com\/blog\/dependency-in-testng\/","og_locale":"en_US","og_type":"article","og_title":"Dependency In TestNG Framework - StudySection Blog","og_description":"Test dependency is one of the beneficial features of TestNG framework that allows us to make one test method dependent on other test methods.","og_url":"https:\/\/studysection.com\/blog\/dependency-in-testng\/","og_site_name":"Blog Posts on famous people, innovations and educational topics","article_publisher":"https:\/\/www.facebook.com\/studysection","article_published_time":"2021-08-16T04:04:16+00:00","article_modified_time":"2021-08-16T04:52:54+00:00","og_image":[{"width":300,"height":200,"url":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/08\/TestNG.png","type":"image\/png"}],"author":"admin-studysection-blog","twitter_card":"summary_large_image","twitter_creator":"@studysection","twitter_site":"@studysection","twitter_misc":{"Written by":"admin-studysection-blog","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/studysection.com\/blog\/dependency-in-testng\/#article","isPartOf":{"@id":"https:\/\/studysection.com\/blog\/dependency-in-testng\/"},"author":{"name":"admin-studysection-blog","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402"},"headline":"Dependency In TestNG","datePublished":"2021-08-16T04:04:16+00:00","dateModified":"2021-08-16T04:52:54+00:00","mainEntityOfPage":{"@id":"https:\/\/studysection.com\/blog\/dependency-in-testng\/"},"wordCount":248,"commentCount":0,"publisher":{"@id":"https:\/\/studysection.com\/blog\/#organization"},"keywords":["TestNG"],"articleSection":["Learn and Grow"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/studysection.com\/blog\/dependency-in-testng\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/studysection.com\/blog\/dependency-in-testng\/","url":"https:\/\/studysection.com\/blog\/dependency-in-testng\/","name":"Dependency In TestNG Framework - StudySection Blog","isPartOf":{"@id":"https:\/\/studysection.com\/blog\/#website"},"datePublished":"2021-08-16T04:04:16+00:00","dateModified":"2021-08-16T04:52:54+00:00","description":"Test dependency is one of the beneficial features of TestNG framework that allows us to make one test method dependent on other test methods.","breadcrumb":{"@id":"https:\/\/studysection.com\/blog\/dependency-in-testng\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/studysection.com\/blog\/dependency-in-testng\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/studysection.com\/blog\/dependency-in-testng\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/studysection.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Dependency In TestNG"}]},{"@type":"WebSite","@id":"https:\/\/studysection.com\/blog\/#website","url":"https:\/\/studysection.com\/blog\/","name":"Blog Posts on famous people, innovations and educational topics","description":"","publisher":{"@id":"https:\/\/studysection.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/studysection.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/studysection.com\/blog\/#organization","name":"StudySection","url":"https:\/\/studysection.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png","contentUrl":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png","width":920,"height":440,"caption":"StudySection"},"image":{"@id":"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/studysection","https:\/\/twitter.com\/studysection","https:\/\/www.instagram.com\/study.section\/","https:\/\/www.linkedin.com\/company\/studysection"]},{"@type":"Person","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402","name":"admin-studysection-blog","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g","caption":"admin-studysection-blog"},"url":"https:\/\/studysection.com\/blog\/author\/admin-studysection-blog\/"}]}},"views":399,"_links":{"self":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/4817"}],"collection":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/comments?post=4817"}],"version-history":[{"count":4,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/4817\/revisions"}],"predecessor-version":[{"id":4823,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/4817\/revisions\/4823"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/media\/4818"}],"wp:attachment":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/media?parent=4817"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/categories?post=4817"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/tags?post=4817"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}