我开始使用Protractor& amp;茉莉花& PhantomJS。我想要实现的是使用PhantomJS从ProtractorDemo运行测试。但我失败了,我不知道为什么。确切的步骤在哪里:
我已经安装了量角器演示(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时,我会看到测试结果。
答案 0 :(得分:4)
事实上,你不需要运行:
.\node_modules\.bin\webdriver-manager update
也不是:
.\node_modules\.bin\webdriver-manager start
相反,您可以通过运行以下命令启动ghost驱动程序(9515将是驱动程序将运行的端口):
phantomjs --webdriver=9515
除此之外,您还应修改配置文件,以便让量角器知道驱动程序的位置。对于您的情况,您的配置文件应如下所示:
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