简体   繁体   English

使用单个Gulp任务管理Protractor测试

[英]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的路径,在protractornode_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服务):

  1. Run with Protractor with remote (standalone) service. 使用带有远程(独立)服务的Protractor运行。 It can be either local or on different machine. 它可以是本地的,也可以是不同的机器。 If Selenium is on different machine then your web app should be publicly available, not just localhost. 如果Selenium在不同的机器上,那么您的Web应用程序应该是公开的,而不仅仅是localhost。 If you choose to use standalone Selenium service then you configure your config file/Gulp task with seleniumAddress option. 如果您选择使用独立的Selenium服务,则使用seleniumAddress选项配置配置文件/ Gulp任务。
  2. "Ask" Protractor to run Selenium for you. “问”量角器为你运行Selenium。 In this case Protractor will run Selenium WebDriver with the Jar file you provide in seleniumServerJar configuration. 在这种情况下,Protractor将使用您在seleniumServerJar配置中提供的Jar文件运行Selenium WebDriver。
  3. Do not use Selenium WD. 不要使用Selenium WD。 Use direct connect instead, which is compatible with Chrome and (probably) Firefox only. 请改用直接连接,它只与Chrome和(可能)Firefox兼容。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM