selenium webdriver (selenium 2.0)

Download Selenium Webdriver (Selenium 2.0)

Post on 20-Oct-2015




4 download

Embed Size (px)


How to setup and use Selenium WebDriver with Microsoft Visual Studio



SeleniumWeb Driver

Rouella MacairanQA TesterMagenic Manila1Table of ContentsWhat is Selenium? (Background/Trivia)Selenium WebDriver


What is Selenium?A set of tools that supports rapid development of test automation for web-based applications.

Can be recorded and written as HTMLSupport for a number of programming languages: Java, C#, Perl, PHP, Python, RubyCross browsers support: IE, Firefox, Opera, Safari and Google ChromeCross platform support: Windows, Linux, and Macintosh.

Selenium BackgroundInvented in 2004 by Jason R. Huggins and team.Originally named JavaScript Functional Tester [JSFT]100% Javascript and HTMLDesigned to make test writing easyOpen source browser based integration test framework built originally by ThoughtWorksSelenium is open source software, released under the Apache 2.0 license and can be downloaded and used without charge.

Selenium TriviaSelenium is a chemical element with the atomic number 34, represented by the chemical symbol Se.



Selenium is used for treating Mercury poisoningProducts: QTP, WinRunner, LoadRunner and TestDirector

Selenium ComponentsSelenium IDE

Selenium RC Selenium Grid

Selenium 2 aka Webdriver

Selenium WebDriver

Why Use the WebDriver?Selenium WebDriverA tool for automating web application testing Developed to better support dynamic web pages where elements of a page may change without the page itself being reloaded(AJAX)Makes direct calls to the browser using each browsers native support for automation the page itself being reloaded.9WebDriver Wire ProtocolSelenium 1.0 + WebDriver = Selenium 2.0Binding Code(C#, Java ) Drivers(IE, Firefox, Chrome )The WebDriver Wire ProtocolAll implementations of WebDriver that communicate with the browser, or a Remote WebDriver server shall use a common wire protocolThe wire protocol defines a RESTful web service using JSON over HTTPimplemented in request/response pairs of "commands" and "responses"11Rest Console Demo

Selenium RC vs. WebDriverSelenium-RC "injected" JS functions into the browser when the browser was loaded and then used its JS to drive the AUT within the browser

Selenium-WebDriver makes direct calls to the browser using each browsers native support for automation13

Setting Up WebDriver14

Create New Project in VSUsing NuGet packagesInstall NuGet package manager and navigate to itSearch for selenium and install the first item in the result listCreating DriverCreate an instance of a driverNote: additional steps are required to use Chrome Driver, Opera Driver, Android Driver and iPhone DriverIWebDriver driverOne = new FirefoxDriver();IWebDriver driverTwo = new InternetExlorerDriver();15driver.Url = "";Navigate to pageGetting StartedChoose and download browser driver you want to use for your tests (ex. Chrome)16using OpenQA.Selenium;usiOpenQA.Selenium.Chrome;

namespace WebDriverDemo{ class Program { static void Main(string[] args) { IWebDriver driver = new ChromeDriver(@"C:\libraries"); driver.Url= ""; } }}The IWebDriver interface can be find under OpenQA.Selenium namespaceYou have to tell the WebDriver API where this ChromeDriverServer is located ElementsElements can be located by the same properties as in the IDEBy IDIWebElement element = driver.FindElement(By.Id("coolestWidgetEvah"));17By ClassIList cheeses = driver.FindElements(By.ClassName("cheese"));By Tag NameIWebElement frame = driver.FindElement(By.TagName("iframe"));Locating Elements(2)By NameIWebElement cheese = driver.FindElement(By.Name("cheese"));18By Link TextBy CSS SelectorBy XPathIWebElement cheese = driver.FindElement(By.LinkText("cheese"));IList inputs = driver.FindElements(By.XPath("//input"));IWebElement cheese = driver.FindElement(By.CssSelector("#food span.dairy.aged"));Wait StepsExplicit waitWebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));

IWebElement myDynamicElement = wait.Until((d) => { return d.FindElement(By.Id("someDynamicElement")); });19driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));Implicit waitType TextType Text into a field using Selenium WebDriver SendKeys() function// Find the text input element by its name IWebElement element = driver.FindElement(By.Name("search"));

// Enter something to search for element.SendKeys(magenic");20

Verify Text StepsWebDriver does not support the well-known commands of Selenium IDE like verifyTextPresent

public static void AssertTextPresent(String value){ if (!driver.PageSource.Contains(value)) { throw new Exception(value + " is not present"); } }21We can implement soAssertsThere wasnt any built-in method to assert text on a pageYou can do something along the lines ofstatic void Main(string[] args){ IWebDriver driver = new ChromeDriver(@"C:\libraries"); driver.Url= ""; Assert.AreEqual("Google", driver.Title);}22Reporting ResultsThe test results are limited by the Unit Testing Framework we useex. NUnit, VS Test Team, Gallio 23

Uning NUnit-Results Web Driver Demo

Selenium Questions????????????