Saturday, September 15, 2018

How to Configure Webdriver-Selenium for Java in Eclipse on Windows

Components You'll Need

To run WebDriver tests in Java with Eclipse you’ll need:
  • Java
  • Eclipse
  • A test framework (We’ll use JUnit; there are many you can use)
  • WebDriver’s Java bindings
  • WebDriver’s Java Standalone Server library
  • Mozilla’s Gekodriver proxy for Firefox

 Getting Java

WebDriver’s Java bindings require a version of Java on the system you’re running your tests from. WebDriver’s Java bindings require only the Java Runtime Environment (JRE), but you’ll be fine if you have either the Java Development Kit (JDK) or JRE installed.

Download java from - https://www.java.com/en/download/ 






Configure Eclipse


Download Eclipse for from their official website
eclipse IDE  32 or 64 bit.
pic1mu

pic2mu
Download it
Configure Eclipse for Selenium
Extract the downloaded file.
Configure Eclipse for Selenium

Configure Eclipse for Selenium
Open the extracted eclipse-standard folder
Configure Eclipse for Selenium
Open eclipse folder
Configure Eclipse for Selenium
Open Eclipse.exe
Configure Eclipse for Selenium
Configure Eclipse for Selenium

Configure Eclipse for Selenium


Selenium Webdriver is a collection of Java library with some predefined methods.
In Java term collection of library is packed into jar files (Java Achieve file).
Step 1- Open any browser and navigate to  http://docs.seleniumhq.org/download/
Configure Eclipse for Selenium
Step 2- Navigate to Selenium Client & WebDriver Language Bindings Section and download Java library files. These jars will come into zip files that we need to extract
Configure Eclipse for Selenium
Step 3- We will also download the Selenium server, which is known as Selenium RC server
Configure Eclipse for Selenium
Now we are almost done now let us open eclipse and install TestNG also.
Open Eclipse
Configure Eclipse for Selenium
Eclipse home page
Step 2- In eclipse, we have some default plugin available now we will install external software into eclipse.
Click on Help then Install new software

Configure Eclipse for Selenium
Click on help











Step 3-  We have to provide TestNG URL so that eclipse can fetch TestNG plugin

Configure Eclipse for Selenium
Specify the URL

Test NG URL- http://beust.com/eclipse.
Step 4- To get TestNG URL please visit  http://testng.org/doc/download.html and 
copy the below mention URL and paste the same URL in Eclipse and Press Enter

Configure Eclipse for Selenium
Copy download URL
pic18
Select TestNG checkbox
Click on Next

Step 5- Accept the term &condition, and click on finish button.
During installation, it will ask you to restart eclipse so please go ahead to restart eclipse.
pic19

Creating The Project

Eclipse works with the concepts of workspaces—folders and spaces where you work with your projects. In this example, I’m using a small workspace I’ve just created for example projects. Teams use different approaches for workspaces and project structures. Use whatever you like with your own small sample projects; however, make sure to follow your team’s pattern for real work. (Workspace and project structure is almost as hotly debated as tabs versus spaces. Be kind.)
This article uses a simple Java Project created by using the menu File => New => Java Project.
Fill out the basic information on the New Java Project dialog, then click Finish to proceed.

Adding WebDriver to Eclipse

As mentioned earlier, there are many ways to include WebDriver in your Eclipse projects. Most mature teams use a build and dependency management system like Maven or Gradle. This post uses a simple static library inclusion due to the wide variances in how teams organize Maven and Gradle.
Load Libraries Into Eclipse
Download the Java WebDriver bindings and save the zip file to a handy spot. I generally include a “libs” folder in my projects for external libraries like this. In Eclipse right click on the project, then select Build Path => Configure Build Path.
Load libraries into eclipse
In this example we’ll also be using the FirefoxDriver for Mozilla’s browser. That means you’ll also need to download the Selenium Standalone Server, which includes the FirefoxDriver, plus remote drivers if you’ll be using them.
In the Project Properties dialog, select Java Build Path then the Libraries tab. Click Add External Jars, then browse to where you saved the Selenium Java language bindings—the “libs” folder in my example. Select that file and click Open to save your changes.
Position The Browser Driver Proxy
Finally, we’ll need to set up the Firefox driver proxy. Again, there are numerous ways to handle where to place the executable, how to configure it, how to invoke it, etc. These ways also differ for other browser types. (Remember, you likely need similar proxies for other browsers like Chrome, Internet Explorer, or Edge.) In this case, I’ve saved the file “geckodriver” to my ~/Utils folder. Firefox’s Gecko driver requires you to specify its location in code, not just have it on the path. You’ll see that in the sample code below.

SIMPLE TEST

Below is a complete test case that starts a browser locally, executes a very simple test, then closes out the browser instance. The example is extremely simple.
package TestNG;

import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;


public class WebDriver_basics {

 @BeforeMethod
 public static void beforemethod() {
      System.setProperty("webdriver.chrome.driver", "D:\\Seleniumm\\chromedriver.exe");  //path of the geko driver
  ChromeDriver driver = new ChromeDriver(); // constructer called from imported class
  driver.get("https://www.google.com");
 
}
 
 @AfterMethod
 public static void aftermethod() {
      closeBrowser();
 

Introduction to Selenium

Introduction to Selenium 


Q1-What is Automation Testing?

Answer- In Software testing or Quality assurance of any product/application. It's our duty to deliver a bug-free product it means no defect in our product/application. In order to achieve the quality, we perform testing in our product/application. i.e. we perform a set of test cases which can be functional and non-functional test cases.

To save our time and resources, we can automate manual test cases, which can save human effort and time.

For example- We need to test a test case/scenario 50-100 times manually and each time we are checking the same result then its better to automate that test case/scenario and we can run it multiple times to verify the result.

Thanks to Selenium for giving us the liberty to automate our product/application.


Q2- Why Automation testing should be performed?

Answer- We perform automation testing for regression testing, smoke testing, and sanity testing.


Q3- When Automation testing should be performed?

Answer- When we have to execute same test cases on regular basis then its better to automate that test cases.

For example- You have 100 test cases/scenarios that you have to execute on daily basis and you have to test the same test case/scenarios on every release. So, it's better to automate them instead of testing the same manually.


Q4- Which test case avoided automating?

Answer- Well this is the first question asked when automation of test cases comes into the picture.
So, below are the test cases/scenarios-

1- Test cases which change very frequently because if you will automate that test case next time it will fail because the application feature will change so it's better to choose a test case which is stable.

2- Test cases which have manual interaction like entering an OTP, captcha code etc.


Selenium introduction

Selenium is an Open source Web Automation tool which was designed by ThoughtWorks in 2004, It started by Selenium IDE then Selenium RC which is also known as Selenium 1 then Selenium Webdriver which is also known as Selenium 2

Selenium is very popular nowadays because of many reasons

It is an open source tool, which means we do not have to purchase any license for this. We can download from their official website and we can use.

It supports many languages like Java, JavaScript, C#, Python, Ruby etc.

We can perform cross-browser testing as well. Selenium Webdriver support almost all browser which their latest version like Firefox, Chrome, IE, Safari, Opera etc.

It supports the entire platform like Windows, UNIX, Linux, Apple etc.

Recently Selenium has introduced mobile testing as well, now we can automate Android testing using Selendroid, iPhone testing using Appium.


Selenium having compatibility with many tools well some example are AutoIT, Jenkins, Sikuli, Testing, Junit etc.



How to Configure Webdriver-Selenium for Java in Eclipse on Windows

Components You'll Need To run WebDriver tests in Java with Eclipse you’ll need: Java Eclipse A test framework (We’ll use JUnit...