Protractor plays an important role in testing AngularJS applications and works as a solution integrator combining powerful technologies like Selenium, Jasmine, Web driver, etc. It is intended not only for testing AngularJS applications but also for writing automating regression tests for normal web applications.
In this topic, our speaker has taken you through a short tour from basic steps to advanced steps to work in project. There are following main sessions:
+ Protractor introduction
+ Building up and creating a simple test script
+ Getting familiar with Cucumber
+ Using page object model (POM) with protractor and cucumber
+ Reporting
6. www.axon.vnfb.com/AxonActiveVietNam
Protractor introduction
PROTRACTOR SELENIUM
Locators By.repeater, By.model,
…. (Selenium locators)
By.name, By.id, By.css,
By.xpath ….
Programming
language
Javascript only C#, Java, Python, Ruby
Browser
Support
(No different from Selenium) Chrome, Mozilla, Safari,
MSEdge
Package Whole range of NPM
packages
Limited to jar’s and assemblies
in JAVA and C#
7. www.axon.vnfb.com/AxonActiveVietNam
Protractor introduction
PROTRACTOR SELENIUM
Test frameworks Jasmine, Mocha,Chai TestNG, Junit for Java, Nunit,
Mstest for C#.
BDD support Cucumber Cucumber, SpecFlow
Programming Asynchronous Object oriented
Browsers Both real and headless
browsers
Only on real browsers
Speed About 20-30% faster than
Selenium
Normal
8. • Why we use protractor
Protractor introduction
12. Install below three things firstly
- Node.js
- Protractor
- Selenium Webdriver
Use npm to install Protractor globally with:
- npm install -g protractor
- webdriver-manager update
- webdriver-manager start
Building up and write a simple test
14. • Work Flow Diagram
Building up and write a simple test
15. • Creating a simple test script
• conf.js: the configuration file
• spec.js: the spec file
• customConfig.js: customize speed for protractor tests
Building up and write a simple test
16. exports.config = {
framework: ‘jasmine',
seleniumAddress:
‘http://localhost:4444/wd/hub',
specs: [‘customConfig.js','spec.js']
}
• Creating a simple test
Building up and write a simple test
17. • Creating a simple test
Building up and write a simple test
18. describe('Protractor Demo App', function() {
var registerBtn =
element.all(by.linkText('Register')).get(0);
var firstname
= element(by.model('vm.user.firstName'));
beforeEach(function() {
browser.get(‘http://localhost/demo');
});
it('register a user', function() {
expect(browser.getTitle()).toEqual('Dashbo
ard');
………………
});
});
Building up and write a simple test
19. var origFn = browser.driver.controlFlow().execute;
browser.driver.controlFlow().execute =
function () {
var args = arguments;
origFn.call(browser.driver.controlFlow(),function ()
{
return protractor.promise.delayed(400);
});
return origFn.apply(browser.driver.controlFlow(),
args);
};
Building up and write a simple test
20. • webdriver-manager update
• sudo webdriver-manager start
• protractor conf.js
(cd to project folder)
Run scripts:
Building up and write a simple test
21. (15’)
Write simple test scripts:
• Register an account (First Name, Last
Name, Username, Password)
• Login into system(Username, Password)
DEMO & PRACTICE
22. Feature: Register Account
As a user of Fusion website,
I want to create an account
So that I have to login the system
Scenario: Register an account successfully
Given I open the website http://localhost/demo/
Then I verify that welcome page is appeared
When I click Register button
Then I verify that register page is appeared
When I register with first name as Thuy, last name as
Nguyen, username as tixiuthu, password as 123456
Then I verify that system shows the Registration successful
Getting familiar with Cucumber
23. Getting familiar with Cucumber
Feature: Register Account
As a user of Fusion website,
I want to create an account
So that I have to login the system
Background:
Given I open the website <website>
Then I verify that add customer screen appears
Scenario Outline: Register an account successfully
When I click Register button
Then I verify that register page is appeared
When I register with first name as <firstname>, lastname as <lastname>, username as
<username>, password as <password>
Then I verify that system shows the <message>
Examples:
| website | firstname | lastname | username | password | message
|
| http://localhost/demo/ | Thuy | Nguyen | tixiuthu | 123456 | Registration successful |
| http://localhost/demo/ | Khue | Tran | ketr | 123456 | Registration successful |
24. • Code Structure
Using POM with protractor and cucumber
• package.jscon, package-lock.json :
get the dependences
• conf.js: the configuration file
• add_customer.feature: feature file
• add_customer_steps.js: definition file
• add_customer_page.js: page file
26. (25’)
In each team, we can implement more
features based on the existed features
in codes. Our supporters will guide and
explain more codes.
After finishing, each team has a short
demo
PRACTICE
Hi everyone,
Today, I am so happy to share you the topic “Protractor: End-to-end Testing for AngularJS”. Firstly, I will be introduced the short demo which created to be based on protractor, mocha, jasmine …
Did you know some definitions below:
- The basics of Selenium (Either Java/c#) Selenium IDE, Selenium Remote Control,
- Selenium Architecture
- Element locators available in Selenium
- Cucumber
POM (Page-Object-Model)
As you know, In this topic I will introduce some sessions related to some things but my point of protractor’s view. Honestly, in case you have a good knowledge about that ones , you will adapt with protractor faster because protractor is also based on some thing such as Selenium, locators, Cucumber, POM which can be built in Selenium
In this topic, we will work together with some sessions below:
Protractor introduction: having some definition of protractor and will give some ideas why we use protractor in Angular JS
Building up and creating a simple test script: how the protractor works in your computer, I also explain/guide how to build the simple test script in protractor. We have a short practice for this one to familiar (config,spec files, locator, running …)
Cucumber: as you know, Cucumber is working as BDD Style (based on Gherkin language), supporting for all team members to know the business faster and collaborate between testers, devs, customers. In this session, I just introduce the main contents to work in protractor
POM: the page object model we can make non-brittle test code and reduce or eliminate duplicate test code. Beside of that it improves the readability and allows us to create interactive documentation (It’s a small script, the maintenance looks easy but with time test suite will grow. More and more line codes, things becomes tough.
Protractor is a Node.js program that supports the Jasmine, Mocha, and Cucumber test frameworks. Protractor is an automated testing framework for testing AngularJS applications in the browser.
Protractor is an open source functional automation framework
Protractor uses Selenium WebDriver to drive browsers and simulate user’s interaction with an AngularJs application running in a browser.
Similarities and differences between Protractor and Selenium with Java/C#:
Locators:
Protractor is an Open Source, End-to-End test framework specifically built for AngularJS apps.
It’s a wrapper around Selenium WebDriverJS and Selenium Server.
You no longer need to add waits and sleeps to your test. Protractor can automatically execute the next step in your test the moment the webpage finishes pending tasks, so you don’t have to worry about waiting for your test and webpage to sync.
Having new locator strategies and functions specifically for Angular apps.
Automatic waiting can execute the next step in your test the moment the web page finishes pending tasks.
Protractor uses Jasmine (which is a behavior-driven development framework for testing JavaScript code) for its test syntax.
Protractor is built on top of WebDriverJS, which uses native events and browser-specific drivers to interact with your application as a user would.
Protractor is a Node.js (Node.js is an open source, cross-platform runtime environment for server-side and networking applications) program that supports the Jasmine, Mocha, and Cucumber test frameworks.
The framework integrated with Jasmine can be used to create and organize tests and user expectations. Jasmine is compatible with Protractor due to which all resources that are extracted from browsers can be used to make tests as promises. Those promises are resolved internally by using the “expect” command from Jasmine. That way the promises work smoothly while creating tests.
This configuration tells Protractor where your test files (specs) are, and where to talk to your Selenium Server (seleniumAddress). It will use the defaults for all other configuration. Chrome is the default browser.
The describe and it syntax is from the Jasmine framework. browser is a global created by Protractor, which is used for browser-level commands such as navigation with browser.get.
Cucumber is a tool based on Behavior Driven Development (BDD) framework which is used to write acceptance tests for web application. It allows automation of functional validation in easily readable and understandable format (like plain English) to Business Analysts, Developers, Testers, etc.