WebDriver API——浏览器控制暨如何学习webdriver API
在测试过程中我们可能需要对浏览器进行控制,大小控制啊,刷新页面啊,前进后退等等,最常用的两个接口是window和Navigation。
我们最常用的就是这4个,那么你是否感兴趣它们后面是什么,它们是怎么写出来的,我能否通过这几个简单的方法拓展自己思路,而不是等用到了去百度,一起来看下
1.window接口
返回了一些方法来管理当前窗口,那么有哪些呢?我们来看下
interface Window {
/**
* Set the size of the current window. This will change the outer window dimension,
* not just the view port, synonymous to window.resizeTo() in JS.
*
* @param targetSize The target size.
*/
void setSize(Dimension targetSize); /**
* Set the position of the current window. This is relative to the upper left corner of the
* screen, synonymous to window.moveTo() in JS.
*
* @param targetPosition The target position of the window.
*/
void setPosition(Point targetPosition); /**
* Get the size of the current window. This will return the outer window dimension, not just
* the view port.
*
* @return The current window size.
*/
Dimension getSize(); /**
* Get the position of the current window, relative to the upper left corner of the screen.
*
* @return The current window position.
*/
Point getPosition(); /**
* Maximizes the current window if it is not already maximized
*/
void maximize();
}
可以看到我们可以对当前窗口进行大小调整,进行位置调整,获取浏览器窗口大小,最大化等等。
2.Navigation接口
可以让driver来访问历史或者访问地址,这个接口可以做什么呢?
interface Navigation {
/**
* Move back a single "item" in the browser's history.
*/
void back(); /**
* Move a single "item" forward in the browser's history. Does nothing if we are on the latest
* page viewed.
*/
void forward(); /**
* Load a new web page in the current browser window. This is done using an HTTP GET operation,
* and the method will block until the load is complete. This will follow redirects issued
* either by the server or as a meta-redirect from within the returned HTML. Should a
* meta-redirect "rest" for any duration of time, it is best to wait until this timeout is over,
* since should the underlying page change whilst your test is executing the results of future
* calls against this interface will be against the freshly loaded page.
*
* @param url The URL to load. It is best to use a fully qualified URL
*/
void to(String url); /**
* Overloaded version of {@link #to(String)} that makes it easy to pass in a URL.
*
* @param url
*/
void to(URL url); /**
* Refresh the current page
*/
void refresh();
}
浏览器的后退,前进,访问url,刷新等操作。
那么我们还看到driver有个manage接口,顾名思义是管理的意思,我们可以看下它到底起到了哪些作用。点进去看下。
有道一下,用来管理你想操作的浏览器菜单,那么我们可以想下浏览器菜单里有什么,历史记录,书签等等等。来看下提供了哪些方法。
/**
* An interface for managing stuff you would do in a browser menu
*/
interface Options { /**
* Add a specific cookie. If the cookie's domain name is left blank, it is assumed that the
* cookie is meant for the domain of the current document.
*
* @param cookie The cookie to add.
*/
void addCookie(Cookie cookie); /**
* Delete the named cookie from the current domain. This is equivalent to setting the named
* cookie's expiry date to some time in the past.
*
* @param name The name of the cookie to delete
*/
void deleteCookieNamed(String name); /**
* Delete a cookie from the browser's "cookie jar". The domain of the cookie will be ignored.
*
* @param cookie
*/
void deleteCookie(Cookie cookie); /**
* Delete all the cookies for the current domain.
*/
void deleteAllCookies(); /**
* Get all the cookies for the current domain. This is the equivalent of calling
* "document.cookie" and parsing the result
*
* @return A Set of cookies for the current domain.
*/
Set<Cookie> getCookies(); /**
* Get a cookie with a given name.
*
* @param name the name of the cookie
* @return the cookie, or null if no cookie with the given name is present
*/
Cookie getCookieNamed(String name); /**
* Returns the interface for managing driver timeouts.
*/
Timeouts timeouts(); /**
* Returns the interface for controlling IME engines to generate complex-script input.
*/
ImeHandler ime(); /**
* Returns the interface for managing the current window.
*/
@Beta
Window window(); /**
* Gets the {@link Logs} interface used to fetch different types of logs.
*
* <p>To set the logging preferences {@link LoggingPreferences}.
*
* @return A Logs interface.
*/
@Beta
Logs logs();
}
这里面包含了对窗口的操作,对cookie的操作,对页面超时的处理,具体的可以再往里深究,在这里就不一一详述了,为大家提供一个思路。
-----------------------------------------------总结一下------------------------------------------------------
希望看到这篇文章的同学能有所启发,做过开发的同学可能觉得这很简单就是提供了许多接口给咱们调用,那么没有做过开发的同学肯定不会有这样的一个开发思路,点开每个方法,每个参数,每个接口去看下它后台是怎么实现的。那么我希望这部分同学在学习webdriver的时候能多些好奇心,拓展下自己的思维,而不是遇到了一个陌生的问题就去度娘,你比如我想操作浏览器前进,就去百度了怎么控制浏览器前进,那么等你想操作cookie的时候你还是会去百度,如果平时没事点开看下源码,那对于提高学习效率和开拓思维是极好的,,对提高自己的测试开发能力也是极好的。
WebDriver API——浏览器控制暨如何学习webdriver API的更多相关文章
- Python3 Selenium自动化web测试 ==> 第三节 常用WebDriver API使用示例上(24个API)
前置步骤: 安装selenium,chrome驱动,Python3.6 学习目的: 常见API的使用 涉及的API: step1: 访问一个网址 step2: 网页的前进和后退 step3: 刷新当前 ...
- 使用python selenium webdriver模拟浏览器
selenium是进行web自动化测试的一个工具,支持C,C++,Python,Java等语言,他能够实现模拟手工操作浏览器,进行自动化,通过webdriver驱动浏览器操作,我使用的是chrome浏 ...
- 浅谈python中selenium库调动webdriver驱动浏览器的实现原理
最近学web自动化时用到selenium库,感觉很神奇,遂琢磨了一下,写了点心得. 当我们输入以下三行代码并执行时,会发现新打开了一个浏览器窗口并访问了百度首页,然而这是怎么做到的呢? from se ...
- [技术博客]基于动态继承类、WebDriver的浏览器兼容性测试框架搭建
问题背景 观察使用selenium进行自动化测试的过程,我们可以将它概述为: 启动测试进程,在该进程中构建WebDriver 启动浏览器进程,将它与WebDriver建立连接 使用WebDriver向 ...
- selenium webdriver(1)---浏览器操作
启动浏览器 如何启动浏览器已在上篇文章中说明,这里还是以chrome为例,firefox.IE启动方式相同. //启动浏览器 import org.openqa.selenium.WebDriver; ...
- Java+selenium之WebDriver对浏览器的简单操作(一)
操作浏览器的主要方法都来自 org.openqa.selenium.WebDriver 这个接口 这些方法都是在 org.openqa.selenium.remote.RemoteWebDriver这 ...
- selenium WebDriver 对浏览器标签页的切换
关于selenium WebDriver 对浏览器标签页的切换,现在的市面上最新的浏览器,当点击一个链接打开一个新的页面都是在浏览器中打开一个标签页,而selenium只能对窗口进行切换的方法,只能操 ...
- 查看webdriver针对浏览器的一些函数
在用webdriver对浏览器进行操作时,很多操作并不是那么好找,后来在朋友的推荐下可以用下面的方法来寻找针对浏览器的一些操作,函数或属性等,这样方便我们可以查找一些方法去完成我们要的操作. 下面是查 ...
- WebDriver 将浏览器窗口最大化
package com.entrym.main; import java.io.File; import java.io.IOException; import org.openqa.selenium ...
随机推荐
- Codeforces Gym 100338C Important Roads 最短路+Tarjan找桥
原题链接:http://codeforces.com/gym/100338/attachments/download/2136/20062007-winter-petrozavodsk-camp-an ...
- POJ 2253 Frogger Floyd
原题链接:http://poj.org/problem?id=2253 Frogger Time Limit: 1000MS Memory Limit: 65536K Total Submissi ...
- 第1章 CentOS安装
一.安装说明 1.1 CentOS介绍 CentOS(Community Enterprise Operating System,中文意思是:社区企业操作系统)是Linux ...
- Extjs grid 单元格编辑
实现grid勾选后出现编辑按钮,通过增加一个字段checked来控制 事件如下: selectionchange: function (thi, selected, eOpts) { for (var ...
- mysql 数据库查询优化
从上图可以看出,计算机系统硬件性能从高到代依次为: CPU——Cache(L1-L2-L3)——内存——SSD硬盘——网络——硬盘 由于SSD硬盘还处于快速发展阶段,所以本文的内容不涉及SSD相关应用 ...
- Java自定义注解和运行时靠反射获取注解
转载:http://blog.csdn.net/bao19901210/article/details/17201173/ java自定义注解 Java注解是附加在代码中的一些元信息,用于一些工具在编 ...
- 分布式服务框架选型:面对Dubbo,阿里巴巴为什么选择了HSF?
转载:http://www.sohu.com/a/141490021_268033 阿里巴巴集团内部使用的分布式服务框架 HSF(High Speed Framework,也有人戏称“好舒服”)已经被 ...
- Convert Sorted List to Binary Search Tree——将链表转换为平衡二叉搜索树 &&convert-sorted-array-to-binary-search-tree——将数列转换为bst
Convert Sorted List to Binary Search Tree Given a singly linked list where elements are sorted in as ...
- 【转】Linux上的free命令详解
解释一下Linux上free命令的输出.默认输出是KB,可以用free -m则输出是MB 下面是free的运行结果,一共有4行.为了方便说明,我加上了列号.这样可以把free的输出看成一个二维数组FO ...
- STL之set具体解释(二)
首先来看看set集合容器: set集合容器实现了红黑树的平衡二叉树数据结构.在插入元素时它会自己主动调整二叉树的排列,把该元素放到适当的位置,而且 保证左右子树平衡.平衡二叉检索树採用中序遍历算法. ...