Skip to main content

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/
  1.  Download Selenium Server jar file
  2.  Download client library java jar file
  3.  Download InternetExplorer Driver file
  4.  Install eclipse workspace. (download eclipse. Unzip folder. Find eclipse.exe application and open it)
  5. Create a new java project with 1,2 as references
  6. Copy 3 to workspace
  7. For IE, go to internet options->security and change the security level so that it’s the same for all zones.
  8. 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.InternetExplorerDriver;

import org.openqa.selenium.support.ui.ExpectedConditions;

import org.openqa.selenium.support.ui.WebDriverWait;

public class googlesearch {

public static void main(String[] args) throws Exception {

NewTest t=new NewTest();

t.test();
}
}

class NewTest {
public void test() throws Exception

{
System.setProperty("webdriver.ie.driver", "IEDriverServer.exe");
final WebDriver driver=new InternetExplorerDriver();
driver.get("http://www.google.com");
//Alert is to handle pop ups
//Alert alert=driver.switchTo().alert();
//alert.accept();
WebElement myelm=(new WebDriverWait(driver,10)).until(ExpectedConditions.presenceOfElementLocated(By.name("q")));
driver.findElement(By.name("q")).sendKeys("selenium test");
driver.findElement(By.name("q")).submit();
driver.quit();
}
}

Comments

Popular posts from this blog

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...

Transition from Test Automation Engineer to Test Engineer

What's the difference? Test Automation Engineer works on automating the Regression Test Suite. Test Engineer ensures the product can be released to the customer. With my industry experience, I have realized, that, as part of automation engineer your job duties don't stop with creating Automation tests, Frameworks and running them. With more tests being automated, your responsibilities not only include running the complete Regression suite but occasionally validation and verification of the product. There are different documents/sites defining different types of testing and where their usage, however,but finding bugs is a different skill. Though we are testers by role, our analytical minds work like developers as we develop scripts too. We could be biased. When something doesn't work, we look for a workaround and think it's no big deal. This attitude is a deal breaker!Instead use your skills to analyse and break the code. Here I am going to list some of my ideas ...

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...