Skip to content

Latest commit

 

History

History
37 lines (22 loc) · 1.49 KB

File metadata and controls

37 lines (22 loc) · 1.49 KB

Automating-Electron-Using-WebDriver-java

Automating any CEF based application using WebDriver in java, We can achieve this in 4 steps.

1. Setup the Environment

We need chromeDriver, Download from ChromeDriver

2. Start ChromeDriverService

ChromeDriverService service = new ChromeDriverService.Builder()
 .usingDriverExecutable(new File("chromedriver/chromedriver"))
 .usingAnyFreePort()
 .build();
  service.start();

3. Setting DesiredCapabilities for chromeDriver

DesiredCapabilities capabilities = new DesiredCapabilities();
 ChromeOptions options = new ChromeOptions();
 // The address string should be in the form of "hostname/ip:port". 9222 is the port that you specified                        // in the--remote-debugging-port Chromium 
 String remoteDebuggingAddress = "localhost:9222";
 options.setExperimentalOption("debuggerAddress", remoteDebuggingAddress);
 capabilities.setCapability(ChromeOptions.CAPABILITY, options)

4. Create chromeDriver instance

 // Create a WebDriver instance using URL provided by the ChromeDriverService and capabilities
  WebDriver driver = new RemoteWebDriver(service.getUrl(), capabilities);

Note :

If your application have Multiple pages or windows, You can discover available pages by requesting: http://localhost:9222/json and getting a JSON object with information about inspectable pages.