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.

怎么利用 ChromeDriver 和 Selenium对 CEF应用进行自动化测试-java实现的更多相关文章

  1. 转载 基于Selenium WebDriver的Web应用自动化测试

    转载原地址:  https://www.ibm.com/developerworks/cn/web/1306_chenlei_webdriver/ 对于 Web 应用,软件测试人员在日常的测试工作中, ...

  2. 自动化测试Java一:Selenium入门

    From: https://blog.csdn.net/u013258415/article/details/77750214 Selenium入门 欢迎阅读Selenium入门讲义,本讲义将会重点介 ...

  3. 使用 Selenium 实现基于 Web 的自动化测试

    (转自http://www.ibm.com/developerworks/cn/web/1209_caimin_seleniumweb/index.html) Selenium 是一个用于 Web 应 ...

  4. 利用jmeter对WebRTC应用进行压力测试(java)

    利用jmeter对WebRTC应用进行压力测试(java) 说明:WebRTC是一款开源的多人即时视频API,与一般的http请求不同,webrtc应用实际压力主要是码流 最近负责了一个WebRTC的 ...

  5. selenium原理应用 - 利用requests模拟selenium驱动浏览器

    前言 selenium是一个web自动化测试的开源框架,它支持多语言:python/java/c#… 前面也有一篇文章说明了,selenium+浏览器的环境搭建. selenium支持多语言,是因为s ...

  6. 利用Python与selenium自动化模拟登陆12306官网!

    近年来,12306的反爬越来越来严重,从一年前的 获取tk参数后到现在增加了 JS.CSS等加密方式! 目前大部分人利用的登陆方式都是利用selenium ,此文也不例外. 环境:        Wi ...

  7. 利用PIL和Selenium实现页面元素截图

    预备 照张相片 selenium.webdriver可以实现对显示页面的截图: from selenium import webdriver dr = webdriver.Firefox() dr.g ...

  8. 人人贷网的数据爬取(利用python包selenium)

    记得之前应同学之情,帮忙爬取人人贷网的借贷人信息,综合网上各种相关资料,改善一下别人代码,并能实现数据代码爬取,具体请看我之前的博客:http://www.cnblogs.com/Yiutto/p/5 ...

  9. 谷歌浏览器加载驱动(chromedriver)——selenium

    http://chromedriver.storage.googleapis.com/index.html 可以到该网站下载对应的谷歌驱动器(注意:需要版本和操作系统对应,其中windows统一32的 ...

随机推荐

  1. learn about sqlserver partitition and partition table --- add or remove table partitions addition more

    Yes . In the previous. chapter , we see how to generate "partition function" "parttit ...

  2. Go语言实现:【剑指offer】翻转单词顺序列

    该题目来源于牛客网<剑指offer>专题. 例如,"student. a am I",正确的句子应该是"I am a student." Go语言实 ...

  3. Java 中序列化与反序列化

    一. 序列化和反序列化概念 Serialization(序列化)是一种将对象以一连串的字节描述的过程:反序列化deserialization是一种将这些字节重建成一个对象的过程.将程序中的对象,放入文 ...

  4. Spring Cloud第十四篇 | Api网关Zuul

    ​ 本文是Spring Cloud专栏的第十四篇文章,了解前十三篇文章内容有助于更好的理解本文: Spring Cloud第一篇 | Spring Cloud前言及其常用组件介绍概览 Spring C ...

  5. EIP

    EIP中的值就是CPU下次要执行的地址 jmp 直接修改eip的值 1.jmp imm=mov eip,imm 2.jmp r 3.jmp m call 直接修改eip的值,并把当前指令的下一行地址存 ...

  6. css3 3d api

    perspective 人看东西的距离 perspective: 500; 越小3d效果越好 perspective-origin观察视点.此处默认为视图的中心点 transform-origin:2 ...

  7. AtCoder Beginner Contest 156

    https://atcoder.jp/contests/abc156/tasks A - Beginner #include <bits/stdc++.h> #define ll long ...

  8. APP图标在线生成

    在线生成安卓APP图标生成 图标在线 在线图标 安卓图标 生成图标 https://icon.wuruihong.com/ 在线png图片压缩  png压缩 https://compresspng.c ...

  9. 进阶之路 | 奇妙的Activity之旅

    前言 本文已经收录到我的Github个人博客,欢迎大佬们光临寒舍: 我的GIthub博客 本篇文章需要已经具备的知识: Activity的基本概念 AndroidManifest.xml的基本概念 学 ...

  10. 07.JS对象-2

    前言: 学习一门编程语言的基本步骤(01)了解背景知识(02)搭建开发环境(03)语法规范(04)常量和变量(05)数据类型(06)数据类型转换(07)运算符(08)逻辑结构(09)函数(10)对象1 ...