Launching Browsers In Selenium- Facts You Should Know

In this segment of tutorial we will be learning how to do Selenium installation and also will be launching browsers in Selenium with hands-on such we will launch Firefox, Chrome, IE browsers and navigate to the Application URL (for an example we will launch www.Google.com to start with). 

In the previous section ie Module one of the tutorial we have learnt about Selenium Architecture , Selenium internal features and functionalities.

Selenium Installation: 

To Work with Selenium you have to undergo the following process , which are :

Install Java in the System: 

You can download updated version of JDK from Oracle.com, and install the Java in your system after downloading by following the steps.

Next step is you need to set the JAVA_HOME path from an environment variable (by copying the path of downloaded directories till bin folder)and also update the PATH variable of your system variables.

To validate whether the above steps are done properly go to command prompt and do java – version, it should show you the installed version of the JDK.

Setup IDE, i.e. Eclipse or Intellij:

You can choose your favourite IDE for coding the Automation scripts, Develop the Automation framework, etc., you can choose Eclipse or Intellij community edition for this purposes.

Download the Selenium Webdriver jar file from Selenium Dev.

Setup Selenium in the IDE (Eclipse)

Once you downloaded your favourite IDE, then open that (Eclipse or Idea ) and create a new Java project. Provide a name of the project and create package inside the newly created project, then create a Java class with a proper name (e.g. DemoTest.java, etc.).

Once the above steps are completed then you have to add the Selenium Jar that you have downloaded from Selenium DEV  in the Java Build Path Libraries in Eclipse to work with Selenium in the following way:

STEP 1—> Right-click on the Project, go to the properties option. Click on Java Build Path in the newly opened dialog box.

STEP 2 —> Click on the libraries option and then click on Add External Jars and select your Selenium JARs whichever you have download, in this way you can add any other externally downloaded JAR in your IDE workspace.

Launching Browsers In Selenium Webdriver:

With these above sections we are done the Selenium Installation or Setup process, now in the upcoming section, we will do hands-on Launching Browsers In Selenium with different browsers such as Firefox browser, Chrome Browser, IE browser, Safari Browsers etc. 

How to launch firefox browser in Selenium Webdriver:

To work with Firefox, you would require to download the GeckODriver which is basically the browserdriver for Firefox.

STEP 1 —> Download the geckodriver.exe file from GeckoDriver Github Release Page, while you download the file make sure you download the version based on on your Operating System.  

STEP 2 —> Set the driverbrowser path for geckodriver.

Code Snippets to Launch firefox browser in Selenium java

  System.setProperty("webdriver.gecko.driver", "pathToGeckoDriver exe");
  return new FirefoxDriver();

The above code is for returning the FirefoxDriver , if you want to launch the firefox driver .

Here is the below code in a public static void main format which launch the firefox browser using selenium and also navigate to the web-application under test.

public static void main(String[] args){
    System.setProperty("webdriver.gecko.driver", "pathToGeckoDriver exe");
    WebDriver driver=new FirefoxDriver();
    driver.get("Application URL");
}

How to launch chrome browser in selenium webdriver

Similarly to work with Chrome Browser with Selenium, you have to download the Chromedriver file and set the driver browser path from your script. 

System.setProperty("webdriver.chrome.driver","pathToDriver exe");
return new ChromeDriver();

Again the above code is for returning the ChromeDriver instance if you want to launch the Chrome browser with Selenium.

Here is the below code in a public static void main format which launch the Chrome browser using selenium and also navigate to the web-application under test.

public static void main(String[] args){
    System.setProperty("webdriver.chrome.driver", "pathToChromeDriver exe");
    WebDriver driver=new ChromeDriver();
    driver.get("Application URL");
}

How to launch ie in selenium Webdriver : 

Similarly to work with IE Browser with Selenium you have to download the IE file and set the driver browser path from your script.

Here is the below code snippet for launching IE browser in Selenium:

public static void main(String[] args){
    System.setProperty("webdriver.ie.driver", "pathToInternetExplorer Driver exe");
    WebDriver driver=new InternetExplorerDriver();
    driver.get("Application URL");
}

How to launch safari in selenium Webdriver:

To work with Safari Browser with Selenium you can follow the below code snippet . 

public static void main(String[] args){
    WebDriver driver =new SafariDriver();
    driver.get("Application URL");
}

How to launch edge browser in selenium : 

First Download the Edge Driver Exe file and set the path using System.setProperty like previously what we had done for other browser and then return the edge browser.

Here is the below code snippet for launching the Edge Browser in Selenium 

public static void main(String[] args){
    public static void main(String[] args){
        System.setProperty("webdriver.edge.driver", "pathToEdge Driver exe");
        WebDriver driver=new EdgeDriver();
        driver.get("Application URL");
    }
}

Conclusion: With this Section of the tutorial, we are have learnt how to install Selenium and Launching Browsers In Selenium and open with the Application URL.

Leave a Comment