How to setup Protractor + Cucumber

Hello guys, I will post about how to install protractor and cucumber to test an AngularJS and how to import this project on your Eclipse.

You need JDK and Node.js installed:

– Install node in your mac

brew install node
node --version

– Check the version of you java

java -version

– Git clone this project as an example:

https://github.com/AndrewKeig/protractor-cucumber.git

– Install protractor and cucumber through npm, update and start the webdriver server

npm install -g protractor
npm install -g cucumber
protractor --version
webdriver-manager update
webdriver-manager start

– You will see a message like this on your console:

11:13:08.586 INFO - Selenium Server is up and running

– Run cucumber.js on the protractor-cucumber’s project folder

– If you have the error below, move the features folder to outside the examples folder and open the /features/step_definitions/steps.js and remove one of the “../”:

  return binding.lstat(pathModule._makeLong(path));

                 ^

Error: ENOENT: no such file or directory, lstat '/Users/Documents/workspace/protractor-cucumber/features'

    at Error (native)

    at Object.fs.lstatSync (fs.js:887:18)

    at Object.realpathSync (fs.js:1518:21)

    at Object.expandPathWithExtensions (/usr/local/lib/node_modules/cucumber/lib/cucumber/cli/path_expander.js:14:23)

    at /usr/local/lib/node_modules/cucumber/lib/cucumber/cli/path_expander.js:8:27

    at Array.map (native)

    at Object.expandPathsWithExtensions (/usr/local/lib/node_modules/cucumber/lib/cucumber/cli/path_expander.js:7:31)

    at Object.expandPaths (/usr/local/lib/node_modules/cucumber/lib/cucumber/cli/feature_path_expander.js:9:38)

    at Function.Configuration (/usr/local/lib/node_modules/cucumber/lib/cucumber/cli/configuration.js:21:63)

    at getConfiguration (/usr/local/lib/node_modules/cucumber/lib/cucumber/cli.js:46:38)

Rafaelas-MBP-2:protractor-cucumber rafaelasouza$ cucumber.js

module.js:341

 

If you want to run on Eclipse:
– Install nodeclipse, a Node.js plugin for Eclipse

npm install -g nodeclipse

nodeclipse -g

– Import this project into your workspace and install Enide on your eclipse.

Thank you guys ! See you tomorrow !

Advertisements
  1. Swapnil
    February 22, 2017 at 12:13 pm

    Hi Rafaela

    I followed all the steps mentioned here till eclipse installation. I got the error that you have mentioned above.
    After making the changes mentioned I am still getting below mentioned error :

    Error: Cannot find module ‘protractor’
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object. (C:\Users\spingle\Desktop\protractor-cucumber-master\lib\index.js:1:80)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object. (C:\Users\spingle\Desktop\protractor-cucumber-master\features\step_definitions\steps.js:1:72)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)

    I am new to protractor cucumber framework so I would really appreciate help from you.

    I am not able to use cucumber.js command but I got to know that it has been changed so cucumber-js does the same action for me.

    please let me know if I am missing something here.

    PS: node version v6.9.5
    protractor version Version 5.1.1

    • February 22, 2017 at 9:35 pm

      Hi Swapnil, the error that mentioned on the post was another one, but I maybe have a guess about what it could be. Are you running on the terminal first ? If yes, you need to run all the commands in your project folder on the terminal:

      npm install -g protractor
      npm install -g cucumber
      protractor --version
      webdriver-manager update
      webdriver-manager start

      After this you need to go to your project folder again on another tab and run: cucumber.js
      Let me know if until this part works.

  2. Swapnil
    February 23, 2017 at 9:34 am

    Hi Rafaela

    I could resolve the issue.
    It was local and global installation of protractor messing up things for me.

    this is the outcome I see in command prompt when i run cucumber-js

    C:\Users\spingle\Desktop\protractor-cucumber-master>cucumber-js
    Feature: Homepage

    As a user
    I want to visit the homepage
    So that I can access the various features on offer

    Scenario: Visit Homepage
    ? Given I am on the homepage
    ? Then I should see a “navbar”
    ? And I should see a “login” link
    ? And I should see a “register” link

    Warnings:

    1) Scenario: Visit Homepage – features\homepage.feature:6
    Step: Given I am on the homepage – features\homepage.feature:7
    Message:
    Undefined. Implement with the following snippet:

    Given(‘I am on the homepage’, function (callback) {
    // Write code here that turns the phrase above into concrete actions
    callback(null, ‘pending’);
    });

    2) Scenario: Visit Homepage – features\homepage.feature:6
    Step: Then I should see a “navbar” – features\homepage.feature:8
    Message:
    Undefined. Implement with the following snippet:

    Then(‘I should see a {arg1:stringInDoubleQuotes}’, function (arg1, callback) {
    // Write code here that turns the phrase above into concrete actions
    callback(null, ‘pending’);
    });

    3) Scenario: Visit Homepage – features\homepage.feature:6
    Step: And I should see a “login” link – features\homepage.feature:9
    Message:
    Undefined. Implement with the following snippet:

    Then(‘I should see a {arg1:stringInDoubleQuotes} link’, function (arg1, callback) {
    // Write code here that turns the phrase above into concrete actions
    callback(null, ‘pending’);
    });

    4) Scenario: Visit Homepage – features\homepage.feature:6
    Step: And I should see a “register” link – features\homepage.feature:10
    Message:
    Undefined. Implement with the following snippet:

    Then(‘I should see a {arg1:stringInDoubleQuotes} link’, function (arg1, callback) {
    // Write code here that turns the phrase above into concrete actions
    callback(null, ‘pending’);
    });

    1 scenario (1 undefined)
    4 steps (4 undefined)
    0m00.000s

    I have taken features folder out of examples folder as you mentioned above.
    Still I am getting this steps missing error.
    Also I imported this project in eclipse after installing nodeclipse as you have suggested.
    Can you please guide the steps to be followed for executing scripts in eclipse and how to make sure that feature file and step def mapping is there ?

    • March 4, 2017 at 11:34 pm

      Hi Swapnil, have you opened the /features/step_definitions/steps.js and removed one of the “../” in the code ? Send me your project structure and the steps.js in case you have did this.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: