2

In general, the protractor scripts are executed in a new browser instance with the following capabilities

capabilities: {
'browserName': 'firefox'
}

Is there any snippets or ways to tweak this; so that our scripts make use of an already opened browser through protractor.

Prashanth Sams
  • 19,677
  • 20
  • 102
  • 125

3 Answers3

1

What worked for me, for angular2:

  1. Go to WebDriverHub and click on Create Session, copy the generated id (eg: 2919ed90-efac-48ee-83df-46f8e98ebce7), you'll need it in step#2.
  2. Add/Modify protractor.conf.js to reflect the following.

    exports.config.seleniumAddress: 'http://localhost:4444/wd/hub', exports.config.seleniumSessionId: '2919ed90-efac-48ee-83df-46f8e98ebce7', exports.config.directConnect: false

Observe:

  • Setting directConnect to false is important.
  • seleniumSessionId will need to be updated everytime u create new session (wish there was a way to tell, use current running browser window without updating seleniumSessionId everytime)
Anand Rockzz
  • 6,072
  • 5
  • 64
  • 71
0

On this line you have an example on how it's passed on the command line to Protractor: https://github.com/angular/protractor/commit/3f3805f9496fb130ae01b3e3278ee1ea7684d8e7#diff-b61b72dbab31e232fdb8466ebf733c4dR54 You can use the same parameter in your config to pass the current session ID. You can usually get the current sessionId by browser.getSessionId Example 1:

var runProtractor = spawn('bin/protractor',
     ['spec/attachSession.js', '--seleniumSessionId=' + currentSessionId]);

Example 2 using your config:

var checkOptions = {
     hostname: 'localhost',
     port: 4444,
     seleniumSessionId: yourCurrentSessionId
....
}
jtbandes
  • 115,675
  • 35
  • 233
  • 266
Gabriel Kohen
  • 4,166
  • 4
  • 31
  • 46
0

Use browser.getCapabilities() to get the debugger address. Using the debugger address we can communicate with the existing browser. In the below link I've written an article on this, take a look into this.

Link