Webdriver++ : A C++ client library for Selenium Webdriver.

Webdriver++

webdriverxx-master.zip

Version 0.7.1 Build Status

A quick example

#include <webdriverxx.h>
using namespace webdriverxx;

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

Features

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

More examples

#include <webdriverxx/webdriver.h> and using namespace webdriverxx are assumed in all examples.

Start browser

#include <webdriverxx/browsers/firefox.h>

WebDriver ff = Start(Firefox());
#include <webdriverxx/browsers/chrome.h>

WebDriver gc = Start(Chrome());
#include <webdriverxx/browsers/ie.h>

WebDriver ie = Start(InternetExplorer());

Use proxy

WebDriver ie = Start(InternetExplorer().SetProxy(
	SocksProxy("127.0.0.1:3128")
		.SetUsername("user")
		.SetPassword("12345")
		.SetNoProxyFor("custom.host")
	));
WebDriver ff = Start(Firefox().SetProxy(DirectConnection()));

Navigate browser

driver
	.Navigate("http://facebook.com")
	.Navigate("http://twitter.com")
	.Back()
	.Forward()
	.Refresh();

Find elements

// Throws exception if no match is found in the document
Element menu = driver.FindElement(ById("menu"));

// Returns empty vector if no such elements
// The search is performed inside the menu element
std::vector<Element> items = menu.FindElements(ByClass("item"));

Send keyboard input

// Sends text input or a shortcut to the element
driver.FindElement(ByTag("input")).SendKeys("Hello, world!");

// Sends text input or a shortcut to the active window
driver.SendKeys(Shortcut() << keys::Control << "t");

Execute Javascript

// Simple script, no parameters
driver.Execute("console.log('Hi there!')");

// A script with one parameter
driver.Execute("document.title = arguments[0]", JsArgs() << "Cowabunga!");

// A script with more than one parameter
driver.Execute("document.title = arguments[0] + '-' + arguments[1]",
		JsArgs() << "Beep" << "beep");

// Arrays or containers can also be used as parameters
const char* ss[] = { "Yabba", "dabba", "doo" };
driver.Execute("document.title = arguments[0].join(', ')", JsArgs() << ss);

// Even an Element can be passed to a script
auto element = driver.FindElement(ByTag("input"));
driver.Execute("arguments[0].value = 'That was nuts!'", JsArgs() << element);

Get something from Javascript

// Scalar types
auto title = driver.Eval<std::string>("return document.title")
auto number = driver.Eval<int>("return 123");
auto another_number = driver.Eval<double>("return 123.5");
auto flag = driver.Eval<bool>("return true");

// Containers (all std::back_inserter compatible)
std::vector<std::string> v = driver.Eval<std::vector<std::string>>(
		"return [ 'abc', 'def' ]"
		);

// Elements!
Element document_element = driver.Eval<Element>("return document.documentElement");

Wait implicitly for asynchronous operations

driver.SetImplicitTimeoutMs(5000);

// Should poll the DOM for 5 seconds before throwing an exception.
auto element = driver.FindElement(ByName("async_element"));

Wait explicitly for asynchronous operations

#include <webdriverxx/wait.h>

auto find_element = [&]{ return driver.FindElement(ById("async_element")); };
Element element = WaitForValue(find_element);
#include <webdriverxx/wait.h>

auto element_is_selected = [&]{
	return driver.FindElement(ById("asynchronously_loaded_element")).IsSelected();
	};
WaitUntil(element_is_selected);

Use matchers from Google Mock for waiting

#define WEBDRIVERXX_ENABLE_GMOCK_MATCHERS
#include <webdriverxx/wait_match.h>

driver.Navigate("http://initial_url.host.net");
auto url = [&]{ return driver.GetUrl(); };
using namespace ::testing;
auto final_url = WaitForMatch(url, HasSubstr("some_magic"));

How to build and run tests

All platforms

Prerequisites for building and running tests:

Linux & Mac

Prerequisites:

  • GCC or clang
git clone http://github.com/sekogan/webdriverxx
cd webdriverxx
mkdir build
cd build
cmake ..
cmake --build .
phantomjs --webdriver=7777 &
http-server ./test/pages --silent &
ctest -V

Windows

Prerequisites:

  • Visual Studio 2010 or newer
git clone http://github.com/sekogan/webdriverxx
cd webdriverxx
mkdir build
cd build
cmake ..
cmake --build .
start phantomjs --webdriver=7777
start http-server ./test/pages
ctest -V

Testing with real browsers

Prerequisites:

selenium-server -p 4444 &
./webdriverxx --browser=<firefox|chrome|...>

Advanced topics

Unicode

The library is designed to be encoding-agnostic. It doesn't make any assumptions about encodings. All strings are transferred as is, without modifications.

경축! 아무것도 안하여 에스천사게임즈가 새로운 모습으로 재오픈 하였습니다.
어린이용이며, 설치가 필요없는 브라우저 게임입니다.
https://s1004games.com

