Step by step selenium – step 1, How to launch a web browser

Selenium Basic

Introduction – In this blog post, we will see how to run first test in selenium and what are necessary configuration required for invoking browser.

There are 2 basic configuration to invoke a browser.

First step, download and configure selenium standalone jar.

Visit -https://www.seleniumhq.org/download/ , Refer below screenshot.

Config the downloaded jar file in eclipse project-

Second step – Download ChromeDriver, Download location- http://chromedriver.chromium.org/downloads.

Click on ChromeDriver 2.43, Refer below image

download and unzip it,

Now, Open Selenium project and create a class, select main class radio button like below-

Write below code in and execute the same –

package TestNG_Classes;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class Selenium_FirstStep {

/**
* @param args
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub
WebDriver driver ;

// Config step-Setting up chrome driver path
String exePath = "E:\\chromedriver_win32\\chromedriver.exe";
System.setProperty("webdriver.chrome.driver", exePath);

//Creating chrome driver object
driver=new ChromeDriver();

//Maximising window
driver.manage().window().maximize();

//Opening URL
driver.get("http://www.facebook.com/");

}

}

Summary– Above configuration will setup initial selenium configuration which will help user to use all selenium commands and launch chrome browser.

Similarly firefox and Internet explorer browser can be launched. for launching them their browser exe needs to be downloaded like we did for chrome.

Firefox(Geecko) and Internet explorer, download location-https://www.seleniumhq.org/download/
Please refer below code for setting up IE and Firefoxdriver

Use below code in (chrome browser launch code above) Config step-Setting up chrome driver path inabove sample code for launching chrome, if IE or Firefox execution is required.

//For launching Firefox browser
System.setProperty("webdriver.gecko.driver","path of geckodriver.exe");
WebDriver driver = new FirefoxDriver();

//For launching IE
System.setProperty("webdriver.ie.driver", "D://Seleniumdriver\\IEDriverServer.exe")
//Initialize InternetExplorerDriver Instance.

WebDriver driver = new InternetExplorerDriver();

Few Questions/With answers-

What is a selenium webdriver

Answers- Selenium webdriver is an Interface, using WebDriver object, selenium interface helps in accessing selenium API’s

Which language is supported by Selenium or in how many langauges we can write selenium scripts

Answer- It supported following languages-

1- Java
2- C#
3- Python
4- Perl
5- Javascript

In Next post we will see the next step of selenium learning, on how to enter values in text box and click a button.

Its Prashant Chaudhary, I have 10+ years of experience in software test automation, performance & process automation with various commercial and open source tools. This blog shares my experience on the topic of Automation. The content published on my blog is solely mine, it does not express the views of any of my employers (current or previous).
No Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Selenium Basic
2
Step by step selenium – step 4, Finding X-path…1/2

In Selenium test automation, if webobject properties does not have id, name, class then we left with 2 options- Option 1 calculate xpath Option 2 Calculate XssSelector In this post, we will calculate about the xpath and various XPath expression for webobjects whose attributed are changing dynamically. There are 2 …

Selenium Basic
1
Step by step selenium – step 3, what is findelement method

Abstract- So far, we have learned how to launch a web browser, entering values in a text box and clicking button. In this post, we will learn about findelement method. Test automation is all about get and set, which means get from web and set into web. Talking more specifically- …

Selenium Basic
Step by step selenium – step 2 -How to enter value in text box and how to click a button.

Abstract- In Previous post, we have learnt how to launch a web-browser in selenium. In this post we will learn how to enter values in a text box and how to click a button. We will be using chrome browser for this posts well. package TestNG_Classes; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; …

Shares