OperaDriver

本文深入探讨了OperaDriver的实现、使用方法、兼容性、配置选项及常见问题解决策略,帮助开发者高效地进行Web自动化测试。
OperDriver
OperaDriver是WebDriver厂商Opera Software和志愿者开发了对于Opera的WebDriver实现。
OperaDriver可以驱动浏览器对您的网页运行不通的测试,就像真实用于一样在他们之间导航。他可以模仿象点击链接,输入文字,提交表单的动作,并把结果报告给您,这样你就知道网站是否象您希望的那样工作。
OperaDriver的终端用户模拟确保了你的整个堆栈(HTML、脚本、样式嵌入资源和后端设置)是正常的,并且没有繁琐的手工测试例程。
要求
您需要JRE1.5(Oracle或OpenJDK)或以上来使用OperaDriver。它使用Scope interface(与Dragonfly一样)来直接在Java中与Opera直接通讯。所以,他和Opera 11.6级以上的版本兼容,虽然他和老的版本做一些调整也可勉强使用。
OperaDriver Server期望你安装了Opera或者Opera Next在每个系统的缺省路径:
OS Expected Location of Opera
GNU/Linux /usr/bin/opera

/usr/bin/opera-next

/usr/bin/operamobile
Mac /Applications/Opera.app/Contents/MacOS/Opera

/Applications/Opera Next.app/Contents/MacOS/Opera

/Applications/Opera Mobile Emulator.app/Contents/Resources/Opera Mobile.app/Contents/MacOS/operamobile
Windows %PROGRAMFILES%\Opera\opera.exe

%PROGRAMFILES%\Opera Next\opera.exe

%PROGRAMFILES%\Opera Mobile Emulator\OperaMobileEmu.exe
你也可以通过opera.binary的capability设置或者环境变量OPERA_PATH来更改该路径。可以在Advanced Usage中得到更多关于OperaDriver配置的信息。
11.52或更低版本的OperaDriver
在低于11.52版本的Opera中使用OperaDriver,请确保opera.port的capabilites值为-1,opera.profile的值为””(空字符串)来禁用-debugproxy和-pd这些在老版本中不支持的命令行参数。对于更老的版本(11.01或者更老)你可能需要使用脚本的包装:(见下面)
开始
远程
去安装请去下载页面 下载selenium-server-standalone或selenium-server,确保你有一个相当最近版本的Opera安装。你所需要做的就是创建一个WebDriver实例:
WebDriver driver = new OperaDriver();
driver.navigate().to("http://opera.com/");
WebDriver提供了多个语言的API,你可以在Ruby中做同样的事,通过设置环境变量“SELENIUM_SERVER_JAR”为*selenium-server-standalone JAR的全路径。
export SELENIUM_SERVER_JAR=/path/to/selenium-server-standalone.jar
然后在Ruby中:
require 'selenium-webdriver'
driver = Selenium::WebDriver.for :opera
driver.navigate.to 'http://opera.com/'
在Python中:
from selenium import webdriver
driver = webdriver.Opera()
driver.get('http://opera.com/')
把Server作为一个单独进程运行
OperaDriver与任何一个RemoteWebDriver客户端兼容。简单地启动您的服务器,创建一个远程客户端:
WebDriver driver = new RemoteWebDriver("http://localhost:9515", DesiredCapabilities.opera());
单独的OperaDriver
也可以使用OperaDriver作为您项目的一个单独的依赖。在Github project's download section下载,解压缩。在examples目录中有一些例子。你自己的项目中,在classpath中include lib目录,例如:
javac -classpath "lib/*:." Example.java
在Eclipse中,可在Project>Properties>Java Build Path中”Add JARs…” 或者”Add External JARs…”取决于您项目布局。
也可以使用Maven,group id是com.opera,artifact ID是operadriver。
文档
高级使用
Capabilities:
您可以使用DesiredCapabilities类来制定OperaDriver的设置。支持的capabilities有:
Capability Type Default Description
opera.logging.level String/Level
Level.INFO 日志的详细级别SEVERE, WARNING, INFO, CONFIG, FINE, FINER, FINEST, ALL.
opera.logging.file String null 日志的文件默认是不写到文件中.
opera.binary String system Opera binary Opera binary 的绝对路径. 如果没有指定,是安装路径。
opera.arguments* String null 传给Opera的参数,以空格分隔。参看Opera -help
opera.host String "127.0.0.1" Opera需要链接的Host。除非Opera在别的机器,否则不需要使用。
opera.port Integer random port Opera连接的端口. 0 = 随机端口, -1 = Opera默认 (port 7001) (for use with Opera < 12).
opera.launcher String ~/.launcher/LAUNCHER launcher binary的绝对路径. Launcher是OperaDriver 和Opera浏览器之间的一个网关,用来控制和监视binary,截屏。 默认使用OperaDriver提供的Launcher
opera.profile String/OperaProfile OperaProfile Opera使用的profile的目录.空是指一个新的随机Profile.如果 "", 空字符串, 那么默认的autotest 目录将会使用.
opera.idle Boolean false 是否使用 Opera 的imlpementation. 它将使用一个浏览器内置的启发式猜测页面何时完成加载,默认禁止。
opera.display Integer null 使用的X 显示, 通常为Xvfb 或者tightvncserver. ( UNIX-like OSes.)
opera.autostart Boolean true 是否自动启动Opera binary. 如果false, OperaDriver 会等待浏览器的连接. 到 "opera:debug", 输入正确的端口点"Connect"手动连接。
opera.no_restart Boolean false 是否重启.
opera.no_quit Boolean false 当OperaDriver 关闭时是否退出Opera. 如果启动,不退出
opera.product String null 我们使用的产品如"desktop", "core-desktop" 或 "sdk". See OperaProduct

