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

5.2 Configuring Selenium

Welcome back, ladies and gentlemen. Here I am inside Brackets and as you can see I still have my terminal window running webdriver-manager open. We set this up in the last video. It's important that you already have web driver manager window running or else your Selenium won't work. So if you don't have that running get it running and if you're not sure go to the last video and review how to do that. With your web driver manager open, we can now proceed with the rest of the application. I'm just gonna minimize this window. Protractor is powered by a file called protractor.config.js. Let's create one inside our test directory. So this is a node package, so we're going to say exports.configs Exports being a special magic keyword only available in node, and we're just going to make that equal to an object. And this object is going to contain a protractor config. Now Protractor needs to hook up with Selenium. So we have to define either a jar for selenium, which is a group of Java classes, or an address. It's easier cross platform to get it working with an address and since we have it running in our terminal window, it should work. So let's say seleniumAddress. And that's a string. But what is our seleniumAddress? Let's have a look back at our terminal window. And here you see it tells us that remote webdriver instances should connect to HTTP 127.001 port 444/wd/hub. Well let's type it in. We can use local host instead of 127.0.0.1 Nice, now Protractor can do a lot of things. It can test with many different browsers like IE, Firefox, and Chrome in case it's your requirement to test all these browsers. This is defined by the capabilities so we'll make a capabilities configuration object. And, we're gonna have just one property, we're gonna say browser name, and we're going to set that to Chrome. Next, we need to define our spec files, which similar to our out tests, contain the actual steps that the tests are gonna do. We haven't written any yet, so lets just create a specs. And let's plan to create a new folder. We'll make the folder in test/e2e and then we'll include all JavaScript files in that folder. Note that this is relative to test so here, e2e/*.js is really test/e2e. Finally, we have one more option, the jasmineNodeOpts. This will create a clearer view for our Protractor tests. Inside this object let's say show colors is true. That's looking good! Let's see how it works. With the terminal open, let's type protractor. Followed by the path to our protractor file. We'll go to test/protractor.config.js. Okay. We're getting an error but this is expected. It says spec patterns did not match any files. You should see this error, and we'll fix it by creating some specs. Let's create a new folder inside test called e2e. And we'll create a new file inside e2e called app.spec.js. We know it's a test file because of the word spec. Let's add a describe block describing the end to end address tests. Let's save that and run our code in the terminal. Cool, did you catch that? It opened a Chrome browser for a very short period of time. However, there were no tests to run. Well, the first thing we're going to do is we're going to run gulp serve in a different terminal window. That will give us something to navigate to in our Protractor tests. Open a new terminal window and type gulp serve. And note, the port we're serving to is 8080. Now, go back to your Protractor end-to-end tests, And we're just going to write a single test. We'll call it, it should have contacts. So inside protractor there's a special keyword called browser and you can use browser to get access to webpages. So we can call browser.get. And pass in a URL. Which is the URL of our website currently being served by gulp. Now let's try to run our tests again. And you can see here behind the terminal. Selenium has navigated to our page. It hasn't run any tests or closed because we haven't written any or called done. We've now gotten our end-to-end test scaffolding done. In the next video, we're going to write some specific end-to-end assertions.

Back to the top