SlideShare ist ein Scribd-Unternehmen logo
1 von 36
Advanced Apache
Cordova
Hazem Saleh
About me
experience
More than eleven years of experience in Java
enterprise and mobile solutions.
Apache Committer.
Author of four technical books.
DeveloperWorks Contributing author.
Technical Speaker (JavaOne, ApacheCon,
Geecon,JavaLand …etc)
Advisory Software Engineer in IBM.
Agenda
Apache Cordova Custom Plugins
Custom Plugins Demo
Cordova Cloud Push Notifications Demo
Cordova Unit Testing Demo
Cordova Cloud Push Notifications
Unit Testing Cordova Apps
Questions & Answers
Apache Cordova Custom Plugins
Apache Cordova core already provides and covers a lot of
important plugins:
Other
Apache Cordova Custom Plugins
Apache Cordova plugin is a package of injected code
that allows the Cordova Webview to communicate with
the native platform on which it runs.
All the main Cordova API features are implemented as
plugins.
In many cases, you do not need to develop your own
custom plugin since many quality plugins are available
in Apache Cordova Plugin registry website:
https://cordova.apache.org/plugins/
Apache Cordova Custom Plugins
Process of custom plugins development
Use Plugman to scaffold our custom plugin code.
Define the plugin API interface using JavaScript.
Implement the plugin interface using the platform native
programming language.
Publish your plugin to NPM registry
Using the custom plugin from a Cordova app
Apache Cordova Custom Plugins
Use Plugman to scaffold our custom plugin code
 plugman create --name helloworld123 --plugin_id
com.test.xyz.helloworld123 --plugin_version 0.0.1
 npm install -g plugman
Install Plugman
Apache Cordova Custom Plugins
Use Plugman to scaffold our custom plugin code (Adding
platforms):
 plugman platform add --platform_name android
 plugman platform add --platform_name ios
Apache Cordova Custom Plugins
Define the plugin API interface using JavaScript
Apache Cordova Custom Plugins
Implement the plugin interface using the platform native
programming language
Apache Cordova Custom Plugins
Using the custom plugin from a Cordova app
 cordova create testApp
 cordova platform add android
 plugman install --platform android --project
/path/to/my/project/platform --plugin /path/to/my/plugin
Apache Cordova Custom Plugins
Publish your plugin to NPM registry
 npm adduser # If you don't have an account yet
 npm publish /path/to/your/plugin
 plugman createpackagejson /path/to/your/plugin
Agenda
Apache Cordova Custom Plugins
Custom Plugins Demo
Cordova Cloud Push Notifications Demo
Cordova Unit Testing Demo
Cordova Cloud Push Notifications
Unit Testing Cordova Apps
Questions & Answers
CREATING CORDOVA PLUGIN
DEMO
Agenda
Apache Cordova Custom Plugins
Custom Plugins Demo
Cordova Cloud Push Notifications Demo
Cordova Unit Testing Demo
Cordova Cloud Push Notifications
Unit Testing Cordova Apps
Questions & Answers
Cordova Cloud Push Notification
In Apache Cordova plugins store, there are many plugins
to integrate Cordova apps with Push Notifications.
Usually, Cloud PaaS provides a unified platform for
managing Push Notifications on the mobile platforms.
As an example of integrated Push Notification Cloud
providers with Apache Cordova is the IBM Bluemix
thanks to ibm-mfp-push plugin:
https://www.npmjs.com/package/ibm-mfp-push
Implementing Push Notifications is a common
requirement in mobile apps.
Cordova Cloud Push Notification
IBM Bluemix supports the following types of Push
Notifications
Broadcast Push Notification:
It is pushed to all devices (you can also specify a
specific platform).
Unicast Push Notification:
It is pushed to a specific device by id.
Tag based Push Notification:
It is pushed to all devices that are registered to tags or
topics.
Cordova Cloud Push Notification
Steps for having IBM Bluemix Push Notification in
Actions for Cordova Apps:
1. Setup push notification in Bluemix
2. Install Bluemix Push Notification Plugin
3. In JavaScript code
1. Register Device for Push Notifications
2. Optionally subscribe in or unsubscribe from
tags
3. Receive notifications
4. Test Push Notifications
Cordova Cloud Push Notification
Setup push notification in Bluemix
Android iOS
Cordova Cloud Push Notification
Install Bluemix Push Notification Plugin
 cordova plugin add ibm-mfp-push
