Learn Selenium and Java for Selenium

Tuesday, 24 May 2016

Automation Framework


Author : Ashwini Velapure (Test Automation Engineer) https://www.linkedin.com/in/ashwinivelapure

What is Automation Framework?
In simple words ,it is nothing but structure of code.
While starting for Automation Testing ,we need to have clear understanding for different types of  automation framework.
Types of Automation Framework:

  • Linear  FrameWork:
It is just sequential code. Steps  are collected one by one. More hard coding of values is one of the  drawback  of linear framework.
In selenium IDE, we can record flow. If we extract testcase,We will get  the java  code.You will get piece of code,which we can say linear automation framework.
For example, if we are automating Login application.Within linear frame work we will follow below steps:
a) Open URL for login page.
b) Enter the details.
c)  Click on Login.
d) Verify the home page

  • Modular Framework
In modular framework,there is dedicated doe for particular functionality, which can be called as ‘Module’.
For achieving this modularity, we are using JAVA,VB etc.
For example, if we are automating Login application and we need to save screenshots.
Within Modular frame work we will have separate  module for take Screenshot. This module will have code for taking screenshot and saving it on desire location
Whenever we land on page we will call take Screenshot  module
Steps :
a)Load Login Page
b)Call take Screenshot
c) Enter the details.
d) Click on Login.
e) Call takes Screenshot

  • Data Driven Framework:
When an application need to test with different set of data, Data driven Frame wok comes into picture.
For example:
If we are automating any login application and we need to check with different username and password. In this scenario we can keep separate data sheet for username  and password. Here we can use JXL/Apache POI for reading data sheet

  • Keyword Driven Framework:
It is similar data driven. Here we are reading keyword from data sheet instead of test data. This keyword may have one of the module associate with it.

  • Hybrid Framework
Hybrid Framework is combination of Data Driven framework and Modular Framework. This is commonly used framework.

  • TestNG Framework
This is advanced framework. It is famous for its reporting feature. We had  already had discussion on the previous blogs

Why Automation  Framework?
Definite structure of code  is very important ,below are some advantages:

  • Reusability
  • Maintainability
  • Readability
  • Scalability
How to select Type of Framework?

  • Based on Complexity of Web Application
This complexity can be determined  by number of pages and their web elements.
Also Number of scenarios incorporated for particular web application workflows.
So, for less complex application we can go with Data Driven FrameWork and for more complex application we can Hybrid framework

  • Based on Reporting requirement
Most of the Business people are not bother with code sctructure.They are only interested in Output.
So, reporting comes into the picture.TestNG  framework gives excellent reporting feature.





Sunday, 22 May 2016

TestNG| Creating the First Case

How to create Test Case using TestNG?

Creating TestCase is simple using TestNG. The main motive to create a Test Case using TestNG is because of it powerful framework and to avoid main() method.

Steps to create a TestNG  Test case

  • Ensure TestNG is correctly configured in Eclipse(Install TestNG)
  • Import the Package import org.testng.annotations.* in the respective Class
  • Use Annotation @ Test to run a particular Test Case
  • Run the Program  as TestNG
Running the Program as a TestNG


The below diagram depicts the flow of Running of Test Cases in accordance to Annotations used

Flow of Running the Test NG Cases 

 import java.io.File;  
 import java.io.IOException;  
 import org.apache.commons.io.FileUtils;  
 import org.openqa.selenium.By;  
 import org.openqa.selenium.JavascriptExecutor;  
 import org.openqa.selenium.OutputType;  
 import org.openqa.selenium.TakesScreenshot;  
 import org.openqa.selenium.WebDriver;  
 import org.openqa.selenium.WebElement;  
 import org.openqa.selenium.chrome.ChromeDriver;  
 import org.openqa.selenium.firefox.FirefoxDriver;  
 import org.testng.annotations.*;  
 public class TestNGProgram {  
      public WebDriver driver;  
      @BeforeClass   
      public void setup()  
      {  
           this.driver=new FirefoxDriver();  
      }  
      @AfterClass  
      public void teardown()  
      {  
           this.driver.quit();  
      }  
      @Test  
      public void loadpage()  
      {  
           driver.get("https://www.facebook.com/");  
           String s =driver.getTitle();  
           System.out.println(s);  
      }  
 }  



