简体   繁体   English

通过grunt在实时服务器上运行量角器

[英]Run protractor on live-server via grunt

I am trying to run my portractor tests on live-server via one grunt task. 我试图通过一项艰巨的任务在实时服务器上运行我的portractor测试。 I have installed live-server ( https://www.npmjs.com/package/live-server ) and grunt-execute. 我已经安装了实时服务器( https://www.npmjs.com/package/live-server )和grunt-execute。 With grunt execute I managed to start live-server with a grunt command in 2 steps: 使用grunt execute,我可以通过2个步骤使用grunt命令启动实时服务器:

1st I created a node script (liveServer.js) 1我创建了一个节点脚本(liveServer.js)

var liveServer = require("live-server");

var params = {
    port: 8080,
    host: "localhost",
    open: true,
    wait: 1000
};
liveServer.start(params);

2nd I created a task in my grunt file to start the script: (in grunt.initConfig) 第二,我在grunt文件中创建了一个任务来启动脚本:(在grunt.initConfig中)

execute: {
    liveserver: {
        src: ['liveServer.js']
    },
}

and registered a command to trigger it: 并注册了一个触发它的命令:

grunt.registerTask('live', [
    'execute:liveserver'
]);

Now if I run "grunt live" in my commandline live-server starts, opens a browser, and I can browse my application. 现在,如果我在命令行中运行“ grunt live”,则实时服务器将启动,打开浏览器,然后可以浏览我的应用程序。

I also created a protractor task in my grunt file, which works just fine as well. 我还在grunt文件中创建了一个量角器任务,它也可以正常工作。
(in grunt.initConfig) (在grunt.initConfig中)

protractor: {
    options: {
        keepAlive: false,
        noColor: false
    },
    e2e: {
        options: {
            configFile: 'protractor.conf.js',
        }
    }
},

If I trigger it with a registered task the protractor tests run just fine, only I have to make sure live-server is running first. 如果我用已注册的任务触发它,则量角器测试运行得很好,只需要确保实时服务器先运行即可。 So ofcourse I want to combine the two in one command that starts live-server and then runs my protractor tests. 因此,我当然想将两者结合在一个命令中,该命令启动实时服务器,然后运行量角器测试。 So I tried: 所以我尝试了:

grunt.registerTask('runProtractor', [
    'execute:liveserver',
    'protractor'
]);

But unfortunately this does not work, live-server starts and then ... nothing happens, the protractor tests aren't run. 但是不幸的是,这不起作用,实时服务器启动,然后……什么也没发生,量角器测试没有运行。 I tried changing some of the live-server parameters such as open and wait, but without any luck. 我尝试更改一些实时服务器参数,例如打开和等待,但是没有任何运气。 There are no error messages either. 也没有错误消息。

As I said before separately the tasks work both fine (with two command windows, first start live-server in one and then protractor in the other) 正如我之前所说,任务都可以正常运行(有两个命令窗口,首先在一个窗口中启动实时服务器,然后在另一个窗口中使用量角器)

Does anybody have a clue why my does not continue after the live-server has started? 有人知道为什么在启动实时服务器后我不继续吗?

The execution of live-server blocks all subsequent tasks, since it doesn't "finish", ie to grunt the task is still running, which is why it won't proceed to the next task. 实时服务器的执行会阻止所有后续任务,因为它不会“完成”,即,为了使任务仍在运行,这就是为什么它将不会继续执行下一个任务的原因。 You can use grunt-concurrent to run tasks in parallel. 您可以使用grunt-concurrent并行运行任务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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