-
Notifications
You must be signed in to change notification settings - Fork 0
/
component---src-pages-content-articles-backup-testing-guide-to-selenium-with-junit-testng-index-md-ae86a5e6841b5b6a41e0.js
2 lines (2 loc) · 66.5 KB
/
component---src-pages-content-articles-backup-testing-guide-to-selenium-with-junit-testng-index-md-ae86a5e6841b5b6a41e0.js
1
2
(window.webpackJsonp=window.webpackJsonp||[]).push([[19],{ME8j:function(e,a,t){"use strict";t.r(a),t.d(a,"_frontmatter",(function(){return s})),t.d(a,"default",(function(){return m}));t("rGqo"),t("yt8O"),t("Btvt"),t("RW0V"),t("91GP"),t("q1tI");var n=t("7ljp");var s={templateKey:"article",published:!1,displayComments:!1,showAuthorInfo:!1,author:"meenakshivemuri",title:"Guide to Selenium with JUnit / TestNG",description:"Guide to Selenium with JUnit / TestNG",date:"2019-12-25T23:46:37.121Z",updated:"2019-12-25T23:46:37.121Z",cover:"../../../images/blog-banners/testing-banner-1200x690.png",category:"testing",tags:["java","streams","featured"]},c={_frontmatter:s};function m(e){var a=e.components,t=function(e,a){if(null==e)return{};var t,n,s={},c=Object.keys(e);for(n=0;n<c.length;n++)t=c[n],a.indexOf(t)>=0||(s[t]=e[t]);return s}(e,["components"]);return Object(n.mdx)("wrapper",Object.assign({},c,t,{components:a,mdxType:"MDXLayout"}),Object(n.mdx)("h2",null,"Intro"),Object(n.mdx)("p",null,"This article is a quick, practical introduction to working with ",Object(n.mdx)("code",Object.assign({parentName:"p"},{className:"language-text"}),"Selenium")," and writing tests with ",Object(n.mdx)("code",Object.assign({parentName:"p"},{className:"language-text"}),"JUnit")," and ",Object(n.mdx)("code",Object.assign({parentName:"p"},{className:"language-text"}),"TestNG"),"."),Object(n.mdx)("h2",null,"Selenium Integration"),Object(n.mdx)("p",null,"In this section, we’ll start with a simple scenario – opening a browser window, navigating to a given URL and looking for some desired content on the page."),Object(n.mdx)("h3",null,"Maven Dependencies"),Object(n.mdx)("p",null,"In the ",Object(n.mdx)("code",Object.assign({parentName:"p"},{className:"language-text"}),"pom.xml")," file, add the following dependency:"),Object(n.mdx)("div",{className:"gatsby-highlight","data-language":"xml"},Object(n.mdx)("pre",Object.assign({parentName:"div"},{className:"language-xml"}),Object(n.mdx)("code",Object.assign({parentName:"pre"},{className:"language-xml"}),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token tag"}),Object(n.mdx)("span",Object.assign({parentName:"span"},{className:"token tag"}),Object(n.mdx)("span",Object.assign({parentName:"span"},{className:"token punctuation"}),"<"),"dependency"),Object(n.mdx)("span",Object.assign({parentName:"span"},{className:"token punctuation"}),">")),"\n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token tag"}),Object(n.mdx)("span",Object.assign({parentName:"span"},{className:"token tag"}),Object(n.mdx)("span",Object.assign({parentName:"span"},{className:"token punctuation"}),"<"),"groupId"),Object(n.mdx)("span",Object.assign({parentName:"span"},{className:"token punctuation"}),">")),"org.seleniumhq.selenium",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token tag"}),Object(n.mdx)("span",Object.assign({parentName:"span"},{className:"token tag"}),Object(n.mdx)("span",Object.assign({parentName:"span"},{className:"token punctuation"}),"</"),"groupId"),Object(n.mdx)("span",Object.assign({parentName:"span"},{className:"token punctuation"}),">")),"\n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token tag"}),Object(n.mdx)("span",Object.assign({parentName:"span"},{className:"token tag"}),Object(n.mdx)("span",Object.assign({parentName:"span"},{className:"token punctuation"}),"<"),"artifactId"),Object(n.mdx)("span",Object.assign({parentName:"span"},{className:"token punctuation"}),">")),"selenium-java",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token tag"}),Object(n.mdx)("span",Object.assign({parentName:"span"},{className:"token tag"}),Object(n.mdx)("span",Object.assign({parentName:"span"},{className:"token punctuation"}),"</"),"artifactId"),Object(n.mdx)("span",Object.assign({parentName:"span"},{className:"token punctuation"}),">")),"\n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token tag"}),Object(n.mdx)("span",Object.assign({parentName:"span"},{className:"token tag"}),Object(n.mdx)("span",Object.assign({parentName:"span"},{className:"token punctuation"}),"<"),"version"),Object(n.mdx)("span",Object.assign({parentName:"span"},{className:"token punctuation"}),">")),"3.4.0",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token tag"}),Object(n.mdx)("span",Object.assign({parentName:"span"},{className:"token tag"}),Object(n.mdx)("span",Object.assign({parentName:"span"},{className:"token punctuation"}),"</"),"version"),Object(n.mdx)("span",Object.assign({parentName:"span"},{className:"token punctuation"}),">")),"\n",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token tag"}),Object(n.mdx)("span",Object.assign({parentName:"span"},{className:"token tag"}),Object(n.mdx)("span",Object.assign({parentName:"span"},{className:"token punctuation"}),"</"),"dependency"),Object(n.mdx)("span",Object.assign({parentName:"span"},{className:"token punctuation"}),">"))))),Object(n.mdx)("p",null,"The latest version can be found in the ",Object(n.mdx)("code",Object.assign({parentName:"p"},{className:"language-text"}),"Maven Central Repository"),"."),Object(n.mdx)("h3",null,"Selenium Configuration"),Object(n.mdx)("p",null,"First, create a new Java class file called ",Object(n.mdx)("code",Object.assign({parentName:"p"},{className:"language-text"}),"SeleniumConfig"),":"),Object(n.mdx)("div",{className:"gatsby-highlight","data-language":"java"},Object(n.mdx)("pre",Object.assign({parentName:"div"},{className:"language-java"}),Object(n.mdx)("code",Object.assign({parentName:"pre"},{className:"language-java"}),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"public")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"class")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"SeleniumConfig")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"{"),"\n \n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"private")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"WebDriver")," driver",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n \n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token comment"}),"//..."),"\n \n",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"}")))),Object(n.mdx)("p",null,"Given we’re using a ",Object(n.mdx)("code",Object.assign({parentName:"p"},{className:"language-text"}),"Selenium 3.x")," version, we have to specify the path of an executable ",Object(n.mdx)("code",Object.assign({parentName:"p"},{className:"language-text"}),"GeckoDriver")," file (based on your OS) using a system property called ",Object(n.mdx)("code",Object.assign({parentName:"p"},{className:"language-text"}),"webdriver.gecko.driver")," The latest version of the GeckoDriver may be downloaded from Github ",Object(n.mdx)("code",Object.assign({parentName:"p"},{className:"language-text"}),"Geckodriver")," Releases."),Object(n.mdx)("p",null,"Let’s now initialize the WebDriver in the constructor, we’ll also set 5 seconds as a time-out for WebDriver to wait for an element on the page to appear:"),Object(n.mdx)("div",{className:"gatsby-highlight","data-language":"java"},Object(n.mdx)("pre",Object.assign({parentName:"div"},{className:"language-java"}),Object(n.mdx)("code",Object.assign({parentName:"pre"},{className:"language-java"}),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"public")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"SeleniumConfig"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"{"),"\n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"Capabilities")," capabilities ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token operator"}),"=")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"DesiredCapabilities"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"firefox"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n driver ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token operator"}),"=")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"new")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"FirefoxDriver"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),"capabilities",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n driver",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"manage"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"timeouts"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"implicitlyWait"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token number"}),"5"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),",")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"TimeUnit"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"SECONDS",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"}"),"\n \n",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"static")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"{"),"\n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"System"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"setProperty"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token string"}),'"webdriver.gecko.driver"'),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),",")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"findFile"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token string"}),'"geckodriver.mac"'),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"}"),"\n \n",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"static")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"private")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"String")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"findFile"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"String")," filename",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"{"),"\n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"String")," paths",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"["),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"]")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token operator"}),"=")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"{"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token string"}),'""'),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),",")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token string"}),'"bin/"'),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),",")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token string"}),'"target/classes"'),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"}"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"for")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"String")," path ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token operator"}),":")," paths",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"{"),"\n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"if")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"new")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"File"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),"path ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token operator"}),"+")," filename",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"exists"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),"\n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"return")," path ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token operator"}),"+")," filename",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"}"),"\n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"return")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token string"}),'""'),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"}")))),Object(n.mdx)("p",null,"This configuration class contains a couple of methods that we will ignore for now, but we will see more about these on the second part of this series."),Object(n.mdx)("p",null,"Next, we will need to implement a ",Object(n.mdx)("code",Object.assign({parentName:"p"},{className:"language-text"}),"SeleniumExample")," class:"),Object(n.mdx)("div",{className:"gatsby-highlight","data-language":"java"},Object(n.mdx)("pre",Object.assign({parentName:"div"},{className:"language-java"}),Object(n.mdx)("code",Object.assign({parentName:"pre"},{className:"language-java"}),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"public")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"class")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"SeleniumExample")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"{"),"\n \n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"private")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"SeleniumConfig")," config",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"private")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"String")," url ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token operator"}),"=")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token string"}),'"http://www.baeldung.com/"'),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n \n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"public")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"SeleniumExample"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"{"),"\n config ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token operator"}),"=")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"new")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"SeleniumConfig"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n config",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"getDriver"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"get"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),"url",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"}"),"\n \n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token comment"}),"// ..."),"\n",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"}")))),Object(n.mdx)("p",null,"In here, we will initialize the ",Object(n.mdx)("code",Object.assign({parentName:"p"},{className:"language-text"}),"SeleniumConfig")," and set the desired URL to navigate to. Similarly, we’ll implement a simple API to close the browser and get the title of the page:"),Object(n.mdx)("div",{className:"gatsby-highlight","data-language":"java"},Object(n.mdx)("pre",Object.assign({parentName:"div"},{className:"language-java"}),Object(n.mdx)("code",Object.assign({parentName:"pre"},{className:"language-java"}),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"public")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"void")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"closeWindow"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"{"),"\n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"this"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"config",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"getDriver"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"close"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"}"),"\n \n",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"public")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"String")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"getTitle"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"{"),"\n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"return")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"this"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"config",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"getDriver"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"getTitle"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"}")))),Object(n.mdx)("p",null,"In order to navigate to the About section of baeldung.com, we need to create a closeOverlay() method that checks and closes the overlay on a homepage load. Thereafter, we navigate to the About Baeldung page using the ",Object(n.mdx)("code",Object.assign({parentName:"p"},{className:"language-text"}),"getAboutBaeldungPage()")," method:"),Object(n.mdx)("div",{className:"gatsby-highlight","data-language":"java"},Object(n.mdx)("pre",Object.assign({parentName:"div"},{className:"language-java"}),Object(n.mdx)("code",Object.assign({parentName:"pre"},{className:"language-java"}),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"public")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"void")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"getAboutBaeldungPage"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"{"),"\n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"closeOverlay"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"clickAboutLink"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"clickAboutUsLink"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"}"),"\n \n",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"private")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"void")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"closeOverlay"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"{"),"\n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"List"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token generics"}),Object(n.mdx)("span",Object.assign({parentName:"span"},{className:"token punctuation"}),"<"),Object(n.mdx)("span",Object.assign({parentName:"span"},{className:"token class-name"}),"WebElement"),Object(n.mdx)("span",Object.assign({parentName:"span"},{className:"token punctuation"}),">"))," webElementList ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token operator"}),"=")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"this"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"config",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"getDriver"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),"\n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"findElements"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"By"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"tagName"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token string"}),'"a"'),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"if")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),"webElementList ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token operator"}),"!=")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"null"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"{"),"\n webElementList",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"stream"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),"\n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"filter"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),"webElement ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token operator"}),"->")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token string"}),'"Close"'),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"equalsIgnoreCase"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),"webElement",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"getAttribute"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token string"}),'"title"'),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),"\n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"filter"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"WebElement"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token operator"}),"::"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"isDisplayed"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),"\n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"findAny"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),"\n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"ifPresent"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"WebElement"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token operator"}),"::"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"click"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"}"),"\n",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"}"),"\n \n",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"private")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"void")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"clickAboutLink"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"{"),"\n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"this"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"config",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"getDriver"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"findElement"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"By"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"partialLinkText"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token string"}),'"About"'),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"click"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"}"),"\n \n",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"private")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"void")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"clickAboutUsLink"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"{"),"\n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"Actions")," builder ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token operator"}),"=")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"new")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"Actions"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),"config",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"getDriver"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"WebElement")," element ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token operator"}),"=")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"this"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"config",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"getDriver"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),"\n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"findElement"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"By"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"partialLinkText"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token string"}),'"About Baeldung."'),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n builder",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"moveToElement"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),"element",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),"\n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"build"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),"\n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"perform"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"}")))),Object(n.mdx)("p",null,"We can check if the required information is available on the displayed page:"),Object(n.mdx)("div",{className:"gatsby-highlight","data-language":"java"},Object(n.mdx)("pre",Object.assign({parentName:"div"},{className:"language-java"}),Object(n.mdx)("code",Object.assign({parentName:"pre"},{className:"language-java"}),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"public")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"boolean")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"isAuthorInformationAvailable"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"{"),"\n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"return")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"this"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),"config",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"getDriver"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),"\n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"findElement"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"By"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"cssSelector"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token string"}),'"article > .row > div"'),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),"\n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"isDisplayed"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"}")))),Object(n.mdx)("p",null,"Next, we are going to test this class with both JUnit and TestNG."),Object(n.mdx)("h2",null,"With JUnit"),Object(n.mdx)("p",null,"Let’s create a new test class as ",Object(n.mdx)("code",Object.assign({parentName:"p"},{className:"language-text"}),"SeleniumWithJUnitLiveTest"),":"),Object(n.mdx)("div",{className:"gatsby-highlight","data-language":"java"},Object(n.mdx)("pre",Object.assign({parentName:"div"},{className:"language-java"}),Object(n.mdx)("code",Object.assign({parentName:"pre"},{className:"language-java"}),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"public")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"class")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"SeleniumWithJUnitLiveTest")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"{"),"\n \n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"private")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"static")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"SeleniumExample")," seleniumExample",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"private")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"String")," expectedTitle ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token operator"}),"=")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token string"}),'"Baeldung | Java, Spring and Web Development tutorials"'),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n \n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token comment"}),"// more code goes here..."),"\n \n",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"}")))),Object(n.mdx)("p",null,"We’re going to use the @BeforeClass annotation from ",Object(n.mdx)("code",Object.assign({parentName:"p"},{className:"language-text"}),"org.junit.BeforeClass")," to do an initial setup. In this setUp() method we are going to initialize the ",Object(n.mdx)("code",Object.assign({parentName:"p"},{className:"language-text"}),"SeleniumExample")," object:"),Object(n.mdx)("div",{className:"gatsby-highlight","data-language":"java"},Object(n.mdx)("pre",Object.assign({parentName:"div"},{className:"language-java"}),Object(n.mdx)("code",Object.assign({parentName:"pre"},{className:"language-java"}),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token annotation punctuation"}),"@BeforeClass"),"\n",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"public")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"static")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"void")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"setUp"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"{"),"\n seleniumExample ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token operator"}),"=")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"new")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"SeleniumExample"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"}")))),Object(n.mdx)("p",null,"In a similar way, when our test case finishes, we should close the newly opened browser. We’re going to do this with ",Object(n.mdx)("code",Object.assign({parentName:"p"},{className:"language-text"}),"@AfterClass")," annotation – to clean up the settings when test case execution has finished:"),Object(n.mdx)("div",{className:"gatsby-highlight","data-language":"java"},Object(n.mdx)("pre",Object.assign({parentName:"div"},{className:"language-java"}),Object(n.mdx)("code",Object.assign({parentName:"pre"},{className:"language-java"}),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token annotation punctuation"}),"@AfterClass"),"\n",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"public")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"static")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"void")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"tearDown"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"{"),"\n seleniumExample",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"closeWindow"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"}")))),Object(n.mdx)("p",null,"Please note the static modifier on our SeleniumExample member variable – because we need to use this variable in the setUp() and tearDown() static methods – ",Object(n.mdx)("code",Object.assign({parentName:"p"},{className:"language-text"}),"@BeforeClass")," and ",Object(n.mdx)("code",Object.assign({parentName:"p"},{className:"language-text"}),"@AfterClass")," can be invoked on static methods only."),Object(n.mdx)("p",null,"Finally, we can create our full test:"),Object(n.mdx)("div",{className:"gatsby-highlight","data-language":"java"},Object(n.mdx)("pre",Object.assign({parentName:"div"},{className:"language-java"}),Object(n.mdx)("code",Object.assign({parentName:"pre"},{className:"language-java"}),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token annotation punctuation"}),"@Test"),"\n",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"public")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"void")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"whenAboutBaeldungIsLoaded_thenAboutEugenIsMentionedOnPage"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"{"),"\n seleniumExample",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"getAboutBaeldungPage"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"String")," actualTitle ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token operator"}),"=")," seleniumExample",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"getTitle"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n \n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"assertNotNull"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),"actualTitle",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"assertEquals"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),"expectedTitle",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),",")," actualTitle",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"assertTrue"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),"seleniumExample",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"isAuthorInformationAvailable"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"}")))),Object(n.mdx)("p",null,"This test method asserts that the title of the web page is ",Object(n.mdx)("code",Object.assign({parentName:"p"},{className:"language-text"}),"not null")," and is set as expected. Besides that, we check that the page contains the expected information."),Object(n.mdx)("p",null,"When the test runs, it simply opens the URL in Firefox and subsequently closes it after the title of the web page and content have been verified."),Object(n.mdx)("h2",null,"With TestNG"),Object(n.mdx)("p",null,"Let’s now use TestNG to run our ",Object(n.mdx)("code",Object.assign({parentName:"p"},{className:"language-text"}),"test case/suite"),"."),Object(n.mdx)("p",null,"Note that if you’re using Eclipse, the TestNG plugin may be downloaded and installed from the Eclipse Marketplace."),Object(n.mdx)("p",null,"First, let’s create a new test class:"),Object(n.mdx)("div",{className:"gatsby-highlight","data-language":"java"},Object(n.mdx)("pre",Object.assign({parentName:"div"},{className:"language-java"}),Object(n.mdx)("code",Object.assign({parentName:"pre"},{className:"language-java"}),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"public")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"class")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"SeleniumWithTestNGLiveTest")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"{"),"\n \n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"private")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"SeleniumExample")," seleniumExample",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"private")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"String")," expectedTitle ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token operator"}),"=")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token string"}),'"Baeldung | Java, Spring and Web Development tutorials"'),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n \n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token comment"}),"// more code goes here..."),"\n \n",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"}")))),Object(n.mdx)("p",null,"We’ll use a ",Object(n.mdx)("code",Object.assign({parentName:"p"},{className:"language-text"}),"@BeforeSuite")," annotation from org.testng.annotations.",Object(n.mdx)("code",Object.assign({parentName:"p"},{className:"language-text"}),"BeforeSuite")," to instantiate our SeleniumExample class. The ",Object(n.mdx)("code",Object.assign({parentName:"p"},{className:"language-text"}),"setUp()")," method will be launched just before the test suite is activated:"),Object(n.mdx)("div",{className:"gatsby-highlight","data-language":"java"},Object(n.mdx)("pre",Object.assign({parentName:"div"},{className:"language-java"}),Object(n.mdx)("code",Object.assign({parentName:"pre"},{className:"language-java"}),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token annotation punctuation"}),"@BeforeSuite"),"\n",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"public")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"void")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"setUp"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"{"),"\n seleniumExample ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token operator"}),"=")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"new")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"SeleniumExample"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"}")))),Object(n.mdx)("p",null,"Similarly, we’ll use the @AfterSuite annotation from org.testng.annotations.AfterSuite to close our opened browser once the test suite has completed:"),Object(n.mdx)("div",{className:"gatsby-highlight","data-language":"java"},Object(n.mdx)("pre",Object.assign({parentName:"div"},{className:"language-java"}),Object(n.mdx)("code",Object.assign({parentName:"pre"},{className:"language-java"}),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token annotation punctuation"}),"@AfterSuite"),"\n",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"public")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"void")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"tearDown"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"{"),"\n seleniumExample",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"closeWindow"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"}")))),Object(n.mdx)("p",null,"Finally, let’s implement our test:"),Object(n.mdx)("div",{className:"gatsby-highlight","data-language":"java"},Object(n.mdx)("pre",Object.assign({parentName:"div"},{className:"language-java"}),Object(n.mdx)("code",Object.assign({parentName:"pre"},{className:"language-java"}),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token annotation punctuation"}),"@Test"),"\n",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"public")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token keyword"}),"void")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"whenAboutBaeldungIsLoaded_thenAboutEugenIsMentionedOnPage"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")")," ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"{"),"\n seleniumExample",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"getAboutBaeldungPage"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token class-name"}),"String")," actualTitle ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token operator"}),"=")," seleniumExample",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"getTitle"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n \n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"assertNotNull"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),"actualTitle",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"assertEquals"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),"expectedTitle",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),",")," actualTitle",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n ",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"assertTrue"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),"seleniumExample",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"."),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token function"}),"isAuthorInformationAvailable"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"("),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),")"),Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),";"),"\n",Object(n.mdx)("span",Object.assign({parentName:"code"},{className:"token punctuation"}),"}")))),Object(n.mdx)("p",null,"After a successful completion of the test suite, we find HTML and XML reports in the ",Object(n.mdx)("code",Object.assign({parentName:"p"},{className:"language-text"}),"test-output")," folder of the project. These reports summarize the test results."),Object(n.mdx)("h2",null,"Conclusion"),Object(n.mdx)("p",null,"In this quick article, we’ve focused on a quick intro to writing ",Object(n.mdx)("code",Object.assign({parentName:"p"},{className:"language-text"}),"Selenium 3")," tests with both ",Object(n.mdx)("code",Object.assign({parentName:"p"},{className:"language-text"}),"JUnit")," and ",Object(n.mdx)("code",Object.assign({parentName:"p"},{className:"language-text"}),"TestNG"),"."),Object(n.mdx)("p",null,"As always, the source for the article is available over at GitHub."))}m.isMDXComponent=!0}}]);
//# sourceMappingURL=component---src-pages-content-articles-backup-testing-guide-to-selenium-with-junit-testng-index-md-ae86a5e6841b5b6a41e0.js.map