Working with Protractor through the command line

This is a translation from a blog post on Talking About Testing. See the original post here.

Walmyr Filho
2 min readJul 31, 2017
iTerm

For the command line fans, just like me, here’s a cool tip on how to run automated test scripts using Protractor before even developing them.

First, open the console of your operating system (on Mac or Linux, open the terminal, on Windows, open cmd).

If you have Protractor installed globally on your computer, run the following command:

protractor --directConnect --elementExplorer

In case Protractor is installed as a dependency of your project, execute the following command:

./node_modules/.bin/protractor --directConnect --elementExplorer

The Chrome browser should open automatically.

Then, run the following command to navigate to the official Protractor page:

browser.get("http://www.protractortest.org");

The official Protractor website should open in the newly instantiated Chrome browser.

After that, run the following command:

element.all(by.css("a")).last().click();

The tutorial page should be available.

Finally, run the following commands:

let title = element(by.css("h1"));
title.getText();

The output should be ‘Tutorial’

So, did you like it? Try what else you can do. Take a look at the Protractor API.

NOTE:

Verification commands will not work (see example below):

expect(title.isDisplayed()).toBe(true);

The above command returns the following error:

Error while evaluating command: ReferenceError: expect is not defined

The official documentation can be found here.

NOTE 2:

If you face the following issue, try using a version of Node.js not greather than 8.

WARNING: _debugger module not available on Node.js 8 *
* and higher.

I suggest using NVM to work with different Node.js versions. I have just tested with Node.js version 7.10.1, and it works fine then (tested on 21st of January, 2019).

If you liked this post, share, clap, or leave a comment!

See you on the next post, and good tests!

--

--

Walmyr Filho

QA Engineer, clean coder, blogger, writer, YouTuber, online teacher, mentor, member of technology communities and passionate for good music 🎶 and skateboarding