©2017 Faichi Solutions Pvt. Ltd.
Automate Testing with Behat,
Selenium, PhantomJs and
Nightwatch.js
©2017 Faichi Solutions Pvt. Ltd. 2
Nikhil Sukul
Senior Drupal Architect
Faichi Solutions LLC
nikhilsukul
nikhilsukul
Nikhil is an open source enthusiast and
contributor to Drupal and its community. He
has an overall software experience of 17+
years and has been active in Drupal space
since last 9 years.
Speakers, who?
Gaurav Bajpai
Senior Drupal Developer
Faichi Solutions LLC
gaurav02b
gaurav-bajpai
Gaurav is an active member and contributor to
Drupal community. His overall Drupal experience is
5+ years. He is Acquia certified developer.
©2017 Faichi Solutions Pvt. Ltd. 3
©2017 Faichi Solutions Pvt. Ltd. 4
©2017 Faichi Solutions Pvt. Ltd. 5
©2017 Faichi Solutions Pvt. Ltd. 6
©2017 Faichi Solutions Pvt. Ltd. 7
©2017 Faichi Solutions Pvt. Ltd.
What is Testing
©2017 Faichi Solutions Pvt. Ltd. 9
• In general, testing is finding out how well something
works,
• Software testing is the process of evaluation a software
item to detect differences between given input and
expected output.
©2017 Faichi Solutions Pvt. Ltd.
How to do Testing
©2017 Faichi Solutions Pvt. Ltd. 11
©2017 Faichi Solutions Pvt. Ltd.
Why Testing
©2017 Faichi Solutions Pvt. Ltd. 13
• To point out the defects and errors made during the
development phases.
• Makes Customer’s reliability and their satisfaction in the
application.
• Effective performance of the software.
• Application resulting to failure is very expensive in future
or in later stages of the development.
©2017 Faichi Solutions Pvt. Ltd. 14
©2017 Faichi Solutions Pvt. Ltd.
Who will Test?
©2017 Faichi Solutions Pvt. Ltd.
©2017 Faichi Solutions Pvt. Ltd.
©2017 Faichi Solutions Pvt. Ltd.
They will Test
©2017 Faichi Solutions Pvt. Ltd.
Types of Testing
(By Execution)
©2017 Faichi Solutions Pvt. Ltd. 20
Manual Testing Automation TestingManual Testing Automation Testing
©2017 Faichi Solutions Pvt. Ltd. 21
Automation Testing Manual Testing
It is very much helpful in
regressions testing.
To execute the test cases first
time.
Runs test cases significantly
faster than human resources.
Running tests manually can be
very time consuming.
Good for automating the Build
Verification Testing (BVT) .
To execute the Build Verification
Testing (BVT) is very mundane
and tiresome.
Initial cost is high. Manual testing requires less cost
than automation.
©2017 Faichi Solutions Pvt. Ltd. 22
Automated Testing
©2017 Faichi Solutions Pvt. Ltd. 23
Real browser testing
Real Browsers are running and performing functions or
commands in front of users in UI. Examples of Real
browsers are Google Chrome, Firefox, and Internet
Explorer etc.
©2017 Faichi Solutions Pvt. Ltd. 24
Headless browser testing
• Headless browsers are basically
web browsers that without a
graphical user interface.
• Examples of Headless browsers
are PhantomJS and ZombieJS etc.
©2017 Faichi Solutions Pvt. Ltd. 25
Real vs Headless browser testing
• Headless Browsers faster than real browsers:
– Real browsers take time opening, rendering html, CSS, Javascript
and images while headless browsers don’t require it. Headless
browsers will start performing functions without waiting for page
to load completely.
• Headless browsers are not representing real users:
– user bugs like images are crashing or not as UI is not showing up
is very difficult to detect in headless browsers.
• Error detection in real browsers is easy pesy:
– In Real browser as functions are performing in front of user and
he can interact with it so he can easily detect where the tests
goes fail. And can easily debug if anything goes wrong.
• Headless browsers does not support Ajax.
©2017 Faichi Solutions Pvt. Ltd. 26
©2017 Faichi Solutions Pvt. Ltd. 27
Selenium WebDriver is a collection of open source APIs which
are used to automate the testing of a web application and it is
platform-independent.
©2017 Faichi Solutions Pvt. Ltd. 28
How Selenium WebDriver works?
You can Download Selenium Jar from http://selenium-
release.storage.googleapis.com/index.html
Chrome
Driver
IE Driver
©2017 Faichi Solutions Pvt. Ltd. 29
• Behat is an open source Behavior-Driven Development
framework for PHP.
• Behat is a tool to test the behavior of any application,
described in special language called Gherkin.
• Gherkin is a Business Readable, Domain Specific Language
created especially for behavior descriptions. It gives you
the ability to remove logic details from behavior tests.
©2017 Faichi Solutions Pvt. Ltd. 30
Feature: Some terse yet descriptive text of what is desired
In order to realize a named business value
As an explicit system actor
I want to gain some beneficial outcome which furthers the goal
Scenario: Some determinable business situation
Given some precondition
And some other precondition
When some action by the actor
And some other action
And yet another action
Then some testable outcome is achieved
And something else we can check happens too
Scenario: A different situation
...
©2017 Faichi Solutions Pvt. Ltd. 31
• Mink is the browser simulator for Behat.
• It is a browser emulator abstraction layer. It hides
emulator differences behind a single, consistent API.
• Mink Support for both in-browser and headless browser
emulators. It is a PHP 5.3+ library.
You can Download and Install Behat and Mink:
http://docs.behat.org/en/v2.5/cookbook/behat_and_mink.html
©2017 Faichi Solutions Pvt. Ltd. 32
“PhantomJS is a scripted, headless browser used for
automating web page interaction. PhantomJS
provides a JavaScript API enabling automated
navigation, screenshots, user behavior and assertions
making it a common tool used to run browser-based
unit tests in a headless system like a continuous
integration environment.” - wikipedia
You can Download and Install PhantomJS:
http://phantomjs.org/download.html
©2017 Faichi Solutions Pvt. Ltd. 33
• Headless website testing:
– Run functional tests along with the frameworks like QUnit, Jasmine,
Mocha, Capybara, WebDriver etc.
• Screen capture:
– taking screen capture programmatically.
• The development can be very easier:
– While developing the UI, you can write the code by selecting the HTML
element wherever you wanted.
• Test framework:
– PhantomJS itself is not a test framework, it is only used to launch the
tests via a suitable test runner.
PhantomJS is a good:
©2017 Faichi Solutions Pvt. Ltd. 34
CasperJS is a navigation scripting & testing utility for PhantomJS
headless browser, written in Javascript.
CasperJs
©2017 Faichi Solutions Pvt. Ltd. 35
• A Browser Automation tool.
• It is an easy to use Node.js based End-to-End (E2E) testing
solution for browser based apps and websites.
• It uses the powerful W3C WebDriver API to perform
commands and assertions on DOM elements.
You can Download and Install NightWatch.js:
http://nightwatchjs.org/getingstarted#installation
©2017 Faichi Solutions Pvt. Ltd. 36
Nightwatch.js architecture
©2017 Faichi Solutions Pvt. Ltd.
What to use
and when?
©2017 Faichi Solutions Pvt. Ltd. 38
©2017 Faichi Solutions Pvt. Ltd. 39
References:
http://www.softwaretestingclass.com/automation-testing-vs-manual-testing/
http://www.teluguone.com/teluguoneUserFiles/Nothing can stop
Automation(1).png
http://www.seleniumhq.org/projects/ide/selenium-ide.gif
http://nightwatchjs.org/guide#theory-of-operation
http://www.slideshare.net/sethmcl/join-the-darkside-nightwatchjs
https://www.youtube.com/watch?v=-eJ2cZXyJ0E
http://www.algoworks.com/blog/choosing-your-automated-testing-frameworks-
phantomjscasperjs-vs-selenium/
http://craveco.de/posts/2016/03/16/part-2-automated-drupal-testing-behat-
selenium-and-headless-firefox
http://www.pngall.com/wp-content/uploads/2016/06/Browsers-
Transparent.png
http://economictimes.indiatimes.com/definition/selenium-web-driver
http://mink.behat.org/en/latest
http://phantomjs.org
https://upload.wikimedia.org/wikipedia/commons/thumb/b/b3/Terminalicon2.p
ng/480px-Terminalicon2.png
http://shashikantjagtap.net/running-behat-scenarios-with-pahntomjs
41
CONNECT WITH US, ASK FOR A DEMO !
Faichi Solutions, LLC
640 W. California Ave Suite 210 Sunnyvale, CA 94086
Phone: +1 (408) 769-4941
Email: inform@faichi.com
FAICHI SOLUTIONS PVT LTD
USA:
OFFICE NO. 230, 640 WEST
CALIFORNIA AVENUE SUITE 210
SUNNYVALE, CA 94086
TEL: +1 (408) 769-4941
INDIA:
ACCORD IT PARK, BANER ROAD,
PUNE, MAHARASHATRA-411045
PH. NO. +91-20-65291435
THANK YOU

