Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web automation from C++

We need to do some fairly complex web automation from C++ application (log into application, do some actions, logout), but performance is really important so we are looking at options.

  1. Is there a way to drive WebKit or other headless engine directly from C++, without the need for few more layers in between (like selenium+webdriver+network communication+...)? Chromedriver perhaps?

  2. If option 1 is not possible, what is the most optimal way to run WebDriver (with real browser) from C++?

like image 744
bozo Avatar asked Jun 27 '13 14:06

bozo


People also ask

Can we use C# for Selenium?

Selenium is an open-source Web UI automation testing suite. It was developed by Jason Huggins in 2004 as an internal tool at Thought Works. It supports automation across different browsers, platforms, and programming languages which includes Java, Python, C#, etc.

Can we use C++ for Selenium?

You can use selenium server and JsonWireProtocol. In C++ you can implement CURL requests to selenium server and do web automation with C++.

Can we automate using C++?

The object-oriented programming language C++ is extremely well suited for writing automation control software. Because it is object-oriented, C++ provides elegant mechanisms for developing reusable interfaces.


2 Answers

You can use selenium server and JsonWireProtocol. In C++ you can implement CURL requests to selenium server and do web automation with C++.

Use this link first: My fork of Webdriver++.

There are also some C++ libraries that do this work. The first is Webdriver++ By sekogan but last commit was 3 years ago, and it seems not all things works for now. The second is my fork of Webdriver++, i've fixed some bugs and make this project as shared library, so you can use it in any C++ project.

This is an example of how you can use my My fork of Webdriver++.

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

int main() {
   WebDriver firefox = Start(Firefox());
   firefox
       .Navigate("http://google.com")
       .FindElement(ByClass("class_name"))
       .SendKeys("Hello, world!")
       .Submit();
   return 0;    
}
like image 106
idurdyev Avatar answered Sep 27 '22 20:09

idurdyev


You should look into PhantomJS (a headless WebKit browser), which comes with GhostDriver, which is the WebDriver protocol implementation for PhantomJS.

You will still need to use one of the WebDriver language bindings, which I'm not aware of any of the language bindings that are in C++, but perhaps one of the available languages could be used by your team for automation purposes.

Worst case, you could always create your WebDriver script in Python, and call the Python script from your C++ application.

like image 28
Nathan Dace Avatar answered Sep 27 '22 20:09

Nathan Dace