Download presentation
Presentation is loading. Please wait.
Published byJason Franklin Modified over 8 years ago
1
Test Automation For Web-Based Applications Portnov Computer School Presenter: Ellie Skobel
2
2 Day 10 Selenium 2 (WebDriver)
3
Selenium is a test automation framework that interacts with a browser via javascript WebDriver is a test automation framework that interacts with the browser directly Selenium 2 is the merging of the Open Source "selenium" and "webdriver" projects The most recent release is Selenium 2.20.0.
4
Better support for IE ◦ Still a huge part of the market Support for testing mobile browsers ◦ Android ◦ iPhone ◦ Blackberry ◦ … other Not trapped in the JS sandbox ◦ So there's a way to handle "alerts" on window load cleanly. ◦ Better emulation of user input, such as clicking and typing. Cleaner API ◦ So it's easier to write and maintain code. ◦ Far less confusion about which method to call.
5
Output relative to input; the amount passing Download Selenium2 server and client jars from: http://seleniumhq.org/download/ Drop JARs into lib ◦ Add jars to Build path. In your Java code o Replace "DefaultSelenium" with "WebDriverBackedSelenium“ o Example: WebDriver driver = new FirefoxDriver(); String baseUrl = "http://www.google.com"; Selenium selenium = new WebDriverBackedSelenium(driver, baseUrl);
6
Pros ◦ Allows for the WebDriver and Selenium APIs to live side- by-side ◦ Provides a simple mechanism for a managed migration from the Selenium RC API to WebDriver’s ◦ Does not require the standalone Selenium RC server to be run Cons ◦ Does not implement every method ◦ More advanced Selenium usage (using “browserbot” or other built-in JavaScript methods from Selenium Core) may not work ◦ Some methods may be slower due to underlying implementation differences
7
may not need the Selenium Server If you will be strictly using the WebDriver API you may not need the Selenium Server. WebDriver makes direct calls to the browser. You will need the Selenium Server: If you are using Selenium Grid - to distribute your tests over many machines If you want to connect to a remote machine that has a particular browser version that is not on your current machine.
8
Simpler programming interface Object-oriented API that provides support for a larger number of browsers along with improved support for modern advanced web- app testing problems Full list of packages, classes, and interfaces with documentation can be found here: http://selenium.googlecode.com/svn/trunk/do cs/api/java/index.html
9
WebDriver is the name of the key interface, but there are several implementations: FirefoxDriver ChromeDriver ** HtmlUnitDriver InternetExlorerDriver AndroidDriver ** iPhoneDriver ** RemoteDriver OperaDriver SafariDriver **
10
To create a WebDriver Instance: WebDriver var_name = new ImplOfWebDriver() WebDriver driver; driver = new InternetExplorerDriver();OR driver = new FirefoxDriver();OR System.setProperty("webdriver.chrome.driver", "C:\\path_to_executable\\chromedriver.exe"); driver = new ChromeDriver();OR driver = new OperaDriver(); WebDriver driver; driver = new InternetExplorerDriver();OR driver = new FirefoxDriver();OR System.setProperty("webdriver.chrome.driver", "C:\\path_to_executable\\chromedriver.exe"); driver = new ChromeDriver();OR driver = new OperaDriver(); driver.quit(); Don’t forget to shutdown the driver when you’re through: driver.quit();
11
CommandDescription getTitlegetTitle()The title of the current page. switchToswitchTo()Send future commands to a different frame or window. getget(jString url)Load a new web page in the current browser window. navigatenavigate()Allows the driver to access browser's history and to navigate to a given URL findElementfindElement(By by)ByFind the first WebElement using the given method.WebElement findElementsfindElements(By by)ByFind all elements within the current page using the given mechanism. Return a List of WebElements.
12
CommandDescription clickclick()Click this element. getTextgetText()Get the visible text submitsubmit()If this current element is a form, or an element within a form, then this will be submitted to the remote server. sendKeys sendKeys (keysToSend) Use this method to simulate typing into an element, which may set its value. isSelectedisSelected()Determine whether or not this element is selected or not. isEnabledisEnabled()Is the element currently enabled or not? This will generally return true for everything but disabled input elements. getAttribute getAttribute (String name) the value of a the given attribute of the element. findElement (By by)By Find the first WebElement using the given method.WebElement findElements (By by)By Find all elements within the current page using the given mechanism. Return a List of WebElements.
13
“Find” methods take a locator called “By” StrategiesDescription id By.id(“UI_Element_Id") This is the most efficient and preferred way to locate an element. className By.className("cheese") “Class” in this case refers to the attribute on the DOM element. tagName By.tagName(“table") The DOM Tag Name of the element. name By.name(“cancel_button") Find the input element with matching name attribute linkText By.linkText(“Log In") Find the link element with matching visible text. cssSelector By.cssSelector ("#food span.dairy.aged") Locator strategy by css. Note: some css that might work in one version may not work in another. xpath By.xpath("//input") Note: some unexpected behaviour unless you are aware of the differences in the various xpath engines.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.