Configure plugin for Android and iOS
Cordova Cloud Push Notification
Register Device for Push Notifications
Cordova Cloud Push Notification
Subscribe in or unsubscribe from tags
Receive notifications
Cordova Cloud Push Notification
Testing Cloud Push Notifications
Agenda
Apache Cordova Custom Plugins
Custom Plugins Demo
Cordova Cloud Push Notifications Demo
Cordova Unit Testing Demo
Cordova Cloud Push Notifications
Unit Testing Cordova Apps
Questions & Answers
CORDOVA PUSH
NOTIFICATION DEMO
Demo Source: https://github.com/hazems/cordova-bmx-push
Agenda
Apache Cordova Custom Plugins
Custom Plugins Demo
Cordova Cloud Push Notifications Demo
Cordova Unit Testing Demo
Cordova Cloud Push Notifications
Unit Testing Cordova Apps
Questions & Answers
Unit Testing Cordova Apps
Since Cordova Apps are based on JavaScript, we need to
pick a suitable JavaScript unit testing framework for
testing Cordova apps logic.
Requirements for picking a good JavaScript unit testing
framework
Executable across browsers (Automated preferred)
Easy to setup
Fast Execution
Easy to configure
Integrated
Provides a good testing mechanism for Asynchronous code
Unit Testing Cordova Apps
Jasmine is a powerful JavaScript unit testing framework
Jasmine describes its tests in a simple natural language
Jasmine tests can be read by Non-programmers
Jasmine provides a clean mechanism for testing
synchronous and asynchronous code
Unit Testing Cordova Apps
Sample Jasmine Test
describe("A sample suite", function() {
it("contains a spec with an expectation", function() {
expect(true).toEqual(true);
});
});
Main Jasmine Constructs
Testsuite begins with a call to describe()
Testcase “or spec” begins with a call to it()
Testcase can contain one or more matcher(s)
Unit Testing Cordova Apps
Jasmine Example
describe("SimpleMath", function() {
var simpleMath;
beforeEach(function() {
simpleMath = new SimpleMath();
});
it("should be able to find factorial for positive number", function() {
expect(simpleMath.getFactorial(3)).toEqual(6);
});
it("should be able to find factorial for zero", function() {
expect(simpleMath.getFactorial(0)).toEqual(1);
});
afterEach(function() {
simpleMath = null;
});
});
Unit Testing Cordova Apps
Async Jasmine Tests
Asynchronous JavaScript code refers to the code whose
caller will NOT to wait until the execution completes.
In order to get the results, the caller should pass
callbacks which will be called with data result
parameters in case of operation success or failure.
Asynchronous JavaScript code mainly refers to Ajax
code.
In order to support Asynchronous operation testing, Jasmine provides:
1. An optional single parameter for its single spec.
2. This parameter has to be called if the asynchronous operation
completes.
3. If this parameter is not called for by default 5 seconds then the test
will fail (means operation timeout).
Unit Testing Cordova Apps
Async Jasmine Example
describe("when doing asynchronous operation", function() {
it("should be able to do the asynchronous operation", function(done) {
var data = {};
var successCallBack = function(result) {
console.log("success");
/* validate result parameter */
done();
};
var failureCallBack = function() {
console.log("failure");
expect("Operation").toBe("passing"); /* force failing test */
done();
};
AsyncObject.asyncOperation(data, successCallBack, failureCallBack);
});
});
Agenda
Apache Cordova Custom Plugins
Custom Plugins Demo
Cordova Cloud Push Notifications Demo
Cordova Unit Testing Demo
Cordova Cloud Push Notifications
Unit Testing Cordova Apps
Questions & Answers
CORDOVA UNIT TESTING
DEMO
Demo Source: https://github.com/hazems/cordova-js-unit-testing
Agenda
Apache Cordova Custom Plugins
Custom Plugins Demo
Cordova Cloud Push Notifications Demo
Cordova Unit Testing Demo
Cordova Cloud Push Notifications
Unit Testing Cordova Apps
Questions & Answers
Questions
Twitter: @hazems
Blog: http://www.technicaladvices.com
Email: hazems@apache.org

