This repository contains a sample test automation project for an AngularJS based web application. Project utilizes Protractor test framework. Protractor is a Node.js program built on top of selenium's WebDriverJS library.
First of all, please ensure that Node.js(>=v8+) is installed in your system, version can be checked by:
node -v
v10.16.2If Node.js isn't existing in the system, it can be installed by following the instructions from the download page of official Node.js site.
Optionally, Java(JDK) will also be necessary in case Selenium Server will be used in standalone mode within the test system. Please note as Protractor has built-in direct communication mode for chrome/firefox selenium webdrivers, this part is not mandatory. Further details on modes will be provided in installation section.
We can either clone the repository:
git clone https://github.com/serkhanheit/test-automation-sample.git
cd test-automation-sampleor just download the project's zip file, then extract into a preferred work folder.
Within the path of work folder, we should run the command:
npm installNow, node_modules(including protractor and webdriver-update) are all ready.
webdriver-manager enables us to download browser drivers practically:
./node_modules/.bin/webdriver-manager update --versions.chrome 2.24Example above installs a specific version for chrome driver(this version should be selected in accordance to the chrome browser installed in test system) If we have the latest versions of a browser, we can drop the versions argument in the command, so letting the webdriver-manager install the latest versions of drivers.
This mode communicates with the webdriver directly and provides faster communication compared to Selenium Server standalone mode. We can run the tests by:
## to utilize chrome browsers:
./node_modules/.bin/protractor conf.chrome.js --suite login # runs "login page" related test-suite
./node_modules/.bin/protractor conf.chrome.js --suite employees # runs "employees page" related test-suite
./node_modules/.bin/protractor conf.chrome.js --suite login,employees # runs both test-suites
## by changing the conf file name firefox browsers can be used as well:
./node_modules/.bin/protractor conf.firefox.js --suite login,employees # runs both test-suitesOr we can utilize the shortcut npm commands prepared for convenience(shortcut details can be seen within scripts section of package.json file)
## to utilize chrome browsers:
npm run tst1 # runs "login page" related test-suite
npm run tst2 # runs "employees page" related test-suite
npm run tst # runs both test-suites (or npm test)
## to utilize firefox browsers:
npm run tstf1 # runs "login page" related test-suite
npm run tstf2 # runs "employees page" related test-suite
npm run tstf # runs both test-suitesPlease note, by default tests will run in DirectConnect mode of protractor due to settings(DirectConnect: true) in conf files.
To run the tests via Selenium Server, it's necessary to make appropriate modifications in config files (disabling directConnect mode & setting the driver version and selenium address accordingly)
this part of conf.chrome.js:
..
directConnect: true,
// chromeDriver: './node_modules/protractor/node_modules/webdriver-manager/selenium/chromedriver_2.24',
// seleniumAddress: 'http://localhost:4444/wd/hub',
..will be changed to:
..
directConnect: false,
chromeDriver: './node_modules/protractor/node_modules/webdriver-manager/selenium/chromedriver_2.24',
seleniumAddress: 'http://localhost:4444/wd/hub',
..In this mode, Selenium Server needs to be started before start of tests: Remark: JDK will be necessary here, as Selenium Server is a java application
webdriver-manager start --versions.chrome 2.24or the shortcut npm command prepared can be used:
npm run selenium-saAfter confirming that the server is up:
$ npm run selenium-sa
> testautomationsample@1.0.0 selenium-sa /home/work/test-automation-sample
> webdriver-manager start --versions.chrome 2.24
[04:08:51] I/start - java -Djava.security.egd=file:///dev/./urandom -Dwebdriver.chrome.driver=/home/work/test-automation-sample/node_modules/protractor/node_modules/webdriver-manager/selenium/chromedriver_2.24 -Dwebdriver.gecko.driver=/home/work/test-automation-sample/node_modules/protractor/node_modules/webdriver-manager/selenium/geckodriver-v0.24.0 -jar /home/work/test-automation-sample/node_modules/protractor/node_modules/webdriver-manager/selenium/selenium-server-standalone-3.141.59.jar -port 4444
..
04:08:52.454 INFO [WebDriverServlet.<init>] - Initialising WebDriverServlet
04:08:52.561 INFO [SeleniumServer.boot] - Selenium Server is up and running on port 4444
..Then, we can start the tests as examplified in directConnect mode.
MIT