3

I am trying to run my Protractor test from command line using package.json.

My package.json looks like below -

{
    "name": "ProtractorFramework",
    "dependencies": {
        "protractor": "^5.4.1"
    },

    "scripts": {    
    "webdriver-manager-update":"./node_modules/.bin/webdriver-manager update",
    "webdriver-manager-start":"./node_modules/.bin/webdriver-manager start",
    "protractor":"./node_modules/.bin/protractor configuration.js",
    "start":"npm run webdriver-manager-update && npm run webdriver-manager-start && npm run protractor"


}
}

When I execute the below command -

npm run start from Project directory, the Selenium Standalone server is up, but the last command is not getting executed. It means, the browser is not opening.

To execute the test/open the browser, I am forced to execute npm run protractor separately in another command window.

Is there any mistake in my package.json that I am unable to execute all three commands together?

Please help.

Prabodh Ghosh
  • 161
  • 2
  • 17

1 Answers1

2

Prabodh you can't chain the selenium server startup command and the test execute command.

webdriver-manager start start up a Selenium Server and will output a bunch of info logs. Your Protractor test will send requests to this server to control a local browser. Leave this server running.

When you run webdriver-manager start selenium server will run in the command prompt. This command prompt can't be closed if you close it then selenium server will be quit.

Instead you can create a script that will open a new command prompt and run the webdriver-manager start command like

  "scripts": {    
       ..... 
       "wdstart":"start cmd /k webdriver-manager start timeout 10 && npm run protractor"
        ......
       }
Bharath Kumar S
  • 1,410
  • 2
  • 10
  • 29
  • Bharath Kumar S - I understand the requirement of opening the second command window, but that is what I was trying to avoid. – Prabodh Ghosh Dec 17 '18 at 10:06
  • Prabodh did you try with "wdstart":"start cmd /k webdriver-manager start" ? – Bharath Kumar S Dec 17 '18 at 10:30
  • Bharath Kumar S - As far as I understand, "wdstart":"start cmd /k webdriver-manager start" only starts the server. How does it execute test? I am not sure what exactly you are suggesting here. It would be helpful if you provide the complete chain of actions, if any. – Prabodh Ghosh Dec 17 '18 at 10:56
  • Update your npm run start script to "wdstart && npm run protractor" – Bharath Kumar S Dec 17 '18 at 10:58
  • I did that. But the problem we have here is, the execution and starting of the server is happening at the same time. So, execution is looking for a up & running server, which is still in process, so it failed. Is there any way we can add some delay before the "npm run protractor" command? Your solution is almost there which I am looking for. – Prabodh Ghosh Dec 17 '18 at 11:11
  • Yes i have updated the answer . 10 seconds delay for second cmd. – Bharath Kumar S Dec 17 '18 at 11:21
  • I don't think it is delaying. After adding the timeout also, it is running in parallel. Anyway, thanks very much for helping on executing the second command on a new CMD. – Prabodh Ghosh Dec 17 '18 at 11:39
  • Refer this post https://stackoverflow.com/questions/46561608/wait-seconds-before-running-next-task-on-scripts-package-jscon – Bharath Kumar S Dec 17 '18 at 11:41