Protractor is an end to end test framework for Angular JS application. It is a library by the Angular team which is a wrapper on WebDriverJS and Jasmine and is specifically designed to make testing of Angular apps. But it doesn't mean that Protractor cannot be used for testing non-angular application. It can be used for testing both application but Protractor is something which is specially designed for handling Angular apps as it offers additional element query finder like binding,model, repeater etc which is not supported by WebDriverJS. By adding an additional line of code you can test your non-angular app as well with Protractor.
Setup Protractor At Home
Now protractor is a node.js program, so in-order to run protractor in your machine you need to have node.js installed in your machine. You can download node.js from their official website and install it into your system.
Once node.js is installed in your system , you can proceed to install protractor . To install protractor you should use following command in your command prompt.:
- npm install -g protractor
Note: -g is used here so that protractor is installed globally into your system and can be accessed from any path. If you do not want to install it globally you can skip -g and install it locally to a specific folder.
Running Your First Test in Protractor
Before creating your first test in protractor, you should understand that protractor needs basically two files to run, a spec file and a configuration file.
- configuration file: It is file which holds all the key information which protractor uses for running the test, like location of your spec file, which browser to be used for testing, selenium server , framework and many other things.
- spec file : It is the file where you actually write your test case.
Now lets get started, open the notepad and copy the following code and save it as spec.js
Now create another file in the same directory with name as conf,js and copy the following code:
In the code we have just provided following thing to protractor:
- framework: which framework to use , we have given Jasmine which is by default supported by protractor.
-seleniumAddress: The address of the selenium server running locally on the machine.
-specs: The location of your spec file, which in this case is your current working directory.
Now to run your first test case you have to first start your selenium server , which can be done by executing the following command on the command prompt:
- webdriver-manager start
This will start your selenium webdriver server at the followwing address:
-http://localhost:4444/wd/hub
Now keep the command prompt window open till you want to execute your test, do not close it otherwise the server will be closed. Open another command prompt instance and set the path to the directory where you have stored your spec and conf file . Now in the command prompt window execute the following command:
- protractor conf.js
And that's all, you are done with your first protractor test. The above command will run your first test.
Setup Protractor At Home
Now protractor is a node.js program, so in-order to run protractor in your machine you need to have node.js installed in your machine. You can download node.js from their official website and install it into your system.
Once node.js is installed in your system , you can proceed to install protractor . To install protractor you should use following command in your command prompt.:
- npm install -g protractor
Note: -g is used here so that protractor is installed globally into your system and can be accessed from any path. If you do not want to install it globally you can skip -g and install it locally to a specific folder.
Running Your First Test in Protractor
Before creating your first test in protractor, you should understand that protractor needs basically two files to run, a spec file and a configuration file.
- configuration file: It is file which holds all the key information which protractor uses for running the test, like location of your spec file, which browser to be used for testing, selenium server , framework and many other things.
- spec file : It is the file where you actually write your test case.
Now lets get started, open the notepad and copy the following code and save it as spec.js
// spec.js describe('Protractor Testing', function() { it('should open google page', function() { browser.ignoreSynchronization=true; // This is to be added if your application is non-angular browser.get('http://www.google.com'); expect(browser.getTitle()).toEqual('Google'); element(by.css('input.gsfi')).sendKeys('Hello testing') }); });In the above code we are trying to open the google page ,verifying its title as Google and enter 'Hello Testing' in the search field.
Now create another file in the same directory with name as conf,js and copy the following code:
// conf.js
exports.config = {
framework: 'jasmine',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['spec.js']
}
In the code we have just provided following thing to protractor:
- framework: which framework to use , we have given Jasmine which is by default supported by protractor.
-seleniumAddress: The address of the selenium server running locally on the machine.
-specs: The location of your spec file, which in this case is your current working directory.
Now to run your first test case you have to first start your selenium server , which can be done by executing the following command on the command prompt:
- webdriver-manager start
This will start your selenium webdriver server at the followwing address:
-http://localhost:4444/wd/hub
Now keep the command prompt window open till you want to execute your test, do not close it otherwise the server will be closed. Open another command prompt instance and set the path to the directory where you have stored your spec and conf file . Now in the command prompt window execute the following command:
- protractor conf.js
And that's all, you are done with your first protractor test. The above command will run your first test.
Hey its really amazing post. Thanks for sharing that useful informative data. I appreciate your difficulty work. Keep blogging. Protractor Training in Electronic City
ReplyDeleteMGM Grand Casino & Hotel, Las Vegas, NV - MapYRO
ReplyDeleteCasino at MGM 김천 출장샵 Grand 광양 출장안마 is situated along the Las 문경 출장마사지 Vegas Strip, near the intersection of 전주 출장샵 Las Vegas Boulevard and Spring Mountain 동해 출장안마 Road. Nearby casinos.