Unlimited WordPress themes, graphics, videos & courses! Unlimited asset downloads! From $16.50/m
by
Lessons:25Length:2.9 hours
Angular test1
  • Overview
  • Transcript

5.4 Automating Protractor

Welcome back, ladies and gentlemen. We're precisely where we left off in our last video. We just successfully ran our end to end tests. Now, I wanted to close off by teaching everyone how to run our tests automatically in Gulp. This will allow us to run our Protractor tests as part of our build, and also automate running gulpServe beforehand. Let's go to our gulpfile, and we'll create a new task and call it protractor. And it's going to be dependent on serve. This will allow us to run it without having to run gulpServe manually like we just did. Be sure to pass the done keyword in the function. Now, we're gonna need to install a plugin, so open your terminal. And while you're at it, if you still have gulpServe running, stop it. And we'll type npm install --save gulpProtractor. Now, we'll start by returning a stream of our tests. So we'll say, return gulp.src. And that takes an array, and we're just going to pass it our end-to-end tests. Now, we're gonna pipe that. To the Protractor function. And we have to set up protractor by going to the top, and saying protractor = gulpProtractor. We'll pass protractor a config object. It needs to know its own config file, so let's pass in the path of that. And we'll say .on('end'). And we'll just pass done. Cool! So, let's see if it works. Let's go run gulpProtractor. And we made a little error, protractor should be equal to require("gulp-protractor").protractor. That makes sense, right? Let's try running it again. Hm. Looks like an error. We'll have to pass a base URL to our Protractor config. Let's go to our gulp file. And after configFile, we'll pass args, which is an array. This array will have two things in it. The first should be base URL with two dashes before it. And the second argument should be local host 8000. We've also made an error, returning both the gulp stream and calling done will call end twice, so we have to pick one or the other. In this case, let's not return the gulp stream. All right, let's give it a shot. And it worked. As you see, it got a little bit tight with the timing, with Protractor almost trying to start before the server was loaded. We can fix this up by tightening our gulp file, which I'll leave to you as an exercise to further understanding of angular. Well in this tutorial, we automated Gulp. And in the previous tutorials, we setup everything to get end to end test with Protractor and Selenium working. Now, you should have a good understanding of how to use Protractor, and what it does and what a good way to automate it is.

Back to the top