Automate testing with behat, selenium, phantom js and nightwatch.js (5)

  • 1.
    ©2017 Faichi SolutionsPvt. Ltd. Automate Testing with Behat, Selenium, PhantomJs and Nightwatch.js
  • 2.
    ©2017 Faichi SolutionsPvt. Ltd. 2 Nikhil Sukul Senior Drupal Architect Faichi Solutions LLC nikhilsukul nikhilsukul Nikhil is an open source enthusiast and contributor to Drupal and its community. He has an overall software experience of 17+ years and has been active in Drupal space since last 9 years. Speakers, who? Gaurav Bajpai Senior Drupal Developer Faichi Solutions LLC gaurav02b gaurav-bajpai Gaurav is an active member and contributor to Drupal community. His overall Drupal experience is 5+ years. He is Acquia certified developer.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
    ©2017 Faichi SolutionsPvt. Ltd. What is Testing
  • 9.
    ©2017 Faichi SolutionsPvt. Ltd. 9 • In general, testing is finding out how well something works, • Software testing is the process of evaluation a software item to detect differences between given input and expected output.
  • 10.
    ©2017 Faichi SolutionsPvt. Ltd. How to do Testing
  • 11.
  • 12.
    ©2017 Faichi SolutionsPvt. Ltd. Why Testing
  • 13.
    ©2017 Faichi SolutionsPvt. Ltd. 13 • To point out the defects and errors made during the development phases. • Makes Customer’s reliability and their satisfaction in the application. • Effective performance of the software. • Application resulting to failure is very expensive in future or in later stages of the development.
  • 14.
  • 15.
    ©2017 Faichi SolutionsPvt. Ltd. Who will Test?
  • 16.
  • 17.
  • 18.
    ©2017 Faichi SolutionsPvt. Ltd. They will Test
  • 19.
    ©2017 Faichi SolutionsPvt. Ltd. Types of Testing (By Execution)
  • 20.
    ©2017 Faichi SolutionsPvt. Ltd. 20 Manual Testing Automation TestingManual Testing Automation Testing
  • 21.
    ©2017 Faichi SolutionsPvt. Ltd. 21 Automation Testing Manual Testing It is very much helpful in regressions testing. To execute the test cases first time. Runs test cases significantly faster than human resources. Running tests manually can be very time consuming. Good for automating the Build Verification Testing (BVT) . To execute the Build Verification Testing (BVT) is very mundane and tiresome. Initial cost is high. Manual testing requires less cost than automation.
  • 22.
    ©2017 Faichi SolutionsPvt. Ltd. 22 Automated Testing
  • 23.
    ©2017 Faichi SolutionsPvt. Ltd. 23 Real browser testing Real Browsers are running and performing functions or commands in front of users in UI. Examples of Real browsers are Google Chrome, Firefox, and Internet Explorer etc.
  • 24.
    ©2017 Faichi SolutionsPvt. Ltd. 24 Headless browser testing • Headless browsers are basically web browsers that without a graphical user interface. • Examples of Headless browsers are PhantomJS and ZombieJS etc.
  • 25.
    ©2017 Faichi SolutionsPvt. Ltd. 25 Real vs Headless browser testing • Headless Browsers faster than real browsers: – Real browsers take time opening, rendering html, CSS, Javascript and images while headless browsers don’t require it. Headless browsers will start performing functions without waiting for page to load completely. • Headless browsers are not representing real users: – user bugs like images are crashing or not as UI is not showing up is very difficult to detect in headless browsers. • Error detection in real browsers is easy pesy: – In Real browser as functions are performing in front of user and he can interact with it so he can easily detect where the tests goes fail. And can easily debug if anything goes wrong. • Headless browsers does not support Ajax.
  • 26.
  • 27.
    ©2017 Faichi SolutionsPvt. Ltd. 27 Selenium WebDriver is a collection of open source APIs which are used to automate the testing of a web application and it is platform-independent.
  • 28.
    ©2017 Faichi SolutionsPvt. Ltd. 28 How Selenium WebDriver works? You can Download Selenium Jar from http://selenium- release.storage.googleapis.com/index.html Chrome Driver IE Driver
  • 29.
    ©2017 Faichi SolutionsPvt. Ltd. 29 • Behat is an open source Behavior-Driven Development framework for PHP. • Behat is a tool to test the behavior of any application, described in special language called Gherkin. • Gherkin is a Business Readable, Domain Specific Language created especially for behavior descriptions. It gives you the ability to remove logic details from behavior tests.
  • 30.
    ©2017 Faichi SolutionsPvt. Ltd. 30 Feature: Some terse yet descriptive text of what is desired In order to realize a named business value As an explicit system actor I want to gain some beneficial outcome which furthers the goal Scenario: Some determinable business situation Given some precondition And some other precondition When some action by the actor And some other action And yet another action Then some testable outcome is achieved And something else we can check happens too Scenario: A different situation ...
  • 31.
    ©2017 Faichi SolutionsPvt. Ltd. 31 • Mink is the browser simulator for Behat. • It is a browser emulator abstraction layer. It hides emulator differences behind a single, consistent API. • Mink Support for both in-browser and headless browser emulators. It is a PHP 5.3+ library. You can Download and Install Behat and Mink: http://docs.behat.org/en/v2.5/cookbook/behat_and_mink.html
  • 32.
    ©2017 Faichi SolutionsPvt. Ltd. 32 “PhantomJS is a scripted, headless browser used for automating web page interaction. PhantomJS provides a JavaScript API enabling automated navigation, screenshots, user behavior and assertions making it a common tool used to run browser-based unit tests in a headless system like a continuous integration environment.” - wikipedia You can Download and Install PhantomJS: http://phantomjs.org/download.html
  • 33.
    ©2017 Faichi SolutionsPvt. Ltd. 33 • Headless website testing: – Run functional tests along with the frameworks like QUnit, Jasmine, Mocha, Capybara, WebDriver etc. • Screen capture: – taking screen capture programmatically. • The development can be very easier: – While developing the UI, you can write the code by selecting the HTML element wherever you wanted. • Test framework: – PhantomJS itself is not a test framework, it is only used to launch the tests via a suitable test runner. PhantomJS is a good:
  • 34.
    ©2017 Faichi SolutionsPvt. Ltd. 34 CasperJS is a navigation scripting & testing utility for PhantomJS headless browser, written in Javascript. CasperJs
  • 35.
    ©2017 Faichi SolutionsPvt. Ltd. 35 • A Browser Automation tool. • It is an easy to use Node.js based End-to-End (E2E) testing solution for browser based apps and websites. • It uses the powerful W3C WebDriver API to perform commands and assertions on DOM elements. You can Download and Install NightWatch.js: http://nightwatchjs.org/getingstarted#installation
  • 36.
    ©2017 Faichi SolutionsPvt. Ltd. 36 Nightwatch.js architecture
  • 37.
    ©2017 Faichi SolutionsPvt. Ltd. What to use and when?
  • 38.
  • 39.
    ©2017 Faichi SolutionsPvt. Ltd. 39 References: http://www.softwaretestingclass.com/automation-testing-vs-manual-testing/ http://www.teluguone.com/teluguoneUserFiles/Nothing can stop Automation(1).png http://www.seleniumhq.org/projects/ide/selenium-ide.gif http://nightwatchjs.org/guide#theory-of-operation http://www.slideshare.net/sethmcl/join-the-darkside-nightwatchjs https://www.youtube.com/watch?v=-eJ2cZXyJ0E http://www.algoworks.com/blog/choosing-your-automated-testing-frameworks- phantomjscasperjs-vs-selenium/ http://craveco.de/posts/2016/03/16/part-2-automated-drupal-testing-behat- selenium-and-headless-firefox http://www.pngall.com/wp-content/uploads/2016/06/Browsers- Transparent.png http://economictimes.indiatimes.com/definition/selenium-web-driver http://mink.behat.org/en/latest http://phantomjs.org https://upload.wikimedia.org/wikipedia/commons/thumb/b/b3/Terminalicon2.p ng/480px-Terminalicon2.png http://shashikantjagtap.net/running-behat-scenarios-with-pahntomjs
  • 41.
    41 CONNECT WITH US,ASK FOR A DEMO ! Faichi Solutions, LLC 640 W. California Ave Suite 210 Sunnyvale, CA 94086 Phone: +1 (408) 769-4941 Email: inform@faichi.com
  • 42.
    FAICHI SOLUTIONS PVTLTD USA: OFFICE NO. 230, 640 WEST CALIFORNIA AVENUE SUITE 210 SUNNYVALE, CA 94086 TEL: +1 (408) 769-4941 INDIA: ACCORD IT PARK, BANER ROAD, PUNE, MAHARASHATRA-411045 PH. NO. +91-20-65291435 THANK YOU