使用capabilities:
DesiredCapabilities capabilities = DesiredCapabilities.opera();
capabilities.setCapability("opera.profile", new OperaProfile("/path/to/existing/profile"));
capabilities.setCapability("opera.logging.level", Level.CONFIG);
capabilities.setCapability("opera.logging.file", "/var/log/operadriver.log");
capabilities.setCapability("opera.display", 8);

// Now use it
WebDriver driver = new OperaDriver(capabilities);
driver.navigate().to("http://opera.com/");
定制Profile
您也可以指定一个Opera使用的profile。您可以使用一个新的随机的Profile(默认的)或者指定一个系统的Profile。您可以在Opera启动之前操作Profile,例如,设置您想要的Preferences。
OperaProfile profile = new OperaProfile(); // fresh, random profile
profile.preferences().set("User Prefs", "Ignore Unrequested Popups", false);
DesiredCapabilities capabilities = DesiredCapabilities.opera();
capabilities.setCapability("opera.profile", profile);
WebDriver driver = new OperaDriver(capabilities);
环境变量
为了制定opera安装路径和命令行参数,您需要使用环境变量。下表是您可以使用的环境变量:
Name Description
OPERA_PATH The absolute path to the Opera binary you want to use. If not set OperaDriver will try to locate Opera on your system.
OPERA_ARGS A space-delimited list of arguments to pass on to Opera, e.g. -nowindow, -dimensions 1600x1200, &c. See opera -help to view available arguments.
OPERA_PRODUCT To override the product check when running the OperaDriver tests.
如何设置环境变量,
GNU/Linux和Mac:export OPERA_PATH=…,添加这行到~/.bashrc(或者您的Shell的配置文件)来使用后面章节的特性。
Windows: 请参考http://support.microsoft.com/kb/310519

支持的Opera版本:
DeskTop
这是OperaDriver支持的官方Opera Desktop版本:
Version Workaround/tweaks needed
12.00 (Not released yet)
11.62
11.61
11.60
11.52 Set opera.port to -1 and opera.profile to "" (empty string) to disable -debugproxy and -pd command-line arguments
11.51
11.50
11.51
11.11
11.10
11.01 -autotestmode command-line argument is not supported, use a wrapper script
11.00
Wrapper script
一些老的版本默认不支持-autotestmode,-debugproxy和-pd等参数,您可以通过创建一个wrapper script绕过这些问题,把capability opera.binary执行它的绝对路径。
#!/bin/sh
# Wrapper to prevent the -autotestmode argument reaching this version of Opera
# which doesn't support it.
`dirname $0`/opera
已知问题:
Modifer Key的状态不能在Actions的多个.sendkeys调用中保持。
启用IME特性的Opera的问题(Opera Mobile, Android)
不支持Opera Mini。
不支持javascript 报警弹出框。
getScreenshotAs()只返回当前视区的图像,其他图像为空白。
在windows vista和win7,当Opera 11.5安装在默认路径时,需要管理员权限。
不可以移动到链接中的图片。
在视区中来回移动鼠标坐标有问题。
多字节输入在Windows中会失败。
双击一个元素时,EcmaScript dbClick事件没有被触发。
在Mac中Opera需要全部的焦点。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值