其实相对于与Selenium2,Selenium3没有作太多的改动。下面给出官方的文档说明,供参考。node
参考文档:https://seleniumhq.wordpress.com/2013/08/28/the-road-to-selenium-3/ios
因此对于Selenium3来讲最大的变更可能就是更加专一于手机和web的测试,尤为是手机的支持,由于你晓得的,如今更多的是移动的时代。git
对于Selenium2中对于RemotControl的实现我看了下Selenium3的源码发现确实不在支持,而更多的转向了W3C standard,不是独成一套Selenium本身的WebDriver API.关于这个须要插如一下有关W3C WebDriver的知识。github
参考文档: https://www.w3.org/TR/webdriver/,https://www.w3.org/testing/Activity,https://github.com/w3c/webdriverweb
W3C组织制定了一套浏览器自动化的规范叫作WebDriver,这套规范规定了全部的浏览器生产商都必须遵照这个规范。其实定义了好多的遵循的接口和WebDriver的概念。对于Chrome,Firefox,Opera,Safari.etc他们都须要遵照这个规范而且实现规范里面的接口,这些实现通常都是伴随浏览器的开发进行的。chrome
因此你应该明白了,Selenium无论是WebDriver仍是RemoteWebDriver都是W3C WebDriver的一种实现而已。真正的核心浏览器的交互在对应的浏览器的WebDriver上,其实你有了对应的浏览器的WebDriver,参考W3C的标准接口文档HTTP-based wire protocol你就能够单独实现浏览器的操做。就是Client-Server的沟通。全部支持的命令列表以下:api
举个ChromeDriver的例子。。。浏览器
https://sites.google.com/a/chromium.org/chromedriver/这里也有不少详细的接口的说明,这里的接口说明跟上面的W3C的接口说明差很少。你须要针对不一样的浏览器下载对应的版本。下面我如下载的一个win版本的为例(下载地址:http://chromedriver.storage.googleapis.com/2.23/chromedriver_win32.zip )session
1.1 查看下chromedriver.exe提供给咱们的一些可用的命令。app
里面的使用很详细,这里咱们只须要使用一个参数来启动ChromeDriver的server, –port ,命令以下:chromedriver.exe –port 9514,或者直接不输入端口直接回车,界面命令以下:
启动后chromedriver会在本地的9514端口号上进行监听通讯,根据不一样的命令发送到浏览器上,浏览器进行交互。好比启动一个chrome浏览器对应的命令是session,单独的ChromeDriver的HTTP通讯URI是:http://localhost:9514/session,对于经过RemoteWebDriver的URL是:http://localhost:9514/wd/hub/session
看一下这个说明: https://www.w3.org/TR/webdriver/#dfn-new-session,操做流程以下:
The remote end steps are:
If the remote end is an intermediary node, take implementation-defined steps that either result in returning an error with error code session not created, or in returning a success with data that is isomorphic to that returned by remote ends according to the rest of this algorithm.
If the maximum active sessions is equal to the length of the list of active sessions, return error with error code session not created.
If there is a current user prompt, return error with error code session not created.
Let capabilities be the result of getting a property named "capabilities
" from the parameters argument.
Let capabilities result be the result of processing capabilities with capabilities as an argument.
If capabilities result is an error, return error with error code session not created.
Let capabilities be capabilities result’s data.
Let session id be the result of generating a UUID.
Let session be a new session with the session ID of session id.
Set the current session to session.
Append session to active sessions.
上面的流程已经在最新的Selenium WebDriver中实现了。全部启动一个浏览器作的session操做能够参考以下核心Selenium代码逻辑。
1. 第一步设置chromeDriver的路径后面代码用到:System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
2. 第二步构建一个命令行对象用于执行chromedriver.exe的命令:
org.openqa.selenium.remote.service.DriverService.Builder.build()
public DS build() {
if (port == 0) {
port = PortProber.findFreePort(); //可用的端口号,例如232323,那么后面用到的命令就是:chromedriver.exe –port 232323
}
if (exe == null) {
exe = findDefaultExecutable();
}
ImmutableList<String> args = createArgs();
return createDriverService(exe, port, args, environment);
}
1. 核心selenium命令执行类:org.openqa.selenium.remote.RemoteWebDriver.RemoteWebDriver(CommandExecutor, Capabilities, Capabilities)
public RemoteWebDriver(CommandExecutor executor, Capabilities desiredCapabilities,
Capabilities requiredCapabilities) {
this.executor = executor;
init(desiredCapabilities, requiredCapabilities);
if (executor instanceof NeedsLocalLogs) {
((NeedsLocalLogs)executor).setLocalLogs(localLogs);
}
try {
startClient(desiredCapabilities, requiredCapabilities);
} catch (RuntimeException e) {
try {
stopClient(desiredCapabilities, requiredCapabilities);
} catch (Exception ignored) {
// Ignore the clean-up exception. We'll propagate the original failure.
}
throw e;
}
try {
startSession(desiredCapabilities, requiredCapabilities);
} catch (RuntimeException e) {
try {
quit();
} catch (Exception ignored) {
// Ignore the clean-up exception. We'll propagate the original failure.
}
throw e;
}
}
以上的代码完成了以下的操做:
1. 初始化desiredCapabilities对象,这是发送到客户端的JSON 数据,
2. 启动一个session,这里包含一个判断,若是这是一个NEW_SESSION,那么会在上面构建的chromedriver上启动chromedriver而后在发送session命令。后台操做HTTP请求用到的是Apache HttpClient的API.
上面说明下WebDriver的通讯是HTTP的协议,所以这里全部的通讯都是经过JSON Wired进行沟通的RESTFul格式。也就是说全部的沟通都是一次RESTFul的request和response的过程。
参考以下Selenium的说明: https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#command-summary
JSON Request:
JSON Response: