Integrating Git with Jenkins

1 comments

Problem

I want to check-out my automation code from Git to build in Jenkins CI environment.

Pre-Conditions

  • Jenkins is installed and running.
  • Git repository is available.
  • Git user is available.

Solution

Install Git client on CI server
Windows: Download Git installer and run through Installation Wizard

  1. Install "Git plugin" in Jenkins
  • Click "Manage Jenkins"
  • Click "Manage Plugins"
  • Click "Available" tab
  • Enter "Git plugin" in Search box
  • Select "Git plugin"
  • Click "Install without restart"
     3. Add Credentials for Git.
         There are 2 ways to authenticate to Git: via HTTPS 
         To Add HTTPS Credentials
    • In Jenkins GUI: Click "Credentials"
    • Click "Global Credentials"
    • Click "Add Credentials"
    • Select "Username with password"
    • Enter username in Firstname_Lastname@gmail.com format
    • Enter domain password
    • Click OK


    4. Create Jenkins Job.
    • In Jenkins GUI: Click "New Item"
    • Enter Job name
    • Select "Freestyle project"
    • Click OK
    • Select Git under "Source Code Management" section
    • Enter Git repository URL (can be copied from Gitlab UI)
    • Enter branches to be fetched (*/master is a good default)
    •  Add build triggers as necessary. Expand for details...
    • Click Save (we don't add build step in this recipe)

    End State

    • Git plugin is installed in Jenkins
    • Git Credentials are added
    • Jenkins job fetching the code from Git is created and the code is fetched to CI server.

    Limitations / Known issues

    • Windows: Fetching may hang depending on which version of git client (git bash vs git cmd) is in your %PATH%.
      If encountered freezing of fetching, update %PATH% environment variable to another version (I.g. update entry from %GIT_HOME%\cmd to %GIT_HOME%\bin).
    • Jenkins Git plugin is suitable for any kind of git repositories but it contains only basic functionality. If one is using Gitlab or GitHub, specific Gitlab andGitHub Jenkins plugins might be the preferable solution.
      For more documentation please see corresponding plugin pages.


    How to switch between Angular page and Iframe in Protractor

    1 comments
    To switch to an Iframe in Protractor, there is a method to serve the purpose. Use switchTo().frame() method to switch focus to Iframe. To get back the focus from Iframe to Angular paga, use switchTo().defaultContent() method.

    Below is the sample code to explain this case. Assuming there is an Iframe and need to click an element in Iframe. Once the element is clicked, Iframe disappears automatically, then swith the focus to Angular page.

    browser.driver.switchTo().frame('Frame');
    browser.driver.findElement(By.className("insert-btn")).click();
    browser.switchTo().defaultContent().then(function() {
       var elm=element.all(by.repeater('data in Data.items')).filter(function(elem, index) {
           return elem.getText().then(function(text) {
               return (text.indexOf("HTML")>-1);
    });
    }).then(function(filteredElements){
        filteredElements[0].click();
          });
    });


    How to select an item in a list in Protractor

    0 comments
    When we need to select an element in the list of element, we need to filter them out with the required criteria like visible text and then perform the action (click).

    We use filter method to get the array of required elements and then perform the action on the array of elements in a callback function.

    See the following sample code to understand better.

    var editTemplateByName = function(templateName) {
        element.all(by.repeater('template in templates')).filter(function(elem, index) {
            return elem.getText().then(function(text) {
                return (text.indexOf(templateName)>-1);
            });
        }).then(function(filteredElements){
           element(by.buttonText('or Edit')).click();
        });
    };

    call the method: editTemplateByName('HTML');

    Capybara brief introduction

    0 comments
    First of all, its open source ruby language based framework which uses selenium web-driver internally to interact with web application controls.
    It's designed specifically for testing a web application through the UI, so it has useful methods for asserting that the page is correct.
    It has the built-in mechanism for handling synchronization issues that we run into while testing web applications.

    It has a very good API support to interact with the application controls. I see there is a discussion forum to discuss the issues/solutions.

    We can integrate BDD frameworks like Cucumber and RSpec with Capybary for better acceptance test results.

    Links:
    API Support
    Discussion Forum
    Sample Code

    Default Test Frameworks in Protractor v3

    0 comments
    By default, Protractor v3 supports Jasmine and Mocha test frameworks. Cucumber is no longer included by default as of version 3.0. However, you can integrate Cucumber with Protractor with the custom framework option. For more details, see the Protractor Cucumber Framework site or the Cucumber GitHub site.

    Jasmine:

    Protractor v3 default test framework is Jasmine 2.x. If you want to upgrade to Jasmine 2.x from 1.3, follow the Jasmine upgrade guide.


    Mocha:

    If you would like to use Mocha as test framework, you need to use BDD interface and Chai assertion libraries with Chai As Promised.

    Note: Limited support for Mocha is available as of December 2013. For more information, see the Mocha documentation site.