Notes
  1. this is a keyword in Java that can be used to refer current class instance variable hence it used to access the driver variable.
  2. Order of execution of above tests annotation is @BeforeClass>@test>@AfterClass
  3. There is no need to write main() method
  4. Title of facebook page is fetched using getTitle() method
Output



Saturday, 21 May 2016

Reading a Excel File using Apache POI


Author : Ashwini Velapure (Test Automation Engineer) https://www.linkedin.com/in/ashwinivelapure

Steps to Read the Excel File

  • Specify the Location of File
  • Load WorkBook
  • Load Sheet: Sheet can be loaded via getSheetAt() method , sheet name /index can be passed as argument.By default Sheet1 has zero index and so on
  • Load Cell: There are 2 methods offered by XSSFSheet class , one is get row() and the other is get Cell() ,the row number and the column number are passed as an argument respectively
  • Read Data
 import java.io.File;  
 import java.io.FileInputStream;  
 import java.io.IOException;  
 import java.util.Iterator;  
 import org.apache.poi.ss.usermodel.Row;  
 import org.apache.poi.xssf.usermodel.XSSFCell;  
 import org.apache.poi.xssf.usermodel.XSSFRow;  
 import org.apache.poi.xssf.usermodel.XSSFSheet;  
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;  
  public class ReadFile {  
      public static void main(String[] args) throws IOException {  
           // TODO Auto-generated method stub  
           FileInputStream file = new FileInputStream(new File("C:\\Users\\Ashish Banka\\Downloads\\Test1.xlsx"));  
           XSSFWorkbook workbook = new XSSFWorkbook(file);    
           XSSFSheet sheet = workbook.getSheetAt(0); //Read Sheet 1,   
           String S= sheet.getRow(0).getCell(0).getStringCellValue();  
           System.out.println(S);  
      }  
 }  

Notes

1-Eclipse support one forward slash or two backward slash ,so we have used two backword slash in order to locate the file
2- XSSFWorkbook is a class so we have created one reference variable "workbook" in order to access the method of this class which is getSheetAt()
3- As we know XSSFWorkbook is a class, its object can be created via new XSSFWorkbook(File)
4-getStringCellValue () method return a string value of Cell so we have stored in a string called "s"

Output


Output of Excel File displaying Row 0 and Column 0 value

Excel Sheet


Excel File used for Reading


Friday, 20 May 2016

What is Apache POI and how to Download it


Author : Ashwini Velapure (Test Automation Engineer) https://www.linkedin.com/in/ashwinivelapure

APACHE POI

What is Apache POI?
Apache POI is a powerful Java library to work with different Microsoft Office file formats such as Excel, Power point, Visio, MS Word etc.

In this API we can handle different types of excel files. Most of the interviewer don’t satisfied with only JXL.It is good to know about APACHE POI
Here, we go for Apache POI.


STEPS FOR GETTING APACHE POI:
  • Download ‘poi-bin-3.14.tar’ file from https://poi.apache.org/download.html

  • Extract the above .tar file to any folder
  • Right Click on Eclipse Project->Build Path->Configure Build Path->Libraries->Add external jar.
  • The following jar files needs to be added
    
    • Under ooxml-lib folder
         
    • Under lib folder
            
  • Brows all the above the poi jar file and add it
  • Here you can access the all Apache POI classes.



Friday, 6 May 2016

TestNG :Annotations Basic Concept

Annotations and its usage in Test NG

TestNG supports a series of annotations which are invoked when running the code. The Annotations is the powerful feature provided by TestNG in order to avoid using the Main() method.

Following are most commonly used annotations in Test NG

@BeforeSuite :-Annotates methods that will be run before any method in a given is run.

