gpt4 book ai didi

phantomjs - 使用 Protractor 设置 PhantomJs 不起作用

转载 作者:行者123 更新时间:2023-12-04 12:31:24 25 4
gpt4 key购买 nike

我正在用 Protractor & Jasmine & PhantomJS 开始我的冒险。我想要实现的是使用 PhantomJS 从 ProtractorDemo 运行测试。但是我失败了,我不知道为什么。具体步骤在哪里:

我已经安装了 Protractor 演示( https://github.com/juliemr/protractor-demo )

git clone https://github.com/juliemr/protractor-demo.git
cd protractor-demo
npm install

然后我安装了phantomjs:
npm install --save-dev phantomjs

然后我更新了配置(基于 http://angular.github.io/protractor/#/browser-setup ):
capabilities: {
'browserName': 'phantomjs',

/*
* Can be used to specify the phantomjs binary path.
* This can generally be ommitted if you installed phantomjs globally.
*/
'phantomjs.binary.path':'./node_modules/phantomjs/bin/phantomjs',

/*
* Command line arugments to pass to phantomjs.
* Can be ommitted if no arguments need to be passed.
* Acceptable cli arugments: https://github.com/ariya/phantomjs/wiki/API-Reference#wiki-command-line-options
*/
'phantomjs.cli.args':['--logfile=PATH', '--loglevel=DEBUG']
}

完整的配置文件如下所示:
// Tests for the calculator. exports.config = {   seleniumAddress: 'http://localhost:4444/wd/hub',

specs: [
'spec.js' ],

capabilities: {
'browserName': 'phantomjs',

/*
* Can be used to specify the phantomjs binary path.
* This can generally be ommitted if you installed phantomjs globally.
*/
'phantomjs.binary.path': './node_modules/phantomjs/bin/phantomjs',

/*
* Command line arugments to pass to phantomjs.
* Can be ommitted if no arguments need to be passed.
* Acceptable cli arugments: https://github.com/ariya/phantomjs/wiki/API-Reference#wiki-command-line-options
*/
'phantomjs.cli.args': ['--logfile=PATH', '--loglevel=DEBUG'] } };

然后我执行了教程中的命令:
.\node_modules\.bin\webdriver-manager update

我已经启动了 WebDriver 和 Web 服务器:
.\node_modules\.bin\webdriver-manager start
npm start

此命令的输出是:
Using the selenium server at http://127.0.0.1:4444/wd/hub
Server running at http://localhost:3456

最后一步:
node_modules\.bin\protractor test\conf.js

其他 webdriver-manager 控制台窗口的输出是:
15:23:10.181 INFO - Executing: [new session: Capabilities [{phantomjs.binary.path=./node_modules/phantomjs/bin/phantomjs, count=1, browserName=phantomjs, phantomjs.cli.args=[--logfile=PATH, --loglevel=DEBUG]}]])
15:23:10.192 INFO - Creating a new session for Capabilities [{phantomjs.binary.path=./node_modules/phantomjs/bin/phantomjs, count=1, browserName=phantomjs, phantomjs.cli.args=[--logfile=PATH, --loglevel=DEBUG]}]
15:23:10.203 INFO - executable: d:\dev\protractor-demo\.\node_modules\phantomjs\bin\phantomjs
15:23:10.203 INFO - port: 44410
15:23:10.203 INFO - arguments: [--logfile=PATH, --loglevel=DEBUG, --webdriver=44410, --webdriver-logfile=d:\dev\protractor-demo\phantomjsdriver.log]
15:23:10.204 INFO - environment: {}

但什么也没有发生。我看不到执行测试的结果。有什么我想念的吗?当我将浏览器从 phantomjs 更改为 chrome 时,我看到了测试结果。

最佳答案

事实上,你不需要运行:

.\node_modules\.bin\webdriver-manager update

也不:
.\node_modules\.bin\webdriver-manager start

相反,您可以通过运行以下命令(9515 将是驱动程序将在其中运行的端口)启动 ghost 驱动程序:
phantomjs --webdriver=9515

除此之外,您应该修改您的配置文件,以便让 Protractor 知道在哪里可以找到驱动程序。对于您的情况,您的配置文件应如下所示:
exports.config = {   
seleniumAddress: 'http://localhost:9515',

specs: ['spec.js'],

capabilities: {
'browserName': 'phantomjs',

/*
* Can be used to specify the phantomjs binary path.
* This can generally be ommitted if you installed phantomjs globally.
*/
'phantomjs.binary.path': './node_modules/phantomjs/bin/phantomjs',

/*
* Command line arugments to pass to phantomjs.
* Can be ommitted if no arguments need to be passed.
* Acceptable cli arugments: https://github.com/ariya/phantomjs/wiki/API-Reference#wiki-command-line-options
*/
'phantomjs.cli.args': ['--logfile=PATH', '--loglevel=DEBUG']
}
};

然后您将能够通过运行来运行测试:
node_modules\.bin\protractor test\conf.js

关于phantomjs - 使用 Protractor 设置 PhantomJs 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26203007/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com