Weitere ähnliche Inhalte

Was ist angesagt?

Automation Open Source tools
Automation Open Source toolsAutomation Open Source tools
Automation Open Source tools
QA Club Kiev
 

Was ist angesagt? (20)

Appium Meetup #2 - Mobile Web Automation Introduction
Appium Meetup #2 - Mobile Web Automation IntroductionAppium Meetup #2 - Mobile Web Automation Introduction
Appium Meetup #2 - Mobile Web Automation Introduction
 
QA Fest 2018. Adam Stasiak. React Native is Coming – the story of hybrid mobi...
QA Fest 2018. Adam Stasiak. React Native is Coming – the story of hybrid mobi...QA Fest 2018. Adam Stasiak. React Native is Coming – the story of hybrid mobi...
QA Fest 2018. Adam Stasiak. React Native is Coming – the story of hybrid mobi...
 
Appium Dockerization: from Scratch to Advanced Implementation - HUSTEF 2019
Appium Dockerization: from Scratch to Advanced Implementation - HUSTEF 2019Appium Dockerization: from Scratch to Advanced Implementation - HUSTEF 2019
Appium Dockerization: from Scratch to Advanced Implementation - HUSTEF 2019
 
Java fx smart code econ
Java fx smart code econJava fx smart code econ
Java fx smart code econ
 
Introduction To Eclipse RCP
Introduction To Eclipse RCPIntroduction To Eclipse RCP
Introduction To Eclipse RCP
 
Agility Requires Safety
Agility Requires SafetyAgility Requires Safety
Agility Requires Safety
 
Automation Open Source tools
Automation Open Source toolsAutomation Open Source tools
Automation Open Source tools
 
Next level of Appium
Next level of AppiumNext level of Appium
Next level of Appium
 
Android & iOS Automation Using Appium
Android & iOS Automation Using AppiumAndroid & iOS Automation Using Appium
Android & iOS Automation Using Appium
 
Android programming-basics
Android programming-basicsAndroid programming-basics
Android programming-basics
 
Mobile Automation with Appium
Mobile Automation with AppiumMobile Automation with Appium
Mobile Automation with Appium
 
Laravel Forge: Hello World to Hello Production
Laravel Forge: Hello World to Hello ProductionLaravel Forge: Hello World to Hello Production
Laravel Forge: Hello World to Hello Production
 
[QE 2018] Adam Stasiak – Nadchodzi React Native – czyli o testowaniu mobilnyc...
[QE 2018] Adam Stasiak – Nadchodzi React Native – czyli o testowaniu mobilnyc...[QE 2018] Adam Stasiak – Nadchodzi React Native – czyli o testowaniu mobilnyc...
[QE 2018] Adam Stasiak – Nadchodzi React Native – czyli o testowaniu mobilnyc...
 
Simplifying RCP Update and Install
Simplifying RCP Update and InstallSimplifying RCP Update and Install
Simplifying RCP Update and Install
 
Appium & Jenkins
Appium & JenkinsAppium & Jenkins
Appium & Jenkins
 
Appium
AppiumAppium
Appium
 
Android develop guideline
Android develop guidelineAndroid develop guideline
Android develop guideline
 
Eclipse RCP Demo
Eclipse RCP DemoEclipse RCP Demo
Eclipse RCP Demo
 
vJUG - The JavaFX Ecosystem
vJUG - The JavaFX EcosystemvJUG - The JavaFX Ecosystem
vJUG - The JavaFX Ecosystem
 
Android Automation Testing with Selendroid
Android Automation Testing with SelendroidAndroid Automation Testing with Selendroid
Android Automation Testing with Selendroid
 

Andere mochten auch

Building Real-World Dojo Web Applications
Building Real-World Dojo Web ApplicationsBuilding Real-World Dojo Web Applications
Building Real-World Dojo Web Applications
Andrew Ferrier
 

Andere mochten auch (6)

Dojo >= 1.7 Kickstart
Dojo >= 1.7  KickstartDojo >= 1.7  Kickstart
Dojo >= 1.7 Kickstart
 
Dojo, from scratch to result
Dojo, from scratch to resultDojo, from scratch to result
Dojo, from scratch to result
 