@BeforeGroups:-Annotates methods that will be run before the first method in any of the specified groups is run.

@BeforeClass:- Annotates methods that will be run before the first method on the current test class is run.

@BeforeTest:- Annotates methods that will be run before any method in a given is run

@BeforeMethod:-Annotates methods that will be run before each test method

@AfterMethod:-Annotates methods that will be run after every test method.

@AfterTest:-Annotates methods that will be run after all the test methods in a given have been run.

@AfterClass:- Annotates methods that will be run after the last test method on the current class is run.

@AfterGroups:-Annotates methods that will be run after the last test method belonging to the groups specified in its value attribute has been run. The annotated method is automatically put into these specified groups.

@AfterSuite:- Annotates methods that will be run after all the test methods in a given have been run.

@ Test : Annotates method as a Test Case

Note: While Running a Test Case with @ Test Annotation there is no need to write main() method


Sunday, 1 May 2016

TestNG and its Installation

What is TestNG?


TestNG is a testing framework for the java programming language inspired by JUnit and NUnit.The design goal is to cover wide range of Testing: Unit,Functional ,Regression etc.


Advantages of TestNG

  • TestNG supports many powerful features & it is easy to use. Let’s see what all new features are supported in new testing framework:
  • Support for parameters.
  • Supports dependent methods testing.
  • Test configuration flexible.
  • Supports powerful execution model.
  • TestNG has a more elegant way of handling parameterized tests with the data-provider concept.
  • For the same test class TestNG support for multiple instances.
  • Extendibility of using different Tools and plug-ins like Eclipse, Maven, IDEA etc.
  • Default JDK functions for runtime and logging (no dependencies).
  • Supported different Annotations like @BeforeSuite, @AfterSuite, @BeforeClass, @AfterClass, @BeforeTest, @AfterTest, @BeforeGroups, @AfterGroups, @BeforeMethod, @AfterMethod, @DataProvider, @Factory, @Listeners, @Parameters, @Test.
  • TestNG allows us to generate test reports in both HTML and XML formats.

How to Install TestNG and configure it in Eclipse?

Steps for installation:

1. Click Help –> Install New Software










2. Type “http://beust.com/eclipse” in the “Work with” edit box and click ‘Add’ button

3. In the ‘Name’ column we can see “TestNG” –> Select this and click ‘Next’ button




4. Click Next and click on the radio button “I accept the terms of the license agreement”

5. Click ‘Next’ button

6. Click ‘Finish’




This will install the TestNG plug-in for Eclipse

After the installation, it will ask for restart of Eclipse. Then restart the Eclipse.

Once the Eclipse is restarted, we can see the TestNG icons & menu items as in the below figures.








Creating Object Repository Using Properties file in Selenium Webdriver

What are Properties file and why we need it?

In Selenium web driver there is not any build in facility to create object repository, so maintenance of page objects becomes very hard if we write all objects of page on code level.So we can create Properties file support of java software in order to store the object X-Path/Id of a location of web element in this file

How to create a Properties file?

Step 1-Right click on project package ->New->Other



Step 2 :- On New Wizard window ,expand general Folder and select file and click on Next Button

Step 3:- Give the file name as Object.Properties and click on Finish button, which will add the Properties file under a Package



Step 4:

Double Click  on Properties file to add the X-Path of the "Login" button of the Facebook page

X-path of Login button of Facebook


