Wednesday, October 30, 2013

Import Web Browsers to the web Driver

To begin with the testing first we need to know how we can call the browsers to out java script. There are selected browsers that selenium supports, You can find them in here Third Party Browser Drivers

In this example ill show you how we can play around with the "Chrome, Firefox and IE" browsers since those are the mostly used browsers in the world. 

Firefox Driver 
WebDriver A = new FirefoxDriver(); 

The code given above will create a new object (A) from the "webDriver" class and assigns the "FirefoxDriver" to it.  unlike the other browsers we do not have to set the system properties as it is in build in the Firefox browser itself. 

Chrome Driver
System.setProperty("webdriver.chrome.driver","D://User//ActivePresenter//drivers//drivers//chromedriver.exe");
WebDriver B = new ChromeDriver()

To run scripts with the chrome driver we have to download the supported third party browser drivers from selenium.  (Ref below screen dump)


once you downloaded you have to provide the extracted driver location in the System.setProperty clause.  and just like in the firefox we are creating a new object from the WebDriver class and assigning the chrome driver to it. 

IE Driver
System.setProperty("webdriver.ie.driver","D://Nayana//ActivePresenter//drivers//drivers//IEDriverServer.exe");  
WebDriver C = new InternetExplorerDriver(); 

To run scripts with the Internet explorer driver we have to download the supported third party browser drivers from selenium.  (Ref below screen dump)


once you downloaded you have to provide the extracted driver location in the System.setProperty clause.  and just like in the firefox we are creating a new object from the WebDriver class and assigning the InternetExplorerDriver to it. 

All in one 

WebDriver A = new FirefoxDriver();     
System.setProperty("webdriver.chrome.driver","D://Nayana//ActivePresenter//drivers//drivers//chromedriver.exe");
WebDriver B = new ChromeDriver();    
System.setProperty("webdriver.ie.driver","D://Nayana//ActivePresenter//drivers//drivers//IEDriverServer.exe");  

WebDriver C = new InternetExplorerDriver(); 

I hope this gives a clear idea on how you can import the browser to the web driver, Read my next blog post to see how you can call a url from a given browser.

No comments:

Post a Comment