Moving to Dojo 1.7 and the path to 2.0
Moving to Dojo 1.7 and the path to 2.0Moving to Dojo 1.7 and the path to 2.0
Moving to Dojo 1.7 and the path to 2.0
 
Rich internet application development using the dojo toolkit
Rich internet application development using the dojo toolkitRich internet application development using the dojo toolkit
Rich internet application development using the dojo toolkit
 
Building Real-World Dojo Web Applications
Building Real-World Dojo Web ApplicationsBuilding Real-World Dojo Web Applications
Building Real-World Dojo Web Applications
 
How dojo works
How dojo worksHow dojo works
How dojo works
 

Ähnlich wie [ApacheCon 2016] Advanced Apache Cordova

Appium mobile web+dev conference
Appium   mobile web+dev conferenceAppium   mobile web+dev conference
Appium mobile web+dev conference
Isaac Murchie
 

Ähnlich wie [ApacheCon 2016] Advanced Apache Cordova (20)

Appium solution
Appium solutionAppium solution
Appium solution
 
Automated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and MoreAutomated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and More
 
Appium mobile web+dev conference
Appium   mobile web+dev conferenceAppium   mobile web+dev conference
Appium mobile web+dev conference
 
Appium workship, Mobile Web+Dev Conference
Appium workship,  Mobile Web+Dev ConferenceAppium workship,  Mobile Web+Dev Conference
Appium workship, Mobile Web+Dev Conference
 
SRV307_Operating Your Serverless API at Scale
SRV307_Operating Your Serverless API at ScaleSRV307_Operating Your Serverless API at Scale
SRV307_Operating Your Serverless API at Scale
 
Serverless Beyond Functions - CTO Club Made in JLM
Serverless Beyond Functions - CTO Club Made in JLMServerless Beyond Functions - CTO Club Made in JLM
Serverless Beyond Functions - CTO Club Made in JLM
 
Apache Cordova phonegap plugins for mobile app development
Apache Cordova phonegap plugins for mobile app developmentApache Cordova phonegap plugins for mobile app development
Apache Cordova phonegap plugins for mobile app development
 
SAP Kapsel Plugins For Cordova
SAP Kapsel Plugins For CordovaSAP Kapsel Plugins For Cordova
SAP Kapsel Plugins For Cordova
 
Managing the Continuous Delivery of Code to AWS Lambda
Managing the Continuous Delivery of Code to AWS LambdaManaging the Continuous Delivery of Code to AWS Lambda
Managing the Continuous Delivery of Code to AWS Lambda
 
Releasing Software Quickly and Reliably With AWS CodePipeline by Mark Mansour...
Releasing Software Quickly and Reliably With AWS CodePipeline by Mark Mansour...Releasing Software Quickly and Reliably With AWS CodePipeline by Mark Mansour...
Releasing Software Quickly and Reliably With AWS CodePipeline by Mark Mansour...
 
Cordova Tutorial
Cordova TutorialCordova Tutorial
Cordova Tutorial
 
Cloud-powered Continuous Integration and Deployment architectures - Jinesh Varia
Cloud-powered Continuous Integration and Deployment architectures - Jinesh VariaCloud-powered Continuous Integration and Deployment architectures - Jinesh Varia
Cloud-powered Continuous Integration and Deployment architectures - Jinesh Varia
 
Codename one
Codename oneCodename one
Codename one
 
Cordova Mobile Application Developer Certification
Cordova Mobile Application Developer CertificationCordova Mobile Application Developer Certification
Cordova Mobile Application Developer Certification
 
Managing the Continuous Delivery of Code to AWS Lambda
Managing the Continuous Delivery of Code to AWS LambdaManaging the Continuous Delivery of Code to AWS Lambda
Managing the Continuous Delivery of Code to AWS Lambda
 
Appium solution artizone
Appium solution   artizoneAppium solution   artizone
Appium solution artizone
 
Android tools for testers
Android tools for testersAndroid tools for testers
Android tools for testers
 
Android CI and Appium
Android CI and AppiumAndroid CI and Appium
Android CI and Appium
 
RichFaces - Testing on Mobile Devices
RichFaces - Testing on Mobile DevicesRichFaces - Testing on Mobile Devices
RichFaces - Testing on Mobile Devices
 