The below code Read X-Path of "Login" button from the Properties file and then click on "Login" Button of Facebook

 import java.io.File;  
 import java.io.FileInputStream;  
 import java.io.IOException;  
 import java.util.Properties;  
 import org.apache.commons.io.FileUtils;  
 import org.openqa.selenium.By;  
 import org.openqa.selenium.OutputType;  
 import org.openqa.selenium.TakesScreenshot;  
 import org.openqa.selenium.WebDriver;  
 import org.openqa.selenium.chrome.ChromeDriver;  
 import org.openqa.selenium.firefox.FirefoxDriver;  
 import org.testng.annotations.Test;  
   
   
   
 public class ReadPropertiesfile {  
        
 public static void main(String[] args) throws IOException {  
             
 WebDriver a= new FirefoxDriver();  
 a.manage().window().maximize();  
 a.get("http://www.facebook.com");  
             
 //Create Object of Properties Class.  
 Properties obj = new Properties();   
 //Create Object of FileInputStream Class. Pass file path -  
 FileInputStream objfile = new FileInputStream(System.getProperty("user.dir")+"\\src\\Object.Properties");   
 //Pass object reference objfile to load method of Properties object  
  obj.load(objfile);  
              
 //Accessing element locators of all web elements using obj.getProperty(key)  
 a.findElement(By.xpath(obj.getProperty("Sumbit"))).click();   
 a.quit();  
             
 }  
 }  


Notes

1-FileInput Stream is a class offered by java to read data from a file
2- Properties Class offers a load(InputStream Is) which loads data from InputStream Object which is objfile
3- getProperty("user.dir") will return the current project directory/ to get the path of the workspace

Output



Sunday, 24 April 2016

Write Data in Excel using Selenium JXL

How Selenium supports Writing of Excel File?

Writing of Excel file can be achieved with the help of API called JXL. Currently JXL only support xls type file.

Steps to download jxl2.6 jar file and configure in the Project

Step1: Go to the URL:-http://www.findjar.com/jar/net.sourceforge.jexcelapi/jars/jxl-2.6.jar.html and down load the jar file
Step 2: Extract the jar file at the location of download
Step3: On Eclipse>Go to Project and right Click on it >Go to build path>Select Configure build pat>Under Libraries ,click on Add External Jar to add the Jar file

Steps to Write data into the Excel File

  • Specify the Location of File where file is to be stored
  • Create WorkBook
  • Create Sheet
  • Get Sheet
  • Add Cell Data 
  • Write WorkBook
  • Close WorkBook

 import java.io.File;  
 import java.io.IOException;  
 import org.apache.commons.io.FileUtils;  
 import org.openqa.selenium.By;  
 import org.openqa.selenium.OutputType;  
 import org.openqa.selenium.TakesScreenshot;  
 import org.openqa.selenium.WebDriver;  
 import org.openqa.selenium.chrome.ChromeDriver;  
 import org.openqa.selenium.firefox.FirefoxDriver;  
 import org.testng.annotations.Test;  
 import org.testng.asserts.*;  
 import jxl.Workbook;  
 import jxl.read.biff.BiffException;  
 import jxl.write.*;  
 public class WriteExcel {  
      public static void main(String[] args) throws BiffException, IOException, WriteException {  
           File f = new File("D:/WriteData.xls");//Give a File Path  
           WritableWorkbook w = Workbook.createWorkbook(f);//Create WorkBook  
           w.createSheet("ashish", 0);//Create Sheet  
           WritableSheet s =w.getSheet(0);//Get Sheet  
           //Add Cell Data  
           Label data = new Label(0,0,"Test");  
           s.addCell(data);  
           //Write WorkBook  
           w.write();  
           //Close WorkBook  
           w.close();  
      }  
 }  

Notes

1-Eclipse support one forward slash or two backward slash ,so we have used forward slash in order to create the file
2-createWorkbook method() creates a work book
3-WritableWorkbook class has a method createSheet() which is used to create a sheet within a workbook, this method has a parameter 1 as "Name of Sheet" which is ashish in this case and parameter 2 as index of sheet: Here index of first sheet is zero
4-Label is a class provided by JXL which creates a cell when added to a sheet.Its Parameters are
    a) Parameter 1: Column number
    b) Parameter 2: Row number
    c) Parameter 3: Content to be added in cell
5-WritableSheet class has a method called addCell which is used to add cell data to the specified location mentioned in Label


Excel Sheet Output



Excel File Created Using JXL






Saturday, 23 April 2016

Read Excel file in Selenium using JXL

