Overview

ChromeDriver and Selenium are tools for automated testing of Chromium-based applications. The tests themselves can be written in a number of languages including Java, JavaScript and Python. ChromeDriver communicates with the Chromium-based application using the DevTools remote debugging protocol (configured via the --remote-debugging-port=XXXX command-line flag passed to the application). Detailed ChromeDriver/Selenium usage information is available here:

https://sites.google.com/a/chromium.org/chromedriver/getting-started

https://code.google.com/p/selenium/wiki/GettingStarted

Java Tutorial

This tutorial demonstrates how to control the cefclient sample application using the Java programming language on Windows. Usage on other platforms and with other CEF-based applications is substantially similar.

  1. Install the Java JDK and add its bin directory to your system PATH variable.

  2. Create a directory that will contain all files. This tutorial uses c:\temp.

  3. Download ChromeDriver from https://sites.google.com/a/chromium.org/chromedriver/downloads and extract (e.g. chromedriver_win32.zip provides chomedriver.exe). This tutorial was tested with version 2.14.

  4. Download selenium-server-standalone-x.y.z.jar from http://selenium-release.storage.googleapis.com/index.html. This tutorial was tested with version 2.44.0.

  5. Download a CEF binary distribution client from Downloads and extract (e.g. cef_binary_3.2171.1979_windows32_client.7z).

  6. Create Example.java:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions; public class Example {
public static void main(String[] args) {
// Path to the ChromeDriver executable.
System.setProperty("webdriver.chrome.driver", "c:/temp/chromedriver.exe"); ChromeOptions options = new ChromeOptions();
// Path to the CEF executable.
options.setBinary("c:/temp/cef_binary_3.2171.1979_windows32_client/Release/cefclient.exe");
// Port to communicate on. Required starting with ChromeDriver v2.41.
options.addArguments("remote-debugging-port=12345"); WebDriver driver = new ChromeDriver(options);
driver.get("http://www.google.com/xhtml");
sleep(3000); // Let the user actually see something!
WebElement searchBox = driver.findElement(By.name("q"));
searchBox.sendKeys("ChromeDriver");
searchBox.submit();
sleep(3000); // Let the user actually see something!
driver.quit();
} static void sleep(int time) {
try { Thread.sleep(time); } catch (InterruptedException e) {}
}
}

Your directory structure should now look similar to this:

c:\temp\
cef_binary_3.2171.1979_windows32_client\
Release\
cefclient.exe (and other files)
chromedriver.exe
Example.java
selenium-server-standalone-2.44.0.jar
  1. Compile Example.java to generate Example.class:
> cd c:\temp
> javac -cp ".;*" Example.java
  1. Run the example:
> cd c:\temp
> java -cp ".;*" Example
When the example is run ChromeDriver will:

Output to the console:

Starting ChromeDriver 2.14.313457 (3d645c400edf2e2c500566c9aa096063e707c9cf) on port 28110
Only local connections are allowed.

Launch cefclient.exe.

Submit a Google search for "ChromeDriver".

Close cefclient.exe.

最新文章

  1. SAP 出库单新版
  2. 《C++ API设计》作者Martin Reddy访谈问题征集
  3. 在Linux(Ubuntu)下搭建ASP.NET Core环境并运行 继续跨平台
  4. powerdesigner设置表主键列为自动增长
  5. acdream 1685 多民族王国(DFS,并查集)
  6. Nginx开启Gzip压缩大幅提高页面加载速度(转)
  7. 最小费用最大流MCMF zkw费用流
  8. c# winform 弹出确认消息框判断是否删除?
  9. jQuery 事件 - bind() 方法
  10. hadoop2.7.3+spark2.1.0+scala2.12.1环境搭建(2)安装hadoop
  11. 饮冰三年-人工智能-Python-30 python开发中常见的错误
  12. pyCharm-激活码(2018)
  13. Azure vm 扩展脚本自动部署Elasticsearch集群
  14. Java代码优化,都有哪些常用方法?
  15. 【python】实例-答题系统
  16. C语言 · 判定字符位置
  17. 一个牛人给Java初学者的建议
  18. js中字符串处理成数字的方法
  19. jquery对象和DOM对象转换
  20. grep 文件内容搜索

热门文章

  1. 2020牛客寒假算法基础集训营4 -- A : 欧几里得
  2. Git 分支设计规范
  3. windows运行shell脚本
  4. phpmyadmin配置文件详解
  5. 1. c++实现最最最原始人的数字时钟
  6. 【HDU - 1260 】Tickets (简单dp)
  7. vscode+php+xdebug Time-out connecting to client (Waited: 200 ms)
  8. ASP.NET Core MVC的基础学习笔记
  9. 06.JS对象-1
  10. Android Intent用法总结