Continuous Delivery with AWS Lambda - AWS April 2016 Webinar Series
Continuous Delivery with AWS Lambda - AWS April 2016 Webinar SeriesContinuous Delivery with AWS Lambda - AWS April 2016 Webinar Series
Continuous Delivery with AWS Lambda - AWS April 2016 Webinar Series
 

Mehr von Hazem Saleh

Mehr von Hazem Saleh (11)

[FullStack NYC 2019] Effective Unit Tests for JavaScript
[FullStack NYC 2019] Effective Unit Tests for JavaScript[FullStack NYC 2019] Effective Unit Tests for JavaScript
[FullStack NYC 2019] Effective Unit Tests for JavaScript
 
Mockito 2.x Migration - Droidcon UK 2018
Mockito 2.x Migration - Droidcon UK 2018Mockito 2.x Migration - Droidcon UK 2018
Mockito 2.x Migration - Droidcon UK 2018
 
JavaScript Unit Testing with an Angular 5.x Use Case 101
JavaScript Unit Testing with an Angular 5.x Use Case 101JavaScript Unit Testing with an Angular 5.x Use Case 101
JavaScript Unit Testing with an Angular 5.x Use Case 101
 
Efficient JavaScript Unit Testing (Chinese Version), JavaOne China 2013
Efficient JavaScript Unit Testing (Chinese Version), JavaOne China 2013Efficient JavaScript Unit Testing (Chinese Version), JavaOne China 2013
Efficient JavaScript Unit Testing (Chinese Version), JavaOne China 2013
 
Efficient JavaScript Unit Testing, JavaOne China 2013
Efficient JavaScript Unit Testing, JavaOne China 2013Efficient JavaScript Unit Testing, JavaOne China 2013
Efficient JavaScript Unit Testing, JavaOne China 2013
 
JSF Mashups in Action
JSF Mashups in ActionJSF Mashups in Action
JSF Mashups in Action
 
Efficient JavaScript Unit Testing, March 2013
Efficient JavaScript Unit Testing, March 2013Efficient JavaScript Unit Testing, March 2013
Efficient JavaScript Unit Testing, March 2013
 
JavaScript tools
JavaScript toolsJavaScript tools
JavaScript tools
 
Efficient JavaScript Unit Testing, May 2012
Efficient JavaScript Unit Testing, May 2012Efficient JavaScript Unit Testing, May 2012
Efficient JavaScript Unit Testing, May 2012
 
[JavaOne 2010] Abstract Mashups for Enterprise Java
[JavaOne 2010] Abstract Mashups for Enterprise Java[JavaOne 2010] Abstract Mashups for Enterprise Java
[JavaOne 2010] Abstract Mashups for Enterprise Java
 
GMaps4JSF
GMaps4JSFGMaps4JSF
GMaps4JSF
 

Kürzlich hochgeladen

Kürzlich hochgeladen (20)

Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

