{"id":4771,"date":"2017-10-11T12:50:37","date_gmt":"2017-10-11T12:50:37","guid":{"rendered":"https:\/\/www.testingdocs.com\/questions\/?p=4771"},"modified":"2024-09-04T06:59:49","modified_gmt":"2024-09-04T06:59:49","slug":"how-to-configure-testng-in-selenium-java-project","status":"publish","type":"post","link":"https:\/\/www.testingdocs.com\/questions\/how-to-configure-testng-in-selenium-java-project\/","title":{"rendered":"How to Configure TestNG in Selenium Java Project"},"content":{"rendered":"<h2>How to Configure TestNG in Selenium Java Project<\/h2>\n<p>In this tutorial, we will configure TestNG in Selenium Java Project. If TestNG is not configured in the project, we get errors in the Test classes. Import statements that use @Test annotations, Assert would result in Errors.<\/p>\n<p>Steps for the TestNG configuration to the Selenium project depends on how the project is built. This article covers the steps if the Selenium project is built with Maven build tool.<\/p>\n<p>Errors in the Project.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4773\" src=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/TestNG-Configuration-in-Selenium-Project.png\" alt=\"TestNG Configuration in Selenium Project\" width=\"1909\" height=\"986\" title=\"\" srcset=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/TestNG-Configuration-in-Selenium-Project.png 1909w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/TestNG-Configuration-in-Selenium-Project-300x155.png 300w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/TestNG-Configuration-in-Selenium-Project-1024x529.png 1024w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/TestNG-Configuration-in-Selenium-Project-768x397.png 768w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/TestNG-Configuration-in-Selenium-Project-1536x793.png 1536w\" sizes=\"auto, (max-width: 1909px) 100vw, 1909px\" \/><\/p>\n<h3><\/h3>\n<h3>TestNG Configuration<\/h3>\n<p>Add the TestNG dependency to the project <strong>pom.xml<\/strong> file.<\/p>\n<pre>&lt;dependency&gt; \r\n    &lt;groupId&gt;org.testng&lt;\/groupId&gt; \r\n    &lt;artifactId&gt;testng&lt;\/artifactId&gt; \r\n    &lt;version&gt;6.14.3&lt;\/version&gt; \r\n    &lt;scope&gt;test&lt;\/scope&gt; \r\n&lt;\/dependency&gt;\r\n\r\n<\/pre>\n<p>Note that always add the latest version of the TestNG.<\/p>\n<ul>\n<li>Launch the IDE and open the project.<\/li>\n<li>Open the pom.xml file.<\/li>\n<li>Add the TestNG dependency with the latest version.<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4774\" src=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/TestNG-Maven-dependency.png\" alt=\"TestNG Maven dependency\" width=\"1902\" height=\"989\" title=\"\" srcset=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/TestNG-Maven-dependency.png 1902w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/TestNG-Maven-dependency-300x156.png 300w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/TestNG-Maven-dependency-1024x532.png 1024w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/TestNG-Maven-dependency-768x399.png 768w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/TestNG-Maven-dependency-1536x799.png 1536w\" sizes=\"auto, (max-width: 1902px) 100vw, 1902px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h3>Sample Test<\/h3>\n<pre>package com.testingdocs.Sample;\r\n\r\nimport java.util.concurrent.TimeUnit;\r\nimport org.openqa.selenium.WebDriver;\r\nimport org.openqa.selenium.opera.OperaDriver;\r\nimport org.testng.Assert;\r\nimport org.testng.annotations.AfterClass;\r\nimport org.testng.annotations.BeforeClass;\r\nimport org.testng.annotations.Test;\r\n\r\npublic class SeleniumTest {\r\n\r\n    private WebDriver driver;\r\n\r\n    @Test\r\n    public void sampleTest() {\r\n        driver.get(\"https:\/\/www.google.com\");\r\n        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);\r\n        Assert.assertEquals(driver.getTitle(), \"Google\", \"Verify title test\");\r\n    }\r\n\r\n    @BeforeClass\r\n    public void beforeClass() {\r\n        System.setProperty(\"webdriver.opera.driver\", \"operadriver.exe\");\r\n        driver = new OperaDriver();\r\n    }\r\n\r\n    @AfterClass\r\n    public void afterClass() {\r\n        if(driver != null)\r\n        {\r\n            driver.quit();\r\n        }\r\n    }\r\n}\r\n\r\n<\/pre>\n<pre><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4772\" src=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/No-TestNG-Errors-in-the-Project.png\" alt=\"No TestNG Errors in the Project\" width=\"1910\" height=\"1002\" title=\"\" srcset=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/No-TestNG-Errors-in-the-Project.png 1910w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/No-TestNG-Errors-in-the-Project-300x157.png 300w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/No-TestNG-Errors-in-the-Project-1024x537.png 1024w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/No-TestNG-Errors-in-the-Project-768x403.png 768w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/No-TestNG-Errors-in-the-Project-1536x806.png 1536w\" sizes=\"auto, (max-width: 1910px) 100vw, 1910px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>Notice that after configuring the TestNG in the project pom file, project errors related to TestNG are gone.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to Configure TestNG in Selenium Java Project In this tutorial, we will configure TestNG in Selenium Java Project. If TestNG is not configured in the project, we get errors in the Test classes. Import statements that use @Test annotations, Assert would result in Errors. Steps for the TestNG configuration to the Selenium project depends [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[185],"tags":[215],"class_list":["post-4771","post","type-post","status-publish","format-standard","hentry","category-selenium","tag-testng-questions","has-post-title","has-post-date","has-post-category","has-post-tag","has-post-comment","has-post-author",""],"_links":{"self":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/4771","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/comments?post=4771"}],"version-history":[{"count":6,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/4771\/revisions"}],"predecessor-version":[{"id":24013,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/4771\/revisions\/24013"}],"wp:attachment":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/media?parent=4771"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/categories?post=4771"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/tags?post=4771"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}