How Selenium supports reading of Excel File?

Reading of Excel file can be achieved with the help of API called JXL. Currently JXL only support xls type file.

Steps to download jxl2.6 jar file and configure in the Project

Step1: Go to the URL:-http://www.findjar.com/jar/net.sourceforge.jexcelapi/jars/jxl-2.6.jar.html and down load the jar file
Step 2: Extract the jar file at the location of download
Step3: On Eclipse>Go to Project and right Click on it >Go to build path>Select Configure build pat>Under Libraries ,click on Add External Jar to add the Jar file


Steps to Read the Excel File

  • Specify the Location of File
  • Load WorkBook
  • Load Sheet: Sheet can be loaded via getSheet() method , sheet name /index can be passed as argument.By default Sheet1 has zero index and so on
  • Load Cell: getCell() method used with 2 arguments, first argument points to column of excel sheet and second argument points to row of excel sheet 
  • Read Data

 import java.io.File;  
 import java.io.IOException;  
 import org.apache.commons.io.FileUtils;  
 import org.openqa.selenium.By;  
 import org.openqa.selenium.OutputType;  
 import org.openqa.selenium.TakesScreenshot;  
 import org.openqa.selenium.WebDriver;  
 import org.openqa.selenium.chrome.ChromeDriver;  
 import org.openqa.selenium.firefox.FirefoxDriver;  
 import org.testng.annotations.Test;  
 import org.testng.asserts.*;  
 import jxl.Workbook;  
 import jxl.read.biff.BiffException;  
 public class ExcelRead {  
      public static void main(String[] args) throws BiffException, IOException {  
           File f = new File("D:/TestTest.xls");  
           Workbook w = Workbook.getWorkbook(f);  
           String c =w.getSheet("Sheet1").getCell(0, 0).getContents();  
           System.out.print(c);  
      }  
 }  

Notes

1-Eclipse support one forward slash or two backward slash ,so we have used forward slash in order to locate the file
2- Workbook is a class so we have created one reference variable "w"
3- getWorkbook() is a static method which is used to load the Work Book.As getWorkbook() is a static method it has been called by its class name
4-getContents() method return a string value so we have stored in a string called "c"

Output

Column 0 and Row 0 value of Excel file has been Printed 
Excel Sheet
Excel Sheet Used




Handling Keyboard Events in Webdriver

What are keyboard events?

Keyboard events are actions that can be performed with keyboard such as Alt F4, Shift "A", Control+Alt+Delete.There may be scenarios were we need to perform typing like a keyboard in certain fields

How Selenium handles keyboard events?

Selenium offers Action class in order to handle the keyboard events.The Action is a user facing API for emulating complex user action events.

There are different methods that are offered by Action Class. Most commonly used for keyboard events are
  • keyDown()- Press down a particular Key in keyboard, It can be Caps Lock or Shift button or any key present on keyboard
  • KeyUp()- UnPress the a particular key in keyboard.  It can be Caps Lock or Shift button or any key present on keyboard 
Here is the code snippets for using the Actions

//Configure the Action
Action builder=new Action(driver)

//To press a particular key(e.g Shift key)
builder.keydown(keys.SHIFT)


The below types a capital letter text on Email id field present on the facebook page


 import java.io.File;  
 import java.io.IOException;  
 import java.util.concurrent.TimeUnit;  
 import org.apache.commons.io.FileUtils;  
 import org.openqa.selenium.By;  
 import org.openqa.selenium.JavascriptExecutor;  
 import org.openqa.selenium.Keys;  
 import org.openqa.selenium.OutputType;  
 import org.openqa.selenium.TakesScreenshot;  
 import org.openqa.selenium.WebDriver;  
 import org.openqa.selenium.WebElement;  
 import org.openqa.selenium.chrome.ChromeDriver;  
 import org.openqa.selenium.firefox.FirefoxDriver;  
 import org.openqa.selenium.interactions.Action;  
 import org.openqa.selenium.interactions.Actions;  
 import org.testng.annotations.Test;  
 import org.*;  
  public class KeyboardEvents  
 {  
      public static void main(String[] args) {  
           WebDriver a = new FirefoxDriver();  
           a.manage().window().maximize();  
           a.get("http://www.facebook.com");  
           a.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);  
           Actions builder = new Actions(a);  
           WebElement e=a.findElement(By.id("email"));  
           Action writeCapital=builder.keyDown(Keys.SHIFT).sendKeys(e, "abc").keyUp(Keys.SHIFT).build();  
           writeCapital.perform();  
      }  
 }  