[ApacheCon 2016] Advanced Apache Cordova

  • 2. About me experience More than eleven years of experience in Java enterprise and mobile solutions. Apache Committer. Author of four technical books. DeveloperWorks Contributing author. Technical Speaker (JavaOne, ApacheCon, Geecon,JavaLand …etc) Advisory Software Engineer in IBM.
  • 3. Agenda Apache Cordova Custom Plugins Custom Plugins Demo Cordova Cloud Push Notifications Demo Cordova Unit Testing Demo Cordova Cloud Push Notifications Unit Testing Cordova Apps Questions & Answers
  • 4. Apache Cordova Custom Plugins Apache Cordova core already provides and covers a lot of important plugins: Other
  • 5. Apache Cordova Custom Plugins Apache Cordova plugin is a package of injected code that allows the Cordova Webview to communicate with the native platform on which it runs. All the main Cordova API features are implemented as plugins. In many cases, you do not need to develop your own custom plugin since many quality plugins are available in Apache Cordova Plugin registry website: https://cordova.apache.org/plugins/
  • 6. Apache Cordova Custom Plugins Process of custom plugins development Use Plugman to scaffold our custom plugin code. Define the plugin API interface using JavaScript. Implement the plugin interface using the platform native programming language. Publish your plugin to NPM registry Using the custom plugin from a Cordova app
  • 7. Apache Cordova Custom Plugins Use Plugman to scaffold our custom plugin code  plugman create --name helloworld123 --plugin_id com.test.xyz.helloworld123 --plugin_version 0.0.1  npm install -g plugman Install Plugman
  • 8. Apache Cordova Custom Plugins Use Plugman to scaffold our custom plugin code (Adding platforms):  plugman platform add --platform_name android  plugman platform add --platform_name ios
  • 9. Apache Cordova Custom Plugins Define the plugin API interface using JavaScript
  • 10. Apache Cordova Custom Plugins Implement the plugin interface using the platform native programming language
  • 11. Apache Cordova Custom Plugins Using the custom plugin from a Cordova app  cordova create testApp  cordova platform add android  plugman install --platform android --project /path/to/my/project/platform --plugin /path/to/my/plugin
  • 12. Apache Cordova Custom Plugins Publish your plugin to NPM registry  npm adduser # If you don't have an account yet  npm publish /path/to/your/plugin  plugman createpackagejson /path/to/your/plugin
  • 13. Agenda Apache Cordova Custom Plugins Custom Plugins Demo Cordova Cloud Push Notifications Demo Cordova Unit Testing Demo Cordova Cloud Push Notifications Unit Testing Cordova Apps Questions & Answers
  • 15. Agenda Apache Cordova Custom Plugins Custom Plugins Demo Cordova Cloud Push Notifications Demo Cordova Unit Testing Demo Cordova Cloud Push Notifications Unit Testing Cordova Apps Questions & Answers
  • 16. Cordova Cloud Push Notification In Apache Cordova plugins store, there are many plugins to integrate Cordova apps with Push Notifications. Usually, Cloud PaaS provides a unified platform for managing Push Notifications on the mobile platforms. As an example of integrated Push Notification Cloud providers with Apache Cordova is the IBM Bluemix thanks to ibm-mfp-push plugin: https://www.npmjs.com/package/ibm-mfp-push Implementing Push Notifications is a common requirement in mobile apps.
  • 17. Cordova Cloud Push Notification IBM Bluemix supports the following types of Push Notifications Broadcast Push Notification: It is pushed to all devices (you can also specify a specific platform). Unicast Push Notification: It is pushed to a specific device by id. Tag based Push Notification: It is pushed to all devices that are registered to tags or topics.
  • 18. Cordova Cloud Push Notification Steps for having IBM Bluemix Push Notification in Actions for Cordova Apps: 1. Setup push notification in Bluemix 2. Install Bluemix Push Notification Plugin 3. In JavaScript code 1. Register Device for Push Notifications 2. Optionally subscribe in or unsubscribe from tags 3. Receive notifications 4. Test Push Notifications
  • 19. Cordova Cloud Push Notification Setup push notification in Bluemix Android iOS
  • 20. Cordova Cloud Push Notification Install Bluemix Push Notification Plugin  cordova plugin add ibm-mfp-push Configure plugin for Android and iOS
  • 21. Cordova Cloud Push Notification Register Device for Push Notifications
  • 22. Cordova Cloud Push Notification Subscribe in or unsubscribe from tags Receive notifications
  • 23. Cordova Cloud Push Notification Testing Cloud Push Notifications
  • 24. Agenda Apache Cordova Custom Plugins Custom Plugins Demo Cordova Cloud Push Notifications Demo Cordova Unit Testing Demo Cordova Cloud Push Notifications Unit Testing Cordova Apps Questions & Answers
  • 25. CORDOVA PUSH NOTIFICATION DEMO Demo Source: https://github.com/hazems/cordova-bmx-push
  • 26. Agenda Apache Cordova Custom Plugins Custom Plugins Demo Cordova Cloud Push Notifications Demo Cordova Unit Testing Demo Cordova Cloud Push Notifications Unit Testing Cordova Apps Questions & Answers
  • 27. Unit Testing Cordova Apps Since Cordova Apps are based on JavaScript, we need to pick a suitable JavaScript unit testing framework for testing Cordova apps logic. Requirements for picking a good JavaScript unit testing framework Executable across browsers (Automated preferred) Easy to setup Fast Execution Easy to configure Integrated Provides a good testing mechanism for Asynchronous code
  • 28. Unit Testing Cordova Apps Jasmine is a powerful JavaScript unit testing framework Jasmine describes its tests in a simple natural language Jasmine tests can be read by Non-programmers Jasmine provides a clean mechanism for testing synchronous and asynchronous code
  • 29. Unit Testing Cordova Apps Sample Jasmine Test describe("A sample suite", function() { it("contains a spec with an expectation", function() { expect(true).toEqual(true); }); }); Main Jasmine Constructs Testsuite begins with a call to describe() Testcase “or spec” begins with a call to it() Testcase can contain one or more matcher(s)
  • 30. Unit Testing Cordova Apps Jasmine Example describe("SimpleMath", function() { var simpleMath; beforeEach(function() { simpleMath = new SimpleMath(); }); it("should be able to find factorial for positive number", function() { expect(simpleMath.getFactorial(3)).toEqual(6); }); it("should be able to find factorial for zero", function() { expect(simpleMath.getFactorial(0)).toEqual(1); }); afterEach(function() { simpleMath = null; }); });
  • 31. Unit Testing Cordova Apps Async Jasmine Tests Asynchronous JavaScript code refers to the code whose caller will NOT to wait until the execution completes. In order to get the results, the caller should pass callbacks which will be called with data result parameters in case of operation success or failure. Asynchronous JavaScript code mainly refers to Ajax code. In order to support Asynchronous operation testing, Jasmine provides: 1. An optional single parameter for its single spec. 2. This parameter has to be called if the asynchronous operation completes. 3. If this parameter is not called for by default 5 seconds then the test will fail (means operation timeout).
  • 32. Unit Testing Cordova Apps Async Jasmine Example describe("when doing asynchronous operation", function() { it("should be able to do the asynchronous operation", function(done) { var data = {}; var successCallBack = function(result) { console.log("success"); /* validate result parameter */ done(); }; var failureCallBack = function() { console.log("failure"); expect("Operation").toBe("passing"); /* force failing test */ done(); }; AsyncObject.asyncOperation(data, successCallBack, failureCallBack); }); });
  • 33. Agenda Apache Cordova Custom Plugins Custom Plugins Demo Cordova Cloud Push Notifications Demo Cordova Unit Testing Demo Cordova Cloud Push Notifications Unit Testing Cordova Apps Questions & Answers
  • 34. CORDOVA UNIT TESTING DEMO Demo Source: https://github.com/hazems/cordova-js-unit-testing
  • 35. Agenda Apache Cordova Custom Plugins Custom Plugins Demo Cordova Cloud Push Notifications Demo Cordova Unit Testing Demo Cordova Cloud Push Notifications Unit Testing Cordova Apps Questions & Answers

