Use selenium with C

From the official page of Selenium:

  • The core language-specific client drivers are:
  • Ruby
  • JavaScript
  • Java
  • Python
  • C#

However as per Selenium Official Home Page language bindings for other languages does exist but those projects are not supported, maintained, hosted, or endorsed by the Selenium project, which are as follows:


Solution

You could always write your WebDriver based tests in any of the core language e.g. Java/Python/C# and call the script from your C / C++ application.


Webdriver++

Webdriver++ is a C++ client library for Selenium Webdriver which you have to install and have the following feature support:

  • Chainable commands
  • Value-like objects compatible with STL containers
  • Header-only
  • Lightweight dependencies:
  • libcurl
  • picojson
  • Can be used with any testing framework
  • Linux, Mac and Windows
  • clang (3.4), GCC (4.6) and Visual Studio (2010)

An example:

#include <webdriverxx/webdriverxx.h>
using namespace webdriverxx;

int main() {
    WebDriver firefox = Start(Firefox());
    firefox
    .Navigate("http://google.com")
    .FindElement(ByCss("input[name=q]"))
    .SendKeys("Hello, world!")
    .Submit();
    return 0;    
}

@JimEvans in his comment clearly mentions:

If you really don’t care that you’re not running in a “real” browser, then directly consuming QtWebKit might be a good choice. Realize, though that it’s not a trivial undertaking. There aren’t any C++ language bindings for WebDriver, as far as I know, but as long as you have a JSON parsing library (json-cpp is pretty good), and an HTTP client library, you can write your own language bindings in pretty short order.

Leave a Comment