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. python学习(1)python的基本概念

    1.python是世界上最流行的程序语言之一,用途广泛. 2.python是解释型语言,与C++编译类语言相比,python扩展性强,简单易上手.但是缺点也很明显,执行速度慢. 3.python定义中 ...

  2. 使用Python打造一款间谍程序

    知识点 这次我们使用python来打造一款间谍程序 程序中会用到许多知识点,大致分为四块 win32API  此处可以在MSDN上查看 Python基础重点在cpytes库的使用,使用方法请点击此处 ...

  3. Maven项目pom文件的节点释意

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...

  4. 不重启 清空tomcat日志

    1.重定向方法清空文件 [root@localhost logs]# du -h catalina.out  查看文件大小17M catalina.out[root@localhost logs]# ...

  5. 访问控制列表 ACL

    访问控制列表(Access Control List,ACL) 是路由器和交换机接口的指令列表,用来控制端口进出的数据包.其目的是为了对某种访问进行控制. 作用 ACL可以限制网络流量.提高网络性能. ...

  6. android wifi断开原因分析

    最近在解bug的过程中经常遇到密码正确但处于saved的状态,总结原因有已下几种: 1 在ASSOCIATING阶段由于丢包导致ASSOC REJECT 03-16 09:22:12.440 D/Wi ...

  7. docker容器互联,实现目录、服务共享

    一.需求 docker使服务之间实现容器隔离,比如Javaweb项目前端.后端.数据库.数据库后台,分别把它们部署在不同的容器里面,实现隔离.但服务和服务之间也有互访的需求,这就涉及到容器网络和容器互 ...

  8. debian 10安装英伟达独显驱动

    我的显卡是GTX1050TI,刚安装好Debian 10的时候启动会黑屏,无法进入系统,解决办法是在grub界面,按e修改启动参数,在启动参数那一行(一般会包含quiet)后面加上 nouveau.m ...

  9. mitmproxy--Cannot establish TLS with client (sni: e.crashlytics.com): TlsException("(-1, 'Unexpected EOF')",) 解决办法

    按崔哥(https://cuiqingcai.com/5391.html)的安装步骤一步步下来,会报这个错误: Cannot establish TLS with client (sni: e.cra ...

  10. The finally block does not always execute in try finally

    A finally block does not always xecute. The code in the try block could go into an infinite loop, th ...