5

I'm delving into the world of Protractor tests for AngularJS.

All the tutorials recommend I execute the following after webdriver-manager update and prior to executing the test: webdriver-manager start

According to the webdriver-manager man, the start command will 'start up the selenium server'. True enough, once I run the above command, I can see something at http://127.0.0.1:4444/wd/hub

My questions is: is the above necessary?

I currently run my tests without the above command.

All I do is: webdriver-manager update php -S localhost:8000 -t dist/ protractor ./test/protractor.config.js

My tests run as expected even though I've excluded webdriver-manager start.

Can someone please explain why webdriver-manager start is necessary?

:EDIT:

My protractor/fooTests.js:

exports.config = {
    directConnect: true,
    capabilities: {
        'browserName': 'chrome'
    },
    specs: ['protractor/fooTests.js'],
    jasmineNodeOpts: {
        showColors: true,
        defaultTimeoutInterval: 30000
    }
};

My protractor/fooTests.js:

describe('test for the bar code', function() {
    it('should login', function() {
        browser.get('http://localhost:8000');

        element(by.model('password')).sendKeys('123456');
        element(by.css('[type="submit"]')).click();
    });
    it('should inspect element ', function() {
        expect(element(by.id('foo-script')).isPresent()).toBe(true);
        console.log('Login Success');
    });
});
cnishina
  • 5,016
  • 1
  • 23
  • 40
Housni
  • 963
  • 1
  • 10
  • 23

1 Answers1

3

Protractor is sending commands to Selenium and Selenium is communicating with the browsers using its drivers.

webdriver-manager start

is starting Selenium.

There are 3 basic options:

  1. directConnect. That makes protractor communicate with the selenium drivers directly, without using the Selenium server. However, the functionality of this option is limited:

directConnect: true - Your test script communicates directly Chrome Driver or Firefox Driver, bypassing any Selenium Server. If this is true, settings for seleniumAddress and seleniumServerJar will be ignored. If you attempt to use a browser other than Chrome or Firefox an error will be thrown.

  1. Connecting to an already running selenium server (either local or remote), specified by seleniumAddress. A server can be started using the webdriver-manager start script.

  2. Starting the server from the test script.

You can explore all the options in the documentation https://github.com/angular/protractor/blob/master/docs/server-setup.md

Sulthan
  • 128,090
  • 22
  • 218
  • 270
  • I don't believe Selenium is running, by default. `ps aux | grep -i selenium` doesn't yield anything. Should I be grepping for something else? – Housni May 22 '15 at 11:07
  • @Housni grep for Java – Sulthan May 22 '15 at 11:08
  • Tried that too, nothing. I do see results when I run `webdriver-manager start` and then grep for it but not otherwise which leads me to believe that Selenium is not running in the background. Is it possible that the command `protractor ./test/protractor.config.js` is triggering Selenium to run with it? – Housni May 22 '15 at 11:13
  • 1
    @Housni It shouldn't do that, they are completely separate components. Another possibility is that your tests are empty or you are using selenium on another computer? How is your `seleniumAddress` set in config? – Sulthan May 22 '15 at 11:16
  • I added the config and my test file to my original post. `seleniumAddress` isn't set. – Housni May 22 '15 at 11:22
  • @Housni That `directConnect` option makes the problem clear :) Updated the answer. – Sulthan May 22 '15 at 11:32
  • I just removed `directConnect` and ran the test without `webdriver-manager start` and it ran fine. However, the output showed that the `protractor ./test/protractor.config.js` ran Selenium as a standalone: `Starting selenium standalone server... [launcher] Running 1 instances of WebDriver Selenium standalone server started at http://192.168.1.2:55312/wd/hub .Login Success . Finished in 16.923 seconds 2 tests, 1 assertion, 0 failures` So it seems like, if Selenium is not running, it will be invoked when a test is run. Is that right? – Housni May 22 '15 at 11:39
  • @Housni Obviously you are right. There are options I never knew were there. I linked the documentation which contains an explanation for all the options. – Sulthan May 22 '15 at 11:45