Skip to main content

Posts

What to expect from this blog?

This blog can be used as a tutorial by beginners and as a reference manual by experts. It covers basics of selenium like how to set up your system to advanced topics like Selenium Grid and data driven testing. Add comments if you would like to learn about anything specific.
Recent posts

Selenium - What Why Who How?

What is Selenium? Selenium is an open source automated   testing   suite for web applications across different browsers and platforms.   It is quite similar to HP Quick Test Pro ( QTP ) only that Selenium focuses on automating web-based applications. Why use Selenium? Selenium is fast and it supports programming in multiple languages like Java, C#,Python and Ruby.  So development of automation scripts can be done in your language of preference. Selenium works well with AJAX testing. Selenium Grid supports execution of test cases in multiple platforms and multiple browsers in remote systems as well.  The support for different programming languages gave selenium the power to harness the capabilities of those programming languages .  For example, using JAVA as the programming language to code selenium scripts enables selenium to use JDBC for database access and testing.All the APIs supported in Java also become the advantage of Selenium like L...

How to Install Selenium and execute your first program

You can install and test Selenium using the following steps. All files can be downloaded from  http://www.seleniumhq.org/download/   Download Selenium Server jar file   Download client library java jar file   Download InternetExplorer Driver file   Install eclipse workspace. (download eclipse. Unzip folder. Find eclipse.exe application and open it) Create a new java project with 1,2 as references Copy 3 to workspace For IE, go to internet options->security and change the security level so that it’s the same for all zones. Write sample java program Below program opens google in IE and searches for selenium test and closes it. // All the imports happen automatically when you use eclipse ide and add the downloaded jars in the project references package test; import org.openqa.selenium.Alert; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.ie...

Selenium Browser Commands

To create a instance of a browser,  WebDriver driver=new InternetExplorerDriver(); WebDriver driver=new FireFoxDriver(); WebDriver driver=new ChromeDriver(); You must have the driver file(which can be downloaded from the selenium site) in your local system for these commands to work. The files can be added in a place where your program can access them or you need to set their path in your program using commands like System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver"); System.setProperty("webdriver.ie.driver", "/path/to/iedriver"); Firefox driver comes with the selenium server jar so we don't have to download it separately.                                                                           (or) The following code can be used to execute scripts in the remote mac...

Switch between browsers\windows and pop ups

These commands can be used to switch between windows, iterate through different windows opened by the webdriver, handle pop ups and frames in windows.  GetWindowHandle Command Purpose : To get the   window handle   of the current window. driver.getWindowHandle(); Returns an alphanumeric string GetWindowHandles Command Purpose : To get the   window handle   of   all   the current windows. Set<String> handle=Driver.getWindowHandles(); Returns a set of window handles SwitchTo Window Command Purpose : WebDriver supports   moving   between named windows using the “switchTo” method. For(String handle:driver.getWindowHandles()) Driver.switchto().window(handle); Or Driver.switchto().window(windowname); <A href="newwindow.html" target=" windowname ">click here for a new window </A> SwitchTo Frame Command Purpose : WebDriver supports moving between frames using the “ switchTo ” method. Driver.s...

How to find a WebElement

Find Element & Find Elements Method The difference between “ Find Elemen t” and “ Find Elements ” method is the first returns a WebElement object otherwise it throws an exception and the latter returns a list of WebElements, it can return an empty list if no DOM elements match the query. The “Find” methods take a locator or query object called “ By ”. “ By ” methods are listed below. By ID With this strategy, the first element with the id attribute value matching the location will be returned. If no element has a matching id attribute, a  NoSuchElementException   will be raised. This is the most efficient and preferred way to locate an element, as most of the times IDs are unique. But in some cases UI developers make it having non-unique ids on a page or auto-generating the id, in both cases it should be avoided. Example : If an element is given like this: <input id=”username”></input> WebElement we=driver.findElement(By.id(“username”));  ...

Selenium Grid - Distributed Systems

Selenium grid is powerful and can be easily used with just few lines of code. A Grid is a network of computers which can be heterogeneous and geographically dispersed. A Selenium Grid is how a grid of computers are connected using Selenium and configured to perform a task. A task typically here is running a suite of test cases with different browsers in different platforms across geographically dispersed systems. The test cases can be run in parallel using Selenium. So if we have a grid of three computers the same set of test cases can be run in IE, Firefox and Chrome. To establish this we have three important components. 1) Hub 2) Node 3) Test Script A Hub acts like the server to which requests are sent . The Hub sends to request to various registered nodes. The HUB can be instantiated using command line by using the selenium server standalone jar file. Open command prompt, navigate to the folder which has the selenium server file and use this command. java -jar selen...