Hinweis der Redaktion

  1. Make sure that two emulators are running before starting / ATOM is started with the workspaces / Bluemix is opened … Hello everyone, my name is (Hazem Saleh) [Advisory engineer in IBM and Apache committer]. Today, I will be talking about advanced aspects of Apache Cordova.
  2. Before going into the details of this presentation, I would like to introduce myself in more details …
  3. So, today, I will be talking about some of the advanced aspects of Apache Cordova: We will know how to extend the capabilities of Apache Cordova by creating custom plugins. 2. We will empower Apache Cordova apps by using Cloud Push notifications. 3. We will understand how to unit test Cordova apps’ logic. We will also see their demos for each of these topics.
  4. Before going into Cordova custom plugins details, it is important to refresh our knowledge about Apache Cordova. Apache Cordova is a complete platform which allows us to develop cross-mobile platform apps using common web technologies (HTML, CSS and JavaScript) In order to do this, Apache Cordova uses a native component called WebView which hosts the Cordova app web files. Apache Cordova also allows accessing device hardware features using plugins. Apache Cordova provides the following core plugins: Camera, Media, Notifications, Storage, Events Geo-location, Device motion, compass, connection, contacts Files, Globalization and others
  5. 1. Although the core plugins of Apache Cordova covers a lot of business scenarios, you may need to have a plugin that is performing something which is not provided by Cordova core plugins. 2. One of the recommendations is to first search in Apache Cordova plugin registry for the feature that you are looking for since in 80% of the cases, you will find good plugins that are covering that the features that you are looking for. 3. If you do not find what you want in the plugin registry then you can start developing your own plugin
  6. This is the process of creating custom plugins in Apache Cordova …
  7. Read it …
  8. Read it …
  9. Then we define the plugin JavaScript API as follows: 1. We define our API parameters. 2. Map our parameters to cordova exec() method communicates your API parameters to native code, it has the following signature: 2.1. Success callback. 2.2. Failure callback. 2.3. Native Class Name. 2.4. Operation name. 2.5. Arguments.
  10. In the android native part (For example): 1. Our plugin class must extend CordovaPlugin and implement the execute() method. 2. The execute() method has the following parameters: 2.1. action parameter which maps to the sent action name. 2.2. JSONArray parameter which maps to the sent action parameters. 2.3. CallbackContext parameter which maps to the callback handler that will be called in success or failure. 2.4. Operation name. 2.5. Arguments.
  11. After defining the plugin interface and implementing the plugin, we can then start testing the plugin by: 1. Create a new Cordova app. 2. Add a platform to the Cordova app. 3. Install the plugin using plugman install command.
  12. Finally publish the plugin to npm registry.
  13. Checking Custom Plugins Demo.
  14. Demo steps: 1. Create a plugin skeleton using Plugman: > plugman create --name helloworld123 --plugin_id com.test.xyz.helloworld123 --plugin_version 0.0.1 2. Add android platform to the generated plugin: > plugman platform add --platform_name android 3. Edit Android generated code: > As you wish, do not forget to access any device information in the returned message. 4. Do not forget to define the accessing object name in the plugin’s plugin.xml as follows: <clobbers target="coolObj" /> 5. Create a Cordova project and add android support to it (build and run the project). 6. Add the plugin to the Cordova project as follows from the Cordova project root (then edit the code to call the plugin then Build and run): > plugman install --platform android --project platforms/android/ --plugin ../helloworld123/ 7. Call the plugin from your test Cordova app. 8. Do not forget to generate plugin package.json file for npm (totally optional): > plugman createpackagejson /path/to/your/plugin
  15. Now, let’s see how to empower Apache Cordova apps by using Cloud Push Notification.
  16. Read it as is …
  17. Read it as is …
  18. https://cordova.apache.org/docs/en/latest/guide/hybrid/plugins/index.html#integrating-with-plugin-search 1. Create bluemix mobile app. 2. Setup push notification for iOS and Android. 3. Create your Cordova app. 4. Add the push plugin to it (for android + iOS) 5. Show the code that can register the mobile client and receive push notifications. 6. Show how to receive push by tags. 7. Finally, show the panel from which you can send push notifications.
  19. Explain it using GCM or APNs.
  20. Add Bluemix Cordova Push plugin and configure them for both Android and iOS.
  21. Register device for Push notification by using registerDevice() of MFPPush.
  22. Use registerNotificationsCallback() to register the callback for receiving notifications. For receiving notifications on specific tags, we can subscribe in tags using subscribe() method of MFPPush. We can also un-subscribe from tags using unsubscribe() method of MFPPush.
  23. Test sending push notifications from Bluemix administration.
  24. Now, let’s see the push demo.
  25. Push Notification Demo steps: 1. Demonstrate the code. 2. Send to all devices. 3. Send to a specific tag "Tag1", no devices will receive. 4. Subscribe in "Tag1". 5. Send to a specific tag "Tag1" to receive push notifications.
  26. Now, let’s see how to unit test Cordova apps logic.
  27. Read as is …
  28. Read as is …
  29. Read as is …
  30. Just highlight the usage of beforeEach() and afterEach().
  31. Read as is …
  32. Read as is …
  33. Now, let’s see the Cordova unit testing Demo.
  34. Jasmine Demo steps: 1. Explain briefly UserServiceSpec.js and WeatherServiceSpec.js files. 2. Run SpecRunner.html 3. Show how Jasmine can be integrated with JavaScript test runners like Karma by explaining config.js. 4. Run silentTests.sh file. 5. Check code coverage HTML report to show the amount of code that is tested. Jasmine is integrated with JavaScript test runners which allows it to be part of CI tools that can automate running JavaScript Tests.
  35. Questions and answers