

{"id":114057,"date":"2023-05-08T09:00:16","date_gmt":"2023-05-08T03:30:16","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=114057"},"modified":"2023-05-12T11:43:02","modified_gmt":"2023-05-12T06:13:02","slug":"maven-for-selenium","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/maven-for-selenium\/","title":{"rendered":"Maven for Selenium"},"content":{"rendered":"<p>Popular open-source software called Selenium is used to automate web browsers. It allows testers and developers to automate web-based applications to perform functional testing. One of the popular build tools for Selenium automation is Maven. Selenium projects can be managed and built using Maven, a potent build automation tool.<\/p>\n<p>In this tutorial, we will cover a Selenium Maven tutorial, which will provide a step-by-step guide on how to set up Selenium projects using Maven.<\/p>\n<h3>Prerequisites for<\/h3>\n<p>The following criteria should be met before beginning this tutorial:<\/p>\n<ul>\n<li>Java Development Kit (JDK) installed<\/li>\n<li>Maven installed<\/li>\n<li>Selenium WebDriver Java client library installed<\/li>\n<\/ul>\n<h3>Setting up a Maven Project for Selenium<\/h3>\n<p>Follow the below steps to set up a Maven project for Selenium:<\/p>\n<p>1. Open a terminal or command prompt and navigate to the directory where you want to create the Maven project.<\/p>\n<p>2. Type the following command to create a new Maven project:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">\u2018mvn archetype:generate -DgroupId=com.example.selenium -DartifactId=selenium-maven-tutorial -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false\u2019\r\n<\/pre>\n<p>The above command creates a new Maven project with the group ID com.example.selenium and the artifact ID selenium-maven-tutorial.<\/p>\n<p>3. Use the following command to navigate to the newly formed project directory:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">cd selenium-maven-tutorial\r\n<\/pre>\n<p>4. Open the pom.xml file located in the project&#8217;s root directory in a text editor. Add the following dependencies to the pom.xml file:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;dependencies&gt;\r\n   &lt;dependency&gt;\r\n       &lt;groupId&gt;org.seleniumhq.selenium&lt;\/groupId&gt;\r\n       &lt;artifactId&gt;selenium-java&lt;\/artifactId&gt;\r\n       &lt;version&gt;3.141.59&lt;\/version&gt;\r\n   &lt;\/dependency&gt;\r\n&lt;\/dependencies&gt;\r\n<\/pre>\n<p>The above dependencies are required to use Selenium in our Maven project.<\/p>\n<p>5. Save the pom.xml file and close it.<\/p>\n<h3>Writing a Selenium Test<\/h3>\n<p>Now that we have set up a Maven project for Selenium, we can create a Selenium test.<\/p>\n<p>1. The code below will create a new Java class in the src\/main\/java directory:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">package com.example.selenium;\r\n\r\n\r\nimport org.openqa.selenium.WebDriver;\r\nimport org.openqa.selenium.chrome.ChromeDriver;\r\nimport org.testng.annotations.Test;\r\n\r\n\r\npublic class SeleniumTest {\r\n\r\n\r\n   @Test\r\n   public void test() {\r\n       System.setProperty(\"webdriver.chrome.driver\", \"path\/to\/chromedriver\");\r\n\r\n\r\n       WebDriver driver = new ChromeDriver();\r\n\r\n\r\n       driver.get(\"https:\/\/www.google.com\");\r\n\r\n\r\n       if (driver.getTitle().contains(\"Google\")) {\r\n           System.out.println(\"Test Passed!\");\r\n       } else {\r\n           System.out.println(\"Test Failed\");\r\n       }\r\n\r\n\r\n       driver.quit();\r\n   }\r\n}\r\n<\/pre>\n<p>The above code opens a Chrome browser window, navigates to the Google homepage. It then verifies that the title of the page contains the word &#8220;Google&#8221;, and then closes the browser window.<\/p>\n<p>2. Save the Java class with the name SeleniumTest.java.<\/p>\n<h3>Running the Selenium Test<\/h3>\n<p>To run the Selenium test, we can use the following command:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">mvn test<\/pre>\n<p>The above command will execute the test() method in the SeleniumTest class.<\/p>\n<h3>Conclusion<\/h3>\n<p>In this tutorial, we have shown how to set up a Maven project for Selenium automation and how to create a simple Selenium test using Maven. With the knowledge gained from this tutorial, you should be able to create and run Selenium tests in a Maven project. Happy testing!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Popular open-source software called Selenium is used to automate web browsers. It allows testers and developers to automate web-based applications to perform functional testing. One of the popular build tools for Selenium automation is&#46;&#46;&#46;<\/p>\n","protected":false},"author":581,"featured_media":114060,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22825],"tags":[27543,27544],"class_list":["post-114057","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-selenium-tutorials","tag-selenium-maven","tag-selenium-maven-dependency"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Maven for Selenium - DataFlair<\/title>\n<meta name=\"description\" content=\"Learn how to set up a Maven project for Selenium automation and how to create a simple Selenium test using Maven.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/maven-for-selenium\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Maven for Selenium - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Learn how to set up a Maven project for Selenium automation and how to create a simple Selenium test using Maven.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/maven-for-selenium\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-05-08T03:30:16+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-05-12T06:13:02+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/04\/selenium-maven-tutorial.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Maven for Selenium - DataFlair","description":"Learn how to set up a Maven project for Selenium automation and how to create a simple Selenium test using Maven.","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:\/\/data-flair.training\/blogs\/maven-for-selenium\/","og_locale":"en_US","og_type":"article","og_title":"Maven for Selenium - DataFlair","og_description":"Learn how to set up a Maven project for Selenium automation and how to create a simple Selenium test using Maven.","og_url":"https:\/\/data-flair.training\/blogs\/maven-for-selenium\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2023-05-08T03:30:16+00:00","article_modified_time":"2023-05-12T06:13:02+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/04\/selenium-maven-tutorial.webp","type":"image\/webp"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/maven-for-selenium\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/maven-for-selenium\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/c187795dc82ab948373cca526df7c445"},"headline":"Maven for Selenium","datePublished":"2023-05-08T03:30:16+00:00","dateModified":"2023-05-12T06:13:02+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/maven-for-selenium\/"},"wordCount":381,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/maven-for-selenium\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/04\/selenium-maven-tutorial.webp","keywords":["Selenium Maven","Selenium Maven dependency"],"articleSection":["Selenium Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/maven-for-selenium\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/maven-for-selenium\/","url":"https:\/\/data-flair.training\/blogs\/maven-for-selenium\/","name":"Maven for Selenium - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/maven-for-selenium\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/maven-for-selenium\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/04\/selenium-maven-tutorial.webp","datePublished":"2023-05-08T03:30:16+00:00","dateModified":"2023-05-12T06:13:02+00:00","description":"Learn how to set up a Maven project for Selenium automation and how to create a simple Selenium test using Maven.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/maven-for-selenium\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/maven-for-selenium\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/maven-for-selenium\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/04\/selenium-maven-tutorial.webp","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/04\/selenium-maven-tutorial.webp","width":1200,"height":628,"caption":"selenium maven tutorial"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/maven-for-selenium\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Selenium Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/selenium-tutorials\/"},{"@type":"ListItem","position":3,"name":"Maven for Selenium"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/c187795dc82ab948373cca526df7c445","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/2302ebc438084d2f1f993edc1996a0aae01332e81f3227cba8df0c48ec010ca4?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/2302ebc438084d2f1f993edc1996a0aae01332e81f3227cba8df0c48ec010ca4?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2302ebc438084d2f1f993edc1996a0aae01332e81f3227cba8df0c48ec010ca4?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam6\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/114057","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/581"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=114057"}],"version-history":[{"count":5,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/114057\/revisions"}],"predecessor-version":[{"id":114433,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/114057\/revisions\/114433"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/114060"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=114057"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=114057"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=114057"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}