06 Sep

Protractor Testing Tool


Use npm to install Protractor globally with:

npm install -g protractor

This will install two command line tools, protractor and webdriver-manager. Try running protractor --version to make sure it’s working.

The webdriver-manager is a helper tool to easily get an instance of a Selenium Server running. Use it to download the necessary binaries with:

webdriver-manager update

Now start up a server with:

webdriver-manager start

This will start up a Selenium Server and will output a bunch of info logs. Your Protractor test will send requests to this server to control a local browser. You can see information about the status of the server at http://localhost:4444/wd/hub.

Write a test

Open a new command line or terminal window and create a clean folder for testing.

Protractor needs two files to run, a spec file and a configuration file.

Let’s start with a simple test that navigates to the todo list example in the AngularJS website and adds a new todo item to the list.

Copy the following into todo-spec.js:

describe('angularjs homepage todo list', function() {
  it('should add a todo', function() {

    element(by.model('todoList.todoText')).sendKeys('write first protractor test');

    var todoList = element.all(by.repeater('todo in todoList.todos'));
    expect(todoList.get(2).getText()).toEqual('write first protractor test');

    // You wrote your first test, cross it off the list
    var completedAmount = element.all(by.css('.done-true'));

The describe and it syntax is from the Jasmine framework. browser is a global created by Protractor, which is used for browser-level commands such as navigation with browser.get.


Now create the configuration file. Copy the following into conf.js:

exports.config = {
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['todo-spec.js']

This configuration tells Protractor where your test files (specs) are, and where to talk to your Selenium Server (seleniumAddress). It will use the defaults for all other configuration. Chrome is the default browser.

Run the test

Now run the test with:

protractor conf.js

You should see a Chrome browser window open up and navigate to the todo list in the AngularJS page, then close itself (this should be very fast!). The test output should be 1 test, 3 assertions, 0 failures. Congratulations, you’ve run your first Protractor test!

Share this

Comments (15)

womens oakley sunglasses
October 5, 2015 Reply

Hello, I enjoy reading all of your article. I like to write a little comment to support you.

July 27, 2016 Reply

Great goods from you, man. I actually have understand your stuff previous to and you're just too excellent.
I actually like what you might have acquired here, really like what you might be saying and how where
you say it. You will be making it entertaining
and you still take care of to hold it smart. I can't wait to read a lot more of
your stuff. This really is actually a tremendous site.

July 27, 2016 Reply

I'd want to many thanks for the efforts you've devote penning this blog.
I truly hope to check out a similar high-grade blog articles from you later on too.
Actually, your creative writing abilities has inspired
me to acquire my very own site now ;)

suba buba
August 4, 2016 Reply

RC50X0 There is certainly a great deal to learn about this topic. I really like all the points you ave made.

August 13, 2016 Reply

There's definately a lot to learn about this topic.

I really like all of the points you have made.

August 15, 2016 Reply

I am certain this paragraph has touched all the internet visitors,
its really really good post on building up new blog.

August 17, 2016 Reply

I have been surfing online more than three hours nowadays,
but I never found any interesting article like yours. It is actually lovely worth sufficient for me
personally. In my view, if all site owners and bloggers made excellent content as you probably did,
the internet will probably be far more helpful than previously.

August 18, 2016 Reply

I'm extremely impressed together with your writing skills
as well as with all the format within your
weblog. Is that this a paid subject material or did you customize it yourself?
Either way keep within the nice good quality writing, it's rare
to peer a nice weblog like this one today..

August 20, 2016 Reply

Be grateful for the auspicious writeup. It in fact was actually
a amusement account it. Look advanced to more added agreeable from you!
Anyway, how could we communicate?

August 20, 2016 Reply

I actually do accept as true with all of the concepts
you've introduced to the post. They're very convincing and may definitely work.
Still, the posts are too brief for beginners.
Might just you please lengthen them somewhat from next time?
Thanks for your post.

August 26, 2016 Reply

Highly descriptive article, I loved that bit.
Will there become a part 2?

August 28, 2016 Reply

Excellent post. I used to be checking continuously this blog and I'm impressed!

Very useful information specially the past part :) I look after such information a great
deal. I had been seeking this certain information for the very long time.
Many thanks and best of luck.

September 20, 2016 Reply

We have to be grateful for the efforts you've devote writing this blog.
I seriously hope to look into the same high-grade blog
posts by you down the road too. In reality, your creative writing abilities
has inspired me to acquire my website now ;)

October 4, 2016 Reply

My brother recommended I might like this web site.

He was entirely right. This post actually made my day.

You cann't imagine just how much time I had spent for this
info! Thanks!

Vickie Figueroa
March 19, 2017 Reply

Hi my name is Deanna Brady and I just wanted to send you a quick message here instead of calling you. I came to your Protractor Testing Tool - QA Programmer website and noticed you could have a lot more hits. I have found that the key to running a successful website is making sure the visitors you are getting are interested in your subject matter. There is a company that you can get keyword targeted traffic from and they let you try the service for free for 7 days. I managed to get over 300 targeted visitors to day to my site. https://fsuh.de/yourls/Q

Leave a reply