你如何让 webdriverjs 工作? [英] How do you get webdriverjs working?
问题描述
这里有人有使用 Selenium 和 webdriverjs 的经验吗?我来自非 Java 背景,在 Node.js 和 JavaScript 方面有丰富的经验.根据 Selenium 文档,您必须设置一个独立的 Selenium 服务器才能使用节点 Web 驱动程序.幸运的是,它们似乎捆绑在一起.
Anyone here have experience using Selenium and webdriverjs? I'm coming from a non-Java background with a good deal of experience with Node.js and JavaScript in general. According to the Selenium docs, you have to set-up a stand-alone Selenium server to use the node web driver. Fortunately, they seem to be bundled together.
npm install webdriverjs
为您在 node_modules/webdriverjs/bin
目录中获取独立 selenium 服务器的 JAR 文件.示例测试位于节点 node_modules/webdriverjs/examples
目录中,但是当我从 webdriverjs 或 examples 目录运行它们时,其中的测试失败.
gets you the JAR file for the standalone selenium server inside the node_modules/webdriverjs/bin
directory. Example tests are inside the node node_modules/webdriverjs/examples
directory but the tests in them fail when I run them from either the webdriverjs or examples directories.
这里缺少的部分是什么?启动和运行的最快方法是什么?
What's the missing piece here? What's the quickest way to get up and running?
我已阅读文档.
注意:堆栈溢出不允许我使用标签 webdriverjs,但这是专门针对 webdriverjs,而不是在 Java 或其他语言中使用 selenium.
Note: Stack overflow wouldn't let me use the tag webdriverjs, but this is specifically about webdriverjs, not using selenium with Java or other languages.
更新:唯一的问题是内置的示例测试已损坏!
Update: The only problem was that the built-in example tests are broken!
推荐答案
为了让 webdriverjs 正常工作,我做了以下工作:
Here's what I did to get webdriverjs working:
第 1 步:通过运行命令 java -jar selenium-server-standalone-2.33.0.jar
在我的笔记本电脑中独立启动 selenium.然后它将侦听 http://localhost:4444/
并且您可以通过 http://localhost:4444/wd/hub/
访问它.您还需要确保您的笔记本电脑上安装了 Firefox 浏览器.
Step 1: start selenium standalone in my laptop by running command java -jar selenium-server-standalone-2.33.0.jar
. then it will listen to http://localhost:4444/
and you can access it via http://localhost:4444/wd/hub/
. You also need to make sure Firefox browser is installed on your laptop.
第 2 步:创建一个新目录并运行命令 npm install webdriverjs
.
Step 2: create a new directory and run command npm install webdriverjs
.
第三步:在你新建的目录下新建一个名为test_webdriverjs.js
的文件,如下所示:
Step 3: create a new file named test_webdriverjs.js
in the new directory you created, and it looks like this:
var webdriverjs = require('webdriverjs');
var client = webdriverjs.remote({
host: 'localhost',
port: 4444
});
client.init();
client.url('https://github.com/')
.getTitle(function(err, title) { console.log (title)}).call(function () {});
client.end();
然后在同一目录下运行命令node test_webdriverjs.js
,你会发现它可以工作.如果它不起作用,请粘贴控制台输出.
Then run command node test_webdriverjs.js
under the same directory and you will find it works. If it doesn't work, paste out the console output.
这篇关于你如何让 webdriverjs 工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!