Launch Chrome, FireFox and IE browsers with Selenium WebDriver

Prerequisites to run Selenium Scripts on Different Browsers:

Programming Language – Java
https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

IDE (Code Editor) -  Eclipse
https://www.eclipse.org/downloads/

Browser Drivers – In order to communicate with actual browsers, selenium need something called driver. Every browser has its own driver.
https://www.seleniumhq.org/download/

Selenium WebDriver Libraries – Libraries which allow you to use all the selenium classes and functions
https://www.seleniumhq.org/download/

Browser – Chrome. Firefox, IE
Application Under Test – Orange HRM (https://opensource-demo.orangehrmlive.com/)


Basic Script:

package launchBrowser;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class FirstSeleniumScriptChrome {

WebDriver driver;

public void launchBrowser() {
System.setProperty("webdriver.chrome.driver", "D://chromedriver.exe");
driver=new ChromeDriver();
System.out.println("Browser is Launched");
driver.manage().window().maximize();
driver.get("https://opensource-demo.orangehrmlive.com/");
System.out.println("Orange HRM url is opened");
}

public void login() {
driver.findElement(By.name("txtUsername")).sendKeys("Admin");
driver.findElement(By.id("txtPassword")).sendKeys("admin123");
driver.findElement(By.id("btnLogin")).click();
System.out.println("User is Logged in");
}

public void title() {
String title=driver.getTitle();
System.out.println("Title of the Page is:"+title);
}

public void logout() throws InterruptedException {
driver.findElement(By.id("welcome")).click();
Thread.sleep(2000);
driver.findElement(By.xpath("//*[@id='welcome-menu']//*[text()='Logout']")).click();
System.out.println("Logged out from Oranage HRM Website");
}

public void closeBrowser() {
driver.close();
System.out.println("Browser is Closed");
}

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

FirstSeleniumScriptChrome obj= new FirstSeleniumScriptChrome();
obj.launchBrowser();
obj.login();
obj.title();
obj.logout();
obj.closeBrowser();

}

}


Please follow below youtube videos for more details...

First Selenium WebDriver Script with Chrome Borwser:


Selenium WebDriver Script with IE Borwser:


Selenium WebDriver Script with FireFox Borwser:


1 comment: