Pages

directConnect in protractor

what is directConnect in protractor?
  • Basically in protractor, a test case will run by connecting to browser through selenium server.
  • But protractor provides a feature i.,. directConnect, it will be used to directly connect to the browser driver.
  • directConnect will take 2 values:
  1. true,
  2. false
directConnect:false  ::
  • Its default value is false.
  • To use directConnect, we have to configure directConnect in the configuration file(conf.js).
  • If we do not use directConnect in the configuration file, it will take the value as false (as it's the default value)
  • When directConnect value is false, it's mandatory to configure seleniumAddress in the configuration file.
  • directConnect=false is used to connect the protractor tests to browser(chrome/firefox drivers) through seleniumServer
  • seleniumServer will start at a specified port number. if not specified it will use default port  4444
  • In your config file, set seleniumAddress to the address of the running server. This defaults to http://localhost:4444/wd/hub.
directConnect:true  ::
  • directConnect=true is used to connect directly, the protractor tests to browser(chrome/firefox driver) bypassing (or) by skipping (or) without using the seleniumServer.
  • If it is true, it will ignore seleniumAddress and seleniumServerJar settings.
  • The main advantage using value directConnect=true,is your test script may start up and run faster.
  • If you try to use browsers other than chrome, firefox, it will throw an error.
Let's see how to configure directConnect in your configuration file:
using directConnect=false:
exports.config = {
    framework: 'jasmine',
    seleniumAddress: 'http://localhost:4444/wd/hub', //directConnect:false
    specs: ['testSpec.js']
}
using directConnect=true:
exports.config = {
    framework: 'jasmine',
    directConnect:true,
    specs: ['testSpec.js']
}
Execute test case with different combinations for directConnect values(true/false)
Learn how to run a testcase here
protractor directConnect true
protractor directConnect
directConnect protractor
directConnect protractor

  • Observe above, here if we provide both seleniumAddress & directConnect=true, it will prefer directConnect=true only.
directConnect in protractor
directConnect=false in protractor


directConnect seleniumAddress
directConnect seleniumAddress protractor
  • we got error in above execution, because server is not started before execution of protractor test.
  • Start server (see below screenhsot) then start run protractor test.
directConnect server start protractor
directConnect server start protractor

directConnect seleniumAddress protractor
directConnect seleniumAddress protractor
Please comment below to feedback or ask questions.

No comments:

Post a Comment

Please comment below to feedback or ask questions.