HOW TO RUN SELENIUM WEBDRIVER SCRIPT IN FIREFOX BROWSER USING CAPABILITIES?

We can also run the Selenium Webdriver programs in Firefox web browser using capabilities to perform automation testing.

Here is the very basic program to run Selenium Webdriver programs in Firefox web browser using capabilities.




Java Source code:

package com.helloselenium.selenium.test;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;

public class OpenHelloSeleniumBlogInFirefox{

 public static void main(String[] args) { 

  WebDriver driver = null;

  DesiredCapabilities capabilities = DesiredCapabilities.firefox();
  capabilities.setCapability(capability arg1, capability arg2);
  driver = new FirefoxDriver(capabilities);

  driver.get("http://www.helloselenium.com");
  
  driver.quit();
 }

}

Detailed explanation for the above program is as follows:




Following code is the required packages for Selenium Webdriver.
import org.openqa.selenium.WebDriver;
Following code is the required packages for Firefox browser and Selenium remote capabilities.
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;




Following code is to initialize the webdriver.
WebDriver driver = null;
Following code is to define Firefox capability.
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
Following code is to set Firefox capability.
capabilities.setCapability(capability arg1, capability arg2);
Following code is to initialize the firefox driver.
driver = new FirefoxDriver(capabilities);
Following code is to open the hello selenium blog in firefox browser.
driver.get("http://www.helloselenium.com");
You can also use the following code is to open the hello selenium blog in browser.
driver.navigate().to("http://www.helloselenium.com");
Following code is to quit the driver instance.
driver.quit();
You can also use the following code is to close the driver instance.
driver.close();



Post a Comment

0 Comments