Notes

1-WebElement is a class in Selenium which is currently used to store the email field location
2-Action class offers keyDown method which is used to press down a particular key
3-.build() method is used to combine different keys method in a single command.For example in below case we are pressing some key then sending some value to the field and then unpress the same key, so 3 different types of action took place in order to combine them build() method is used
4-Perform method is used here to execute the action.

Output


Capital "ABC" is typed on email id field

Friday, 22 April 2016

Handling Mouse Events in Webdriver

What are mouse events?

Mouse events are actions that can be performed with mouse such as double click, drag and drop, click and hold.There may be scenarios were we need to perform mouse hover to see the calender etc..

How Selenium handles mouse events?

Selenium offers Action class in order to handle the mouse events.The Action is a user facing API for emulating complex user action events.

There are different methods that are offered by Action Class. Most commonly used for Mouse events are


  • clickAndHold()- Click without releasing the current mouse location
  • contentClick() - Perform a context click at current mouse location
  • dobleClick()- Perform a double click at current mouse location
  • dragAndDrop(source,target) -Performs click and hold at the location of the source element and moves to the location of target element then releases the mouse
Here is the code snippets for using the Actions

//Configure the Action
Action builder=new Action(driver)

//To focus on element using Webdriver
builder.moveToElement(element).perform()

//To click on the element to Focus
builder.moveToElement(element).click().perform()

The below program focus on element using Action Class


import java.io.File;  
 import java.io.IOException;  
 import java.util.concurrent.TimeUnit;  
 import org.apache.commons.io.FileUtils;  
 import org.openqa.selenium.By;  
 import org.openqa.selenium.JavascriptExecutor;  
 import org.openqa.selenium.OutputType;  
 import org.openqa.selenium.TakesScreenshot;  
 import org.openqa.selenium.WebDriver;  
 import org.openqa.selenium.WebElement;  
 import org.openqa.selenium.chrome.ChromeDriver;  
 import org.openqa.selenium.firefox.FirefoxDriver;  
 import org.openqa.selenium.interactions.Actions;  
 import org.testng.annotations.Test;  
 import org.*;  
  public class MouseEvents  
 {  
      public static void main(String[] args) {  
           WebDriver a = new FirefoxDriver();  
           a.manage().window().maximize();  
           a.get("http://www.seleniumhq.org/");  
           a.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);  
           Actions builder = new Actions(a);  
           WebElement e=a.findElement(By.id("menu_projects"));  
           builder.moveToElement(e).perform();  
      }  
 }  


Notes

1-WebElement is a class in Selenium which is currently used to store the Project button location
2-Action class offers moveToElement which is used to move the mouse to location stored in WebElement
3-Perform method is used here to execute the action.

Output


Project Tab is highlighted

Sunday, 17 April 2016

Generate Logs in Selenium


What are Log files?

Log files are check points that can be added at any step of code.Logs gives us detailed reasoning of any step failure .To see logs we first need to download Log4j jar file.

Steps to Configure Log4j in Selenium

1-Go to http://www.java2s.com/Code/Jar/a/Downloadapachelogginglog4jjar.htm
2-Download apache-logging/apache-logging-log4j.jar.zip( 435 k) and extract Jar File and Store it 
3-Go to Selenium>Right Click of Project Name>Click on Properties>Select Java Build Path>Go to Libraries>Add External jar and open and select the Log4j jar from the location it was saved
4- Open a notepad, Copy and Paste the code below and save the filename as Log4j.Properties with double quotes("") on it on the Project Location 

