Saturday, February 25, 2017

Jenkins - Email Configuration (Example- Gmail)

We always struggle to configure our Email (either Personal/Office) with Jenkins. This article will help you to come out from that problem. I have taken "Gmail-Configuration" as example in this demonstration since Gmail is widely used.

First change the setting in Gmail to access less secure applications:- 
  • ·         Login to your Gmail account with valid credentials
  • ·         Navigate to "https://myaccount.google.com/security" url
  • ·         Enable "Allow less secure apps" option as shown in the below diagram 

Install Email-ext plugin:-
  • ·         Install Email-ext plugin at plug-in install page of Jenkins 

Configure System: - (Manage Jenkins > Configure System)
  • ·         Make sure you have logged into Jenkins as admin
  • ·         In Extended E-mail Notification section
  • ·         Enter your SMTP server name to “SMTP server”
    •  In case of Gmail – smtp.gmail.com
  • ·          Enter “Default user E-mail suffix
    • In case of Gmail – @gmail.com
  • ·         Click “Advanced”
  • ·         Click “Use SMTP Authentication”
  • ·         Enter required information(Gmail-Username & Password)
  • ·         Check “Test configuration by sending test e-mail”
  • ·         Click “Test configuration” to send test email
  • ·         Click “Save” in the bottom of the page

Configure a project to send email at every build:-
  • ·         Click “Add post-build action”
  • ·         Click “Editable Email Notification”
  • ·         Click “Advanced Settings…”
  • ·         Click “Add Trigger”
  • ·         Click “Always”
  • ·         Save 
Run your Test:-
  • ·         Click “Build Now” / “Build with Parameters” as per your requirement
  • ·         Check Console output and received email as shown below


XPath & Xpath Axes

XPath:- Xpath is used to locate a web element based on its XML path. XML stands for Extensible Mark-up Language and is used to store, organize and transport arbitrary data. It stores data in a key-value pair which is very much similar to HTML tags.

XPath Axes: - Plays a major role to handle dynamic web elements.

·         Axis details: -

AXIS Name
Result
ancestor
Selects all ancestors (parent, grandparent, etc.) of the current node
ancestor-or-self
Selects all ancestors (parent, grandparent, etc.) of the current node and the current node itself
attribute
Selects all attributes of the current node
child
Selects all children of the current node
descendant
Selects all descendants (children, grandchildren, etc.) of the current node
descendant-or-self
Selects all descendants (children, grandchildren, etc.) of the current node and the current node itself
following
Selects everything in the document after the closing tag of the current node
following-sibling
Selects all siblings after the current node
namespace
Selects all namespace nodes of the current node
parent
Selects the parent of the current node
preceding
Selects all nodes that appear before the current node in the document, except ancestors, attribute nodes and namespace nodes
preceding-sibling
Selects all siblings before the current node
self
Selects the current node

·         Syntax -
axisname
::
nodetest
[predicate]
an axis
symbol
a node-test
zero or more predicates
Defines the tree-relationship between the selected nodes and the current node
Constant
Identifies a node within an axis
To further drill down the selected node-set

·         Examples of axis usage: -

Example
Result
child::book
Selects all book nodes that are children of the current node
attribute::lang
Selects the lang attribute of the current node
child::*
Selects all element children of the current node
attribute::*
Selects all attributes of the current node
child::text()
Selects all text node children of the current node
child::node()
Selects all children of the current node
descendant::book
Selects all book descendants of the current node
ancestor::book
Selects all book ancestors of the current node
ancestor-or-self::book
Selects all book ancestors of the current node - and the current as well if it is a book node
child::*/child::price
Selects all price grandchildren of the current node

·         Xpath example with Axis: -I have given few examples. Please try to use other axes with your own. If you are facing any issues, please let me know.

AXIS Names
XML
Xpath
ancestor
<root>
    <foo>
        <bar attr="xxx"></bar>
    </foo>
    <foo>
        <bar attr="val"></bar>
    </foo>
    <foo>
        <bar attr="zzz"></bar>
    </foo>
</root>
//*[ancestor::foo[bar[@attr="val"]]] or root/foo/bar[ancestor::foo[bar[@attr="val"]]]
ancestor-or-self
<root>
    <item key="a">
        <item key="b">
            <item key="c">
                <item key="d"/>
            </item>
        </item>
        <item key="e">
            <item key="f">
                <item key="g"/>
            </item>
        </item>
    </item>
</root>
ancestor-or-self::*[parent::item[@key='a']]
attribute
<Employees>
    <Employee id="3">
        <age>40</age>
        <name>Tom</name>
        <gender>Male</gender>
        <role>Manager</role>
    </Employee>
    <Employee id="4">
        <age>25</age>
        <name>Meghna</name>
        <gender>Female</gender>
        <role>Manager</role>
    </Employee>
</Employees>
//Employee[@id='4'] or /Employees/Employee[@id='4']
child
child::* selects all element children of the context node
child::text() selects all text node children of the context node
child::node() selects all the children of the context node, whatever their node type
descendant
<div id="books">
  <table>
    <tr><td class="title">Lord of the Rings</td><td class="author">JRR Tolkein</td></tr>
    <tr><td class="title">The Hitch-Hikers Guide to the Galaxy</td><td class="author">Douglas Adams</td></tr>
  </table>
