[英]Manage Protractor tests with a single Gulp task
I'm trying to get e2e testing going with on my angular project using Gulp. 我正在尝试使用Gulp在我的角度项目上进行e2e测试。
I'm able to get it working, but only if I manually launch a standalone selenium server using webdriver-manager start
in a seperate terminal window. 我能够让它工作,但只有当我在一个单独的终端窗口中使用
webdriver-manager start
手动启动一个独立的selenium服务器时。
Ideally I would like my gulp task to manage starting and stopping the server so as to not add more overhead for my team to run these tests. 理想情况下,我希望我的gulp任务能够管理启动和停止服务器,以免为我的团队增加运行这些测试的开销。
I got set up following the instructions here: 我按照这里的说明进行了设置:
https://github.com/mllrsohn/gulp-protractor
https://github.com/mllrsohn/gulp-protractor
They describe 2 options for starting the selenium server. 他们描述了启动selenium服务器的2个选项。 One is to set up a gulp task which appears to do the same thing as
webdriver-manager start
: 一个是设置gulp任务,它似乎与
webdriver-manager start
:
gulp.task('webdriver_standalone', require("gulp-protractor").webdriver_standalone);
This works , but not when I have my e2eTest task invoke it as a dependency. 这有效 ,但是当我的e2eTest任务将其作为依赖项调用时。 I have to run
gulp webdriver_standalone
in a seperate terminal window. 我必须在一个单独的终端窗口中运行
gulp webdriver_standalone
。
I cannot understand the other suggested option. 我无法理解其他建议的选项。
point to the selenium jar in the protractor config file
指向量角器配置文件中的selenium jar
These instructions require a path to the selenium-server-standalone jar , in protractor
s node_modules
( ./node_modules/protractor/selenium/selenium-server-standalone-2.45.0.jar
), but my node_modules/protractor/
directory does not have such a jar (or a selenium
sub-directory at all) 这些说明需要一个指向selenium-server-standalone jar的路径,在
protractor
的node_modules
( ./node_modules/protractor/selenium/selenium-server-standalone-2.45.0.jar
node_modules/protractor/
selenium-server-standalone- ./node_modules/protractor/selenium/selenium-server-standalone-2.45.0.jar
)中,但是我的node_modules/protractor/
目录没有这样一个罐子(或者一个selenium
子目录)
The instructions for Running Protractor without a plugin seem to have the same problem of having to run the selenium server in another terminal window. 没有插件的Running Protractor的说明似乎有同样的问题,必须在另一个终端窗口中运行selenium服务器。
Is there a way to get this set up so that a single gulp task starts the standalone server, runs the tests, and shuts it down with no other intervention? 有没有办法让这个设置,以便单个gulp任务启动独立服务器,运行测试,并关闭它没有其他干预?
When you run Protractor you have several options regarding Selenium WebDriver (remember that WebDriver is web-service written in Java): 当你运行Protractor时,你有几个关于Selenium WebDriver的选项(记住WebDriver是用Java编写的web服务):
In your case simply run: 在您的情况下,只需运行:
./node_modules/protractor/bin/webdriver-manager update
It will download Selenium. 它将下载Selenium。 Then point config to the right jar.
然后将config指向正确的jar。
The easiest way to get this working locally is using a local Selenium Standalone jar, as Igor suggested in option #2. 在本地工作的最简单方法是使用本地Selenium Standalone jar,就像Igor在选项#2中建议的那样。 (It is pretty difficult to get gulp to run
webdriver-manager start
as a spawned child_process or async task.) You can get that jar in your node_modules
folder easily by using: (运行
webdriver-manager start
作为生成的child_process或异步任务,很难获得gulp。)您可以使用以下node_modules
轻松地在node_modules
文件夹中获取该jar:
npm install selenium-server-standalone-jar --save-dev
Then, in your protractor.conf.js
comment out or remove the seleniumAddress line and add a line for seleniumServerJar . 然后,在
protractor.conf.js
注释掉或删除seleniumAddress行并为seleniumServerJar添加一行。
exports.config = {
seleniumServerJar: '../node_modules/selenium-server-standalone-jar/jar/selenium-server-standalone-2.47.1.jar',
//seleniumAddress: 'http://localhost:4444/wd/hub',
/* Lines below for completeness only, leave yours as is. */
framework: 'jasmine2',
specs: ['login-spec.js'],
multiCapabilities: [{
browserName: 'chrome',
browserName: 'firefox'
}]
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.