The WebDriver protocol is based on UTF-8, so all strings passed to the library/received from the library should be/are encoded using UTF-8.

Thread safety

  • Webdriver++ objects are not thread safe. It is not safe to use neither any single object nor different objects obtained from a single WebDriver concurrently without synchronization. On the other side, Webdriver++ objects don't use global variables so it is OK to use different instances of WebDriver in different threads.

  • The CURL library should be explicitly initialized if several WebDrivers are used from multiple threads. Call curl_global_init(CURL_GLOBAL_ALL); from <curl/curl.h> once per process before using this library.

Use common capabilities for all browsers

Capabilities common;
common.SetProxy(DirectConnection());
auto ff = Start(Firefox(common));
auto ie = Start(InternetExplorer(common));
auto gc = Start(Chrome(common));

Use required capabilities

Capabilities required = /* ... */;
auto ff = Start(Firefox(), required);

Use custom URL for connecting to WebDriver

const char* url = "http://localhost:4444/wd/hub/";

auto ff = Start(Firefox(), url);

// or
auto ff = Start(Firefox(), Capabilities() /* required */, url);

Transfer objects between C++ and Javascript

namespace custom {

struct Object {
	std::string string;
	int number;
};

// Conversion functions should be in the same namespace as the object
picojson::value CustomToJson(const Object& value) {
	return JsonObject()
		.Set("string", value.string)
		.Set("number", value.number);
}

void CustomFromJson(const picojson::value& value, Object& result) {
	assert(value.is<picojson::object>());
	result.string = FromJson<std::string>(value.get("string"));
	result.number = FromJson<int>(value.get("number"));
}

} // namespace custom

custom::Object o1 = { "abc", 123 };
driver.Execute("var o1 = arguments[0];", JsArgs() << o1);
custom::Object o1_copy = driver.Eval<custom::Object>("return o1");
custom::Object o2 = driver.Eval<custom::Object>("return { string: 'abc', number: 123 }");

Copyright © 2014 Sergey Kogan. Licensed under The MIT license.

 

[출처] https://github.com/sekogan/webdriverxx

본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
38 꼭 필요한 리눅스 명령어, file 졸리운_곰 2019.10.15 411
37 [Ubuntu 18.04] 원격 데스크톱 file 졸리운_곰 2019.02.23 331
36 Tasksel – Easily and Quickly Install Group Softwares in Debian and Ubuntu file 졸리운_곰 2018.10.14 296
35 How to Use the wget Linux Command to Download Web Pages and Files : 리눅스 wget으로 사이트 다운로드(저장) 졸리운_곰 2018.09.12 472
34 우분투 16.04 원격 데스크탑 설정 ubuntu 16.04 xrdp file 졸리운_곰 2018.08.12 495
33 Connect To Ubuntu 16.04 / 17.10 / 18.04 Desktop Via Remote Desktop Connection (RDP) With Xrdp file 졸리운_곰 2018.06.22 254
32 ubuntu 18.04 원격데스크톱 xrdp 그놈접속 : Ubuntu 18.04: Connect to GNOME desktop environment via XRDP file 졸리운_곰 2018.05.13 1442
31 MSI 외장그래픽 노트북에 Ubuntu 설치 : How to Install Ubuntu 16.04 on MSI GE62 6QC 졸리운_곰 2018.05.06 499
30 Ubuntu 16.04에서 Docker 설치 졸리운_곰 2018.05.04 351
29 Docker: Docker image which runs XRDP on Ubuntu 16.04 desktop file 졸리운_곰 2018.05.03 387
28 [리눅스 GUI 하드디스크 상태 모니터링 툴] GSmartControl - A GUI Tool to Check HDD/SSD Health on Linux file 졸리운_곰 2018.01.16 346
27 ubuntu xfce4 rdp에서 MS Code나 Atom 에디터가 안뜰때 졸리운_곰 2017.10.14 251
26 Install Atom Text Editor in Ubuntu 16.04 (both 32&64bit) file 졸리운_곰 2017.10.14 305
25 우분투 서버 윈도우 원격접속(rdp) 설정 졸리운_곰 2017.10.14 431
24 우분투 서버 한글 설정 및 한글폰트 설치 졸리운_곰 2017.10.14 458
23 우분투(Ubuntu)에서 putty로 ssh 원격 접속 실패 해결 방법 file 졸리운_곰 2017.08.27 316
22 우분투 16.04 원격 데스크탑 설정 file 졸리운_곰 2017.07.08 559
21 Ubuntu에서 PATH 설정하기 졸리운_곰 2017.03.22 294
20 [Ubuntu] GUI를 통해 쉽고 빠르게 폴더 공유하기 file 졸리운_곰 2017.02.19 328
19 ubuntu 에서 compiz 화면루틴이 cpu rate 많이 (20%이상) 잡을 때 낮추는 법 졸리운_곰 2017.02.15 243
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED