如何使用 Java 使用 Selenium 运行 ghostdriver [英] How to run ghostdriver with Selenium using java

查看:19
本文介绍了如何使用 Java 使用 Selenium 运行 ghostdriver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 phantomJS 进行一些 web 测试,我遇到了 GhostDriver (https://github.com/detro/ghostdriver).我已经使用自述文件中的说明构建了它,并且可以在指定的端口上运行它,但是我不确定如何从我的 java 代码中访问 Web 驱动程序.为了澄清,我在 ruby​​ 中看到了这个例子:

I want to use phantomJS for some web testing, and I've come across GhostDriver (https://github.com/detro/ghostdriver). I've built it using the instructions in the readme and I can run it on a specified port, but I am not sure how to access the web driver from my java code. To clarify, I've seen this example in ruby:

  caps = {
  :browserName => "phantomjs",
  :platform => "LINUX"
   }

urlhub = "http://key:secret@hub.testingbot.com:4444/wd/hub"

client = Selenium::WebDriver::Remote::Http::Default.new
client.timeout = 120

@webdriver = Selenium::WebDriver.for :remote, :url => urlhub, :desired_capabilities => caps, :http_client => client
@webdriver.navigate.to "http://www.google.com/"
puts @webdriver.title
@webdriver.save_screenshot("./screenshot.png")
@webdriver.quit

我只是不确定如何在 java 中做同样的事情.

I'm just not sure how to do the same from java.

推荐答案

我相信这个链接会回答你的问题.您将需要 Selenium 2.28.0 和 PhantomJS 1.8.我已经对此进行了测试,它的工作原理与宣传的一样,尽管我的测试是先行的.请注意,您需要下载 Selenium zip 文件以获取包含绑定的 jar.Maven 存储库尚未包含它.

I believe this link will answer your questions. You will need Selenium 2.28.0, and PhantomJS 1.8. I have tested this, and it works as advertised, although my tests were precursory. Note that you need to download the Selenium zip file to get the jar which contains the bindings. The Maven repo does not yet include it.

http://ivandemarino.me/2012/12/04/Finally-GhostDriver-1-0-0/

这篇关于如何使用 Java 使用 Selenium 运行 ghostdriver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