End to End Testing using protector in Angular Applications.
This is first tutorial in a entire series of End2End Testing using protractor framework.
Automation testing on the Angular based application also can be done using selenium web-driver but protractor framework lets us directly interact angular elements that why it is more advisable to write tests on protractor.
What Will I Learn?
you will learn following points in this tutorial.
- What is Protractor ? and why should we use it to test angular based application ?
- Tools that are compatible with protractor
- How to setup your systems environment to run Protractor tests.
- How to fix any error which can occur during setting up the environment.
- Various command that you will need for execution , management , error solving , configure the protractor tests.
Requirements
below listed tools and frameworks you will need to install in order to run the protractor tests
- Node.js - download the version based on the compatibility of your system from here nodejs.org
- Java development kit - download the version based on the compability of your system from here JDK
- Editor - any editor will do. we will be using the Eclipse for our tutorials but you can also use Notepad++ , Eclipse , Webstorm , Sublime etc...
Difficulty
- Basic
Tutorial Contents
What is Protractor ? and why should we use it to test angular based application ?
Protractor is an end-to-end test framework build on Node.js program that supports the Jasmine and Mocha test frameworks for Angular and AngularJS applications.
Protractor uses the Jasmine test framework for its testing interface so all the codes we will be writing will be in Jasmine.Jasmine will allow us to write unit and functional tests for our angular application.
protractor framework lets us directly interact angular specific locators, which allow us to test Angular-specific elements and run unit and End2End Tests
Running Test :
I have mentioned to install JDK because Protractor uses a standalone Selenium Server which is written in Java . we will be using selenium standalone server to interact with browsers.
Tools that are compatible with protractor :
protractor combines the tools and technologies such as NodeJS, Selenium, webDriver, Jasmine, Cucumber and Mocha.
How to setup your systems environment to run Protractor tests :
- First you will have to install JDK and set up the java environment.
- Then add below command in your command prompt which will install Protractor globally using Node Package Manager (npm)
npm install -g protractor
This will install two command line tools, protractor and webdriver-manager. After it is installed then run protractor --version command to make sure it's working.
If you need any help regrading anything then enter protractor --help command and it will list down all the options which you can use with protractor
The webdriver-manager is a helper tool to easily get an instance of a Selenium Server running. Use it to download the necessary binaries webdriver-manager update
Now lets run webdriver-manager version and make sure it's working.
If you need any help regrading anything then enter webdriver-manager help command and it will list down all the options which you can use with webdriver-manager
use webdriver-manager status to see we have all the browser drivers that we need to run our test on particular browser.
if something is missing then run webdriver-manager clean command and it will clean out all the browser drivers and then you can use webdriver-manager update and add fresh copy of drivers.
Now that you have followed all the steps and installed everything lets start up a server.
webdriver-manager start fire this command to start the server.
If webdriver-manager start does not work, and if you see error like below then try to clear out the saved files with webdriver-manager clean and installs this files again.
Now you will have a started up a Selenium Server and will see some output like some logs and at the end you will see "Selenium server is up and running" this means we have successfully started the serve and ready for our tests.
Your Protractor test will send requests to this server to control a local browser.
Important note : Server should be running while we run our tests , that means every time you want to run protractor tests then you have to start and leave this server running.
Now lets go to our browser and add this URL http://localhost:4444/wd/hub .
You can see information about the status of our server.
There is a another command for shutting down the server shutdown webdriver-manager shutdown but according to official documents " stopping is not yet supported on standalone server 3.x.x."
so you will have to close the command prompt in order to shutdown the server.
So ,that was all it about how to set up and run your protractor test. In next tutorial i will be discribing how you can configure Eclipse to run Protractor test directly from your browser.
Thank you for learning with this tutorial. This is my first tutorial so if you have any suggestion points or if you think there is something i should improve upon or if you run into any error or have any question regrading this tutorial please add your comment and i will try to address it as per best of my ability.
Thanks
Posted on Utopian.io - Rewarding Open Source Contributors
hi @roj
Thanks you for your quick review. as you suggested i have changed the repository .
As you see this is my first evey tutorial so if you could help me , i have few questions regrading contribution.
After the approval of the contribution will my tutorial will be available on official protractor repository ?
@pritpatel, No matter approved or not, I upvote and support you.
Thanks @steemitstats for the support.
Your contribution cannot be approved because it does not follow the Utopian Rules.
You can contact us on Discord.
[utopian-moderator]
hi @roj can you please review it again. i have made changes to the github repository. I had I had selected the other repository because it is a tutorial and i tried to find another tutorial on the github but wasn't able to find any. and i also did have question that i have mentioned in previous comment.