How to download Selenium ?

Download Selenium WebDriver Jars and configuring in eclipse.
In order to start with Automation testing using selenium WebDriver, we need below things –

1. Installed JDK or JRE on your machine.

           2. Installed Eclipse / NetBeans / or any other IDE
As we know, java is not a tool but it is a collection of jars which we need to use in eclipse or any other IDE. Here we will see how can this be achieved.

Step 1: Download Selenium WebDriver jar files.

Use below URL to download Selenium WebDriver jar files.
To Download Latest version, use this URL –   http://www.seleniumhq.org/download/
Once Selenium WebDriver jar has been downloaded, extract them to some folder. Now we will see how to configure these jar files in to our project.

Step 2: Create Java Project

Create Java project in eclipse so that we can configure selenium jars in to java project, which can be used for creating test cases.
Below steps explain how to create java project.
Click on File -> New -> Other
In select wizard, type Java, then select “Java project” from the list.
Give the desired project name & click on finish.
Now, Once the project is created, we need to create Package.
Right click on project that you have created.  Then go to New -> Package
Enter proper package name -> then click on Finish.
Now, once package is created, we need to create a class  where we can write our automation test cases.
Right click on Package, -> New -> class
Give some class name, then click on finish.
That’s it, now we have created a project along with package and class within it.

Step 3: Configure Selenium jar files in java project

Since now, we have created java project, package & class within it, its time to configure selenium jars within project. Below steps explains how this can be done.
Right click on the project -> Build Path -> Configure Build path
Go to Libraries, Click on Add External Jars -> Select the selenium jars (which you downloaded. Mentioned in step 1)
Click on Apply and OK
This is all done. To verify if your jars are added in to project, Check Referenced library in your project. It should contain all the jar files which you have added.
All set now, you are good to begin with your first test case using selenium
Hope this helps. Drop your comments.

How to read properties file in selenium (java)?

Working with properties file in java / Selenium – 
Hard coding is not a good practice anywhere. It’s hard to go back and change something you’ve hard-coded previously in your code. Suppose you are testing some application. Consider that, its URL keep changing environment to environment, like in UT, UIT, ST, SIT, UAT etc.
Now, your application will be same but URL only will be different.
In this case if you are hard coding URL in your coding, then you need to update the URL whenever it changes.
 Same case would be with Username and password.
So, to overcome situations like this, we usually give these changing parameters in properties file.
You can create the properties file anywhere in the project, just make sure that you give correct path while loading the file.
I
n properties file each entry is stored as a pair of Strings, let us say, Name and value.
Now, let us see, how can we create properties file first of all.
Click on File -> New -> File
 Give some meaningful file name. save the file with “.properties” extension
Once the file is created, Open the file, and have some data, can refer below snap.
Now, the file is created. Let us see how to read this file in our program.
There are 3 simple steps to read file
1. Define FileInputStream & Give your file path of properties file. 

Ex –

File configfile = new File("C:UsersPrakashworkspaceAayush-SeleniumsrccomaayushCorpexternalResourcesConfiguration.Properties");

FileInputStream fis = new FileInputStream(configfile);

2. Load properties file 

For this, create object of properties file & then load.

Properties prop = new Properties();
prop.load(fis);

       3. Retrieve data from properties file.
Use below line to retrieve data.

     PropertyFileValue = prop.getProperty(key);
Below is the complete code, which return the value from properties file based on the key you supply.

import java.io.File;

import java.io.FileInputStream;

import java.io.IOException;

import java.util.Properties;

public class PropertyOperations {

public String getPropertyValueByKey(String key) {

String PropertyFileValue = null;

FileInputStream fis = null;

try {

File configfile = new File(
fis = new FileInputStream(configfile);

} catch (Exception e) {
System.out.println("Configuration file is not found. terminating Process !!!");

System.exit(0);

}

Properties prop = new Properties();

try {

prop.load(fis);

} catch (IOException e) {

e.printStackTrace();

}


Boolean isFileEmpty = prop.isEmpty();


if (isFileEmpty == false) {

PropertyFileValue = prop.getProperty(key);

} else {

System.out.println("Configuration file is empty. Processing is terminated");

System.exit(0);


}

return PropertyFileValue;


}

}

You can create object of this class in any class where you wanted to retrieve the data from properties file. And then retrieve the data by giving key.

Ex – 

PropertyOperations prop = new PropertyOperations();

String username = prop.getPropertyValueByKey("username")

Above piece of code will return username from properties file in to String username.

Post you questions in comment if you have any