1
votes

I am working on a mobile app. I am using ionic framework with angularjs. So I am programming this app using web technologies. My issues are regarding to the tests. I have unit and end to end (e2e) tests in my application. Look at my script section in my package.json file:

"scripts": {
  "test": "karma start test/karma.conf.js",
  "test-single-run": "karma start test/karma.conf.js --single-run"
}

I am able to run my unit tests executing the command in a git console:

npm run test

And my e2e tests executing two commands in two git consoles:

ionic serve (to run my app)
protractor test/protractor-conf.js (to run my e2e tests)

I have two issues here:

  • I am not able to add a script command to my package.json in order to simplify the protractor command. In the same way of my karma commands for unit testing. I have tried this:

    "e2e" : "protractor test/protractor-conf.js"

In order to run "npm run e2e", But I received this error: enter image description here

  • The second issue: I would like to create a build (or pipeline) for all my tests. I mean, to have a command like "rake" in ruby. Where I can run my units and e2e tests through it. This could be very useful in order to save time in the development process and to avoid the fact of forgetting to run my e2e tests.
1
Do you have a custom location setup for seleniumServerJar in your config? If not, it sounds like you forgot to run webdriver-manager update. Although it does seem odd that it works when you run them directly but not when using an npm script.tehbeardedone
I did run webdriver -manager update, that is why my e2e tests run with the protractor command.afonte
Strange. I essentially have the same thing as you and it works ok for me. "e2e:run-all-tests": "protractor ProtractorTests/protractor.conf.js". What is the location of the supposed missing .jar?tehbeardedone
I can't tell where it's looking for the selenium jar in the error you posted so I'm guessing here. I think it's probably looking for it under `node_modules\webdriver-manager\selenium` in your project repo and when you run the tests from the command line it's using a global install instead.tehbeardedone
You are totally right, I installed protractor and webdriver-manager globally following the instruction at protractor web site. I need to install them locally using npm if I want to used them from my scripts section in package.json. If you know how to do that please right the answer. I will accept it.afonte

1 Answers

1
votes

Ok, so now that you know what the issue is it's pretty easy to get this working. What I did was add a postinstall script that runs webdriver-manager update so that I don't ever forget to do it. Now that you have protractor as a local dependency you should be able to do something like this:

"scripts": {
    "postinstall": "webdriver-manager update",
    "e2e" : "protractor test/protractor-conf.js"    
  },

Now each time you run npm install the postinstall script will update webdriver for you and you don't have to remember to run it manually.

As for your second question, look at using Gulp or Grunt to do what you are asking. They are both similar to rake. You can setup a task to run your tests each time it detects file changes.