Koushik
Koushik

Reputation: 156

UI Automation for CefSharp Wpf browser hosted in WPF usercontrol

We have a WPF application where we are using CefSharp browser. The application has some wpf windows within which we are embedding the CefSharp browser control. The problem we have run into is regarding automation. We have tried CUIT(Coded Ui Test) and Selenium already - none is able to identify the control inside the CefSharp browser. We are seeing that CUIT is identifying the CefSharp browser content as an image. Also we tried to expose the automationpeer from CefSharp from the usercontrol in which it is wrapped. However we found that, CefSharp does not expose any automationpeer for WPF - we got back null when tried to grab automationpeer from CefSharp browser control. My question is - is it possible to do automation for a CefSharp browser that is hosted inside a wpf control? If yes, then what should be the approach - any specific technology stack and/or any tweaks to the CefSharp browser control? We are using VS 2015 for the WPF application and CefSharp.Wpf 49.0.1

Upvotes: 3

Views: 2221

Answers (1)

Rajive Pai
Rajive Pai

Reputation: 312

I have solved the problem(Automating CEF# Embedded in a WPF application) by taking the following steps:

Define debugging port in .net application (on start up) that hosts embedded cef web browser:

 var settings = new CefSettings { RemoteDebuggingPort = 8088 };
 Cef.Initialize(settings);

In Protractor(Its like Selenium – another automation tool, which is my favorite)  configuration file this full debugging address "ip:port" should be defined under capabilities

exports.config = {
    seleniumAddress: 'http://localhost:4444/wd/hub',
    specs: ['./tests.spec.js'],
    capabilities: {
        'browserName': 'chrome',
        'chromeOptions': {'debuggerAddress': "127.0.0.1:8088" } 

// debugger Address : An address of a Chrome debugger server to connect to, in the form of <hostname/ip:port>, e.g. localhost:8088

}}
  • Run .net application and enter the screen with the hosted web browser

  • Run protractor configuration.js (This would run tests written in ./tests.spec.js)

Upvotes: 3

Related Questions