1
votes

I'm trying to set up E2E testing on one of my windows asp.net (mvc->angular)projects. We use team city to do our builds so I want my configuration to work on my box and on the build box.

I'm stuck trying to set up the values in conf.js so that protractor will automatically start up and stop when protractor needs it...

I run it via a batch file like this:

 call npm install -g
 call C:\Users\brown.ericw\AppData\Roaming\npm\protractor conf.js
 pause 

Everything was working fine when I was running selenium manually.

But I just can't figure out the right conf.js to get selenium started and shut down automatically(Stopping it in the bat file was not always effective, despite several different approaches).

I've tried lots of different combos, but I'm stumped.

Here is the relevant portion of my conf.js:

exports.config = {
    seleniumjar: '.\node_modules\protractor\selenium\selenium-server-standalone-2.45.0.jar',

    //seleniumArgs: '-Dwebdriver.chrome.driver="\node_modules\protractor\selenium\chromedriver',
    //chromeDriver: '.\node_modules\protractor\selenium\chromedriver',
    //chromeDriver: '.\node_modules\protractor\bin\webdriver-manager',
    chromeDriver: 'C:\Users\Brown.ericw\AppData\Roaming\npm\node_modules\protractor\selenium\chromedriver',
    //seleniumAddress: 'http://localhost:4444/wd/hub',
    specs: [
        'e2eTests/*.js'
    ],

I have protractor installed under my project folder, so I run npm install, so I know it's all kosher at the beginning of the run on the build/test server.

Here is the error I'm getting.. Clearly I can't I figure out the setting to get get it pointing towards the chrome driver...

D:\TFS\TACAdmin3G_Test_E2E>call C:\Users\brown.ericw\AppData\Roaming\npm\protra ctor conf.js [launcher] Process exited with error code 1 C:\Users\Brown.ericw\AppData\Roaming\npm\node_modules\protractor\node_modules\q\ q.js:126 throw e; ^ Error: Could not find chromedriver at D:\TFS\TACAdmin3G\node_modules\protractor\ selenium\chromedriver at LocalDriverProvider.addDefaultBinaryLocs_ (C:\Users\Brown.ericw\AppData\R oaming\npm\node_modules\protractor\lib\driverProviders\local.js:54:15) at LocalDriverProvider.setupEnv (C:\Users\Brown.ericw\AppData\Roaming\npm\no de_modules\protractor\lib\driverProviders\local.js:71:8) at Runner.run (C:\Users\Brown.ericw\AppData\Roaming\npm\node_modules\protrac tor\lib\runner.js:265:31) at TaskRunner.run (C:\Users\Brown.ericw\AppData\Roaming\npm\node_modules\pro tractor\lib\taskRunner.js:123:19) at createNextTaskRunner (C:\Users\Brown.ericw\AppData\Roaming\npm\node_modul es\protractor\lib\launcher.js:220:20) at C:\Users\Brown.ericw\AppData\Roaming\npm\node_modules\protractor\lib\laun cher.js:243:7 at _fulfilled (C:\Users\Brown.ericw\AppData\Roaming\npm\node_modules\protrac tor\node_modules\q\q.js:797:54) at self.promiseDispatch.done (C:\Users\Brown.ericw\AppData\Roaming\npm\node_ modules\protractor\node_modules\q\q.js:826:30) at Promise.promise.promiseDispatch (C:\Users\Brown.ericw\AppData\Roaming\npm \node_modules\protractor\node_modules\q\q.js:759:13) at C:\Users\Brown.ericw\AppData\Roaming\npm\node_modules\protractor\node_mod ules\q\q.js:573:44

I tried changing the slashes because of the space in the path up there and it changed back to the normal path:

Error: Could not find chromedriver at D:\TFS\TACAdmin3G\_Test_E2E\..

which doesn't give me the whole path.

chromedriver.exe is in all the locations in the various commented version in the conf.js. but no joy truing each of them.

I need to use relative pathing because the root folder on my box is different than the one on the build server.

Any help is greatly appreciated.

Forgot to say I looked at this one:Protractor does not find chromedriver: The driver executable does not exist: and this one

how to close selenium webdriver at end of test?

and wasn't able to figure it out

2
Sorry, copied it but got distracted and didn't' paste it, it's up now, Thanks!Eric Brown - Cal
Are you getting this error on your local server or on build server. Remember chrome may not be installed on the team city servernilesh
On the build server... I'll check chrome. Thanks! I checked Chrome is installed on the build server.Eric Brown - Cal

2 Answers

2
votes

Okay every body, for those who follow ,here is the answer to the problem and why I think this is what works. This answer works in my node.js project in VS(have to add the packages here too) , in a batch file on my dev box, and in team city.

I added NPM INSTALL to my build script, so that once the code is pulled down it immediately puts all the js packages in the code directories.

Then I added the selenium server stand lone package to my project(and package.json so I knew exactly where the jar is. I added it as a --Save(write to config)and as a --Dev (add in the dev section, ie include in node_models in my code folders)

Then I have this in my conf.js

> exports.config = {
>     seleniumServerJar: 'node_modules/selenium-server-standalone-jar/jar/selenium-server-standalone-2.45.0.jar',
>     chromeDriver: './node_modules/protractor/selenium/chromedriver',
>     //seleniumAddress: 'http://localhost:4444/wd/hub',

There are several subtle but important changes.

1

seleniumServerJar vs seleniumjar - there are a lot of examples out there using seleniumjar... so I'm guessing the standard tag changed at some point, but seleniumServerJar is what is shown on the documentation pages and it's what works.

2

/ vs \ as the slash in paths.. this one was tricks because when I used backslash, it didn't complain, the only difference was it truncated the path with a ... in the error messages, but when i dug in deeper, backslashes are getting removed from the part of the path you enter... even the part the code uses based on .\ has back slashes... so only use forward slashes in paths in these tags in conf.js

3

Relative pathing with ../node_modules vs .\node_modules vs node_modules..., there are examples out there with all of these used, once I was able to see the full paths being generated I figured out that ../ wasn't what I wanted.. so I played with it and got it working with one ./ and one nothing... why they both didn't work with ./ I don't know.. but it works.(sorry about that)

Just in case it helps you here is my package.json

{
  "name": "_Test_e2e",
  "version": "0.0.0",
  "description": "_Test_e2e",
  "main": "app.js",
  "author": {
    "name": "Brown.EricW",
    "email": ""
  },
  "devDependencies": {
    "jasmine-reporters": "^1.0.0",
    "protractor": ">=0.14.0-0 <1.0.0",
    "selenium-server-standalone-jar": "^2.45.0"
  },
  "scripts": {
    "postinstall": "webdriver-manager update"
  },
  "dependencies": {
    "jasmine": "^2.3.1",
    "jasmine-reporters": "^1.0.0",
    "protractor": "^2.1.0"
    
  }
}
1
votes

Running real browsers on build server probably isn't a good solution. If you have a dedicated Teamcity node, then a headless browser implementation like PhantomJS could be an option. You need to make sure that PhantomJS is installed on your dedicated node and its executable is placed somewhere in the PATH. Also make sure to set browser name to be phantomjs instead of chrome.

Secondly you could setup a Selenium grid and setup nodes with different browsers you want to test. From build server you would run tests on the remote selenium grid on the browser of your choice. There are paid, third part options like sauce labs or browser stack if you wish to go that route.

I would tend to go with second option since PhantomJS is not a real browser and you may have requirement of testing your application on different browsers/platforms etc.