// Here we have defined root logger
log4j.rootLogger=INFO,CONSOLE,R,HTML,TTCC

// Here we define the appender
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.TTCC=org.apache.log4j.RollingFileAppender
log4j.appender.HTML=org.apache.log4j.FileAppender

// Here we define log file location
log4j.appender.R.File=./log/testlog.log
log4j.appender.TTCC.File=./log/testlog1.log
log4j.appender.HTML.File=./log/application.html

// Here we define the layout and pattern
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern= %5p [%t] (%F:%L)- %m%n
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d - %c -%p - %m%n
log4j.appender.TTCC.layout=org.apache.log4j.TTCCLayout
log4j.appender.TTCC.layout.DateFormat=ISO8601
log4j.appender.HTML.layout=org.apache.log4j.HTMLLayout
log4j.appender.HTML.layout.Title=Application log
log4j.appender.HTML.layout.LocationInfo=true


Properties file is configured on the Project Location

The below code will generate Log info after each Steps of code execution



Notes
1-An object "L" of Logger Class has been created to generate Log Statements
2-Class name has been passed to the getLogger method because it is easy to trace the logs in case of Multiple Classes being used in a Project. See output >NotePad file a class Name is mentioned in the Log
3-Properties file of Logs has been configured in with the use of PropertyConfigurator.configure("Log4j.Properties") code



Output


Log File Created on the Project Folder

Log Info Details in NotePad

 








Setting up a Selenium Webdriver Project

How To Setup a Selenium WebDriver Project in Eclipse ?

Creating a Simple Selenium – Java project in Eclipse

This post will help the selenium users-Beginners to setup the selenium project and execute a simple WebDriver script
Steps To Create a Selenium Project in Eclipse


Step 1: Download Eclipse



Step 2: Creating a New Java Project in Eclipse IDE



Step 3: Enter a Project Name E.g:SampleDemo

Step 4: Creating a New Package
Right Click on the New Java Project created → New→ Package

Step 5: Type In a New Package Name E.g:com.selenium.example

Step 6: Creating a New Java Class file.
Right Click on the Newly created Package → New → Class

Step 7:Type In a Name for your Java Class file,
click on the check box for “public static void main (String args[])”
Click on Finish


Step 8: The Java class file is created and ready for Java Scripting.

Now, We need to add the Selenium Library files to our project
Step 9: Download the selenium server from the seleniumhq.org website.

Step 10: Click on Downloads Tab and then click on the link as highlighted in the screenshot

Step 11: Save the jar file in a specific Location E.g C:/Selenium

Step 12: Configuring Build Path.
Right Click on the package → Build Path → Configure Build Path

Step 13: Click on Libraries tab → Add External Jar’s

Step 14: The jar files should be loaded from the C:/Selenium folder (or where you have saved the downloaded Jar file from Seleniumhq website) to our Eclipse Workspace and should look as in the screenshot

Step 15:We can also verify by expanding the Referenced Libraries in the Project Explorer that, whether the Jar file is added properly

Step 16: Now, our Eclipse is ready for Selenium Scripting :-)
Web Driver object initialization as WebDriver driver=new FirefoxDriver();
As in the below Screenshot

You may see errors, but that’s not a problem here is how we resolve it.


Step 17: Mouse Hover near the WebDriver error line you will see an Auto suggest Option, you will find Import WebDriver.
Click on Import WebDriver –Now the error will be vanished.

Step 18: Now Mouse Hover near the Firefox Driver, and you will get an autosuggest option.
Click on the Import FirefoxDriver option the suggested list


You can also eliminate the steps 15,16,17 by manually adding the below Import statements
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
And, that’s it we are done with Selenium Project setup in Eclipse.

Popular Posts

Recent Posts



Newsletter

Join our newsletter to get secret tips directly in your inbox!


*We Hate Spam!

Powered by Blogger.