{"id":16265,"date":"2014-12-07T12:12:50","date_gmt":"2014-12-07T06:42:50","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=16265"},"modified":"2015-07-10T13:15:42","modified_gmt":"2015-07-10T07:45:42","slug":"selenium-web-driver-an-intro","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/selenium-web-driver-an-intro\/","title":{"rendered":"Selenium Web Driver: An Introduction"},"content":{"rendered":"<p>Selenium WebDriver is a clean, fast framework for automated testing of webapps.<\/p>\n<p>Selenium WebDriver, a popular and well established <a title=\"Web Testing using Selenium\" href=\"http:\/\/www.tothenew.com\/blog\/web-testing-using-selenium-fix-for-error-javalangnullpointerexception-sessionid-should-not-be-null-has-this-session-been-started-yet\/\">testing framework<\/a> is a wonderful tool that provides a handy unified interface that works with a large number of browsers and allows you to write your tests in almost every language you can imagine from Java or C# through Ruby, Python to JavaScript. It is one of the first Open Source projects to bring browser-based testing to the masses.<\/p>\n<p>It aims to provide a friendly API that is easy to explore and understand, which will help make your tests easier to read and maintain down the line.<\/p>\n<p>It is not tied to any particular test framework, so it can be used equally well with JUnit, TestNG or from a plain old &#8220;main&#8221; method.<\/p>\n<p><strong>Guide to \u201cGetting Started\u201d<\/strong><\/p>\n<p>This &#8220;Getting Started&#8221; guide introduces you to WebDriver&#8217;s Java API and helps get you started becoming familiar with it.<\/p>\n<ul>\n<li>Start by <a href=\"http:\/\/selenium-release.storage.googleapis.com\/2.44\/selenium-java-2.44.0.zip\">downloading<\/a> the latest binaries and unpack them into a directory.<\/li>\n<li>Start a new Java project in your favourite IDE<\/li>\n<li>Add all the JAR files from the directory to the CLASSPATH of the Java project<\/li>\n<\/ul>\n<p><!--more--><\/p>\n<p>You can see that WebDriver acts just as a normal Java library does, it&#8217;s entirely self-contained, and you don&#8217;t need to remember to start any additional processes or run any installers before using it.<\/p>\n<p>You&#8217;re now ready to write some code. An easy way to get started is this example, which open the Firefox browser and searches for the term &#8220;Selenium Web Driver&#8221; on Google and then outputs the result page&#8217;s title to the console.<\/p>\n<p><code>package com.intelligrape.selenium.example;<br \/>\nimport org.openqa.selenium.By;<br \/>\nimport org.openqa.selenium.WebDriver;<br \/>\nimport org.openqa.selenium.WebElement;<br \/>\nimport org.openqa.selenium.firefox.FirefoxDriver;<\/code><\/p>\n<p>public class Example {<br \/>\npublic static void main(String[] args) {<\/p>\n<p>\/\/ create a new instance of the Firefox driver<br \/>\nWebDriver driver = new FirefoxDriver();<\/p>\n<p>\/\/ go to &#8220;http:\/\/google.com&#8221; to visit Google<br \/>\ndriver.get(&#8220;http:\/\/www.google.com&#8221;);<\/p>\n<p>\/\/ find the text input element by its name<br \/>\nWebElement element = driver.findElement(By.name(&#8220;q&#8221;));<\/p>\n<p>\/\/ enter something to search for<br \/>\nelement.sendKeys(&#8220;Selenium Web Driver&#8221;);<\/p>\n<p>\/\/ now submit the form.<br \/>\nelement.submit();<\/p>\n<p>\/\/ check the title of the page<br \/>\nSystem.out.println(&#8220;Page title is: &#8221; + driver.getTitle());<\/p>\n<p>\/\/close the browser<br \/>\ndriver.quit();<br \/>\n}<br \/>\n}<\/p>\n<p>Cheers<br \/>\nGaurav Gupta<br \/>\ngaurav.gupta[at]intelligrape[dot]com<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Selenium WebDriver is a clean, fast framework for automated testing of webapps. Selenium WebDriver, a popular and well established testing framework is a wonderful tool that provides a handy unified interface that works with a large number of browsers and allows you to write your tests in almost every language you can imagine from Java [&hellip;]<\/p>\n","protected":false},"author":144,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":1},"categories":[7,1],"tags":[1561,25,1562,1563],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/16265"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/144"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=16265"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/16265\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=16265"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=16265"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=16265"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}