Thursday, January 14, 2016

Selenium Using Browser and Profiles in RemoteWebDriver

Here I am using the Chrome browser through RemoteWebDriver. I am using the RemoteWebDriver constructor RemoteWebDriver(remoteAddress, desiredCapabilities).
For the Argument remoteAddress I am passing a String parameter using URL constructor and using desiredCapabilities method capability.setCapability(String key, Object value);.
Argument Key is String parameter Capability name and Object is ChromeOptions.
And you can use several ChromeOptions methods


      public static void chromeDriverRemote(RemoteWebDriver driver) {  
           // create a ChromeOptions object  
           ChromeOptions options = new ChromeOptions();  
           // adding a extension to the chrome  
           options.addExtensions(new File("C:\\DRIVE\\My Documents\\Downloads\\AdBlock_v2.46.crx"));  
           // loading a profile to the chrome  
           options.addArguments("user-data-dir=C:\\Users\\sudas\\AppData\\Local\\Google\\Chrome\\User Data\\sudas");  
           // maximize chrome  
           options.addArguments("start-maximized");  
           // Create a DesiredCapabilities object  
           DesiredCapabilities capability = new DesiredCapabilities();  
           // Use the DesiredCapabilities method  
           capability.setBrowserName("chrome");  
           // use the DesiredCapabilities method capability.setCapability(String key, Object value);  
           capability.setCapability(ChromeOptions.CAPABILITY, options);  
           try {  
                // STEP 01  
                driver = new RemoteWebDriver(new URL("http://10.129.63.183:4444/wd/hub"), capability);  
           } catch (MalformedURLException e) {  
                // TODO Auto-generated catch block  
                e.printStackTrace();  
           }  


Selenium using Forefox extension through RemoteWebDriver




No comments:

Post a Comment