Setup Protractor and Get Started In Flash
Step 1 : Installing Node.js and the latest Java Development Kit installed.
​
Step 2: To install protractor run the following in your terminal:
​
npm install -g protractor
​
Step 3: In another terminal window or tab, update and start the Selenium Server. This is needed to run tests locally in a browser.
​
webdriver-manager update
webdriver-manager start
​
Step 4: Create a Config FIle
Now that the Selenium Server is up and running, you can create your tests. You will first need to create a tests.conf.js file.
This stores each option needed to run tests like timeouts, test directory sources, and suites.
​
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
getPageTimeout: 60000,
allScriptsTimeout: 500000,
specs: ['*.spec.js'],
suites: {
suite1: 'spec/suite1/*.spec.js',
suite2: 'spec/suite2/*.spec.js'
},
baseURL: 'http://localhost:8080/',
framework: 'jasmine',
};
​
Some understnding of what do each of these options mean?
​
seleniumAddress: Where to talk to the Selenium Server instance that is running on your machine. This can be verified by checking the logs in the terminal window that is running the server.
​
getPageTimeout: Time to wait for the page to load
​
allScriptsTimeout: Time to wait for page to synchronize.
​
specs: Location of specs to run
​
suites: Organized directories for suites – run with –suite=suite1,suite2
​
baseURL: Main URL to hit for testing. This is helpful if there is only one, root URL.
​
framework: Where you specify the type of framework to use with Protractor
​
Step 5: Create a Spec File
The next step is creating a spec, where the test is defined.
Below is an example:
​
//test.spec.js
describe('Protractor Test', function() {
var addField = element(by.css('[placeholder="add new todo here"]'));
var checkedBox = element(by.model('todo.done'));
var addButton = element(by.css('[value="add"]'));
it('should navigate to the AngularJS homepage', function() {
browser.get('https://angularjs.org/'); //overrides baseURL
});
it('should show a search field', function() {
browser.sleep(5000); //used just to give you enough time to scroll to todo section
addField.isDisplayed();
});
it('should let you add a new task ', function() {
addField.sendKeys('New Task');
addButton.click();
browser.sleep(5000); //used just to see the task list update
});
});
​
Step 6: Run Your Test
Now that you have a configuration and spec written, it’s time to run the test. In your terminal, navigate to the directory where the configuration file is located and run the following command.
protractor tests.conf.js
​
RESULT:- You will see a browser window pop up and the test will execute – Firefox by default. You can watch the output of steps in your terminal window and, after the test is done running it will show as “passed” in terminal.
​