</div>
//id('books')//td[@class='title']
or //id('books')//td[@class='title']









Topics to be covered

Tools & Technologies :-



Rough Mind map :-



BDD - Quick Start Guide

Behavior-driven development (BDD) is a software development methodology in which an application is specified and designed by describing how its behavior should appear to an outside observer. 

Principles of BDD: -
  • First define a test set for the unit/module
  • Make the test fail
  • Then implement the failed unit
  • Finally verify that the implementation of the unit makes the tests success
Concepts to Remember: -
  • Keywords:
    • Feature: List of scenarios.
    • Scenario: Business rule through list of steps with arguments.
    • Given: Some precondition step
    • When: Some key actions
    • Then: To observe outcomes or validation
    • And, But: To enumerate more Given, When, Then steps. But is mainly used for negative scenarios
    • Scenario Outline: List of steps for data-driven as an Examples and <placeholder>
    • Examples: Container for s table
    • Background: List of steps run before each of the scenarios
  • Symbols:
    • """ (Doc Strings)
    • | (Data Tables)
    • @ (Tags/Labels): To group Scenarios 
    • <> (placeholder)
    • "" (scenario parameter container)
    • # (Comments)

  • Feature File Definition Template: -
        @tag
          Feature: Title of your feature
                  I want to use this template for my feature file

          @tag1
          Scenario: Title of your scenario
          Given I want to write a step with precondition
             And some other precondition
          When I complete action
             And some other action
             And yet another action
          Then I validate the outcomes
          And check more outcomes

         @tag2
          Scenario Outline: Title of your scenario outline
          Given I want to write a step with <name>
          When I check for the <value> in step
          Then I verify the <status> in step

          Examples:
          | name    |value | status |
          | name1  |  5       | success|
          | name2    7   | Fail   |

  • Step Definition: -  When Cucumber executes a Step in a Scenario it will look for a matching Step Definition to execute. A Step Definition is a small piece of code with a pattern attached to it. The pattern is used to link the step definition to all the matching Steps, and the code is what Cucumber will execute when it sees a Gherkin Step.
    • Example: - Using Java & Cucumber


  • Runner File: - Mainly it's the driver to drive whole test execution.
    • Options: -
      • -g, --glue PATH -Where glue code (step definitions and hooks) is loaded from.
      • -f, --format FORMAT[:PATH_OR_URL]  How to format results. Goes to STDOUT unless PATH_OR_URL is specified. Built-in FORMAT types: junit, html, pretty, progress, json. FORMAT can also be a fully qualified class name.
      • -t, --tags TAG_EXPRESSION - Only run scenarios tagged with tags matching TAG_EXPRESSION.
      • -n, --name REGEXP - Only run scenarios whose names match REGEXP.
      •  -d, --[no-]-dry-run - Skip execution of glue code.
      • -m, --[no-]-monochrome - Don't colour terminal output.
      • -s, --[no-]-strict - Treat undefined and pending steps as errors.
      • --dotcucumber PATH_OR_URL-Where to write out runtime information. PATH_OR_URL can be a file system path or a URL
      • -v, --version - Print version.
      • -h, --help - You're looking at 
    • Example: - Using Java & Cucumber


Market Leading Tools: -
  • Cucumber: - https://cucumber.io/
  • JBehave: - http://jbehave.org/
  • SpecFlow:- http://specflow.org/
  • Serenity: - http://www.thucydides.info/#/
  • Spinach: - http://www.rubydoc.info/github/codegram/spinach/master




Robot Framework - Quick Start Guide


Robot Framework is a generic test automation framework for acceptance testing and acceptance test-driven development (ATDD). It has easy-to-use tabular test data syntax and it utilizes the keyword-driven testing approach. Its testing capabilities can be extended by test libraries implemented either with Python or Java, and users can create new higher-level keywords from existing ones using the same syntax that is used for creating test cases.

Key Highlights :- 
  • Lightweight, simple, fast
  • Clear & easy learning curve
  • Open source, Keyword/Data Driven approach
  • Many python libraries available
  • BDD support makes sure everyone is speaking same language
  • Can be used by non-technical QA 
  • Easy to read the tests from business stand point of view
  • Large online community
References :- 
  • Robot Framework Ecosystem :- http://robotframework.org/
  • Robot Framework User Guide :- http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html
  • Selenium with Pyhton :- http://selenium-python.readthedocs.io/
  • Selenium 2 Library :- http://robotframework.org/Selenium2Library/Selenium2Library.html
  • Python :-  
    • For v.2 +  :- https://docs.python.org/2.7/tutorial/index.html
    • For v.3 +  :- https://docs.python.org/3/tutorial/index.html
  • Python Repository (Library Files) :- https://pypi.python.org/pypi
Editor Options :- 
  • IDE :- PyCharm(Best), Eclipse(Plugin:- PyDev), Brackets
  • Text Editors :- Notepad ++, Emacs, Vim
  • RIDE