How do I launch the browser using WebDriver?

How do I launch the browser using WebDriver?

1 Like

Selenium is the best framework to achieve this

 package newproject;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
//comment the above line and uncomment below line to use Chrome
public class PG1 {

    public static void main(String[] args) {
        // declaration and instantiation of objects/variables
		WebDriver driver = new FirefoxDriver();
		//comment the above 2 lines and uncomment below 2 lines to use Chrome
		//WebDriver driver = new ChromeDriver();
        String baseUrl = "";
        String expectedTitle = "Welcome: Mercury Tours";
        String actualTitle = "";

        // launch Fire fox and direct it to the Base URL

        // get the actual value of the title
        actualTitle = driver.getTitle();

         * compare the actual title of the page with the expected one and print
         * the result as "Passed" or "Failed"
        if (actualTitle.contentEquals(expectedTitle)){
            System.out.println("Test Passed!");
        } else {
            System.out.println("Test Failed");
        //close Fire fox


Try this out with any IDE intellij or eclipse preferably