Robot Framework- Working with Excel Library(Part-3)

After our installation and fetching data from excel we would move towards writing data into excel.
Robot Framework with Excel Library

Scenario:- How to publish robot framework run results into Excel?

We can connect on Fb,G+,Twitter to find what we do next?.

Solution:- 
Step1:- Create excel at run time with given heading inside Results folder.(At "Suite Setup")
Step2:- Add test details (at Test Case "Setup") to newly created excel
Step3:- Append the results(pass/fail) to the excel after the run of the Test case in Robot Framework.(at Test Case "Teardown")


Download

Code:-

*** Settings ***
Suite Setup       Create Result File
Library           ExcelLibrary
Library           OperatingSystem
Library           robot.api.logger
Library           Selenium2Library
Library           String

*** Variables ***
${sFileName}      ${EXECDIR}\\Data\\TestSheet.xls    # DataSheet
${sResultFilePath}    ${EXECDIR}\\Results\\Results    # ResultFile

*** Test Cases ***
TC01_Fetch Data From Excel & Write Results
    [Setup]    Append Test Details to Results File
    Open given Excel file    ${sFileName}
    ${sURL}    Get data from Excel with given column    Data    TC_02    Url
    Log    ${sURL}
    [Teardown]    Publish Test Case Result

*** Keywords ***
Open given Excel file
    [Arguments]    ${sFileName}
    #Check that the given Excel Exists
    ${inputfileStatus}    ${msg}    Run Keyword And Ignore Error    OperatingSystem.File Should Exist    ${sFileName}
    Run Keyword If    "${inputfileStatus}"=="PASS"    info    ${sFileName} Test data file exist    ELSE    Fail    Cannot locate the given Excel file.
    Open Excel    ${sFileName}

Get data from Excel with given column
    [Arguments]    ${sSheetName}    ${sTestCaseNo}    ${sColumnName}
    log    ${sColumnName}
    ${colCount}    Get Column Count    ${sSheetName}
    : FOR    ${y}    IN RANGE    0    ${colCount}
    \    ${header}    Read Cell Data By Coordinates    ${sSheetName}    ${y}    0
    \    #Check if this is the given header
    \    Run Keyword If    "${header}"=="${sColumnName}"    Set Test Variable    ${colNum}    ${y}
    log    ${colNum}
    #Get the total rows in the Sheet
    ${iTotalRows}    ExcelLibrary.Get Row Count    ${sSheetName}
    : FOR    ${iRowNo}    IN RANGE    1    ${iTotalRows}+1
    \    ${TC_Num}    Read Cell Data By Coordinates    ${sSheetName}    0    ${iRowNo}
    \    #Incase TestCase No is same , fetch the data from same row and given column No
    \    ${sSearchedData}    Run Keyword If    "${sTestCaseNo}"=="${TC_Num}"    ExcelLibrary.Read Cell Data By Coordinates    ${sSheetName}    ${colNum}
    \    ...    ${iRowNo}
    \    Run Keyword If    "${sTestCaseNo}"=="${TC_Num}"    Exit For Loop
    [Return]    ${sSearchedData}

Create Result File
    [Documentation]    Create a result file at runtime
    ${sResultFile}    Add TimeStamp to File    ${sResultFilePath}
    #Create Result file at the given location
    Create File    ${sResultFile}
    Append to file    ${sResultFile}    TC_Number\tTC_Desc\tStatus\tComments\n
    Set Global Variable    ${sResultFile}    ${sResultFile}

Add TimeStamp to File
    [Arguments]    ${sResultFilePath}
    [Documentation]    Creating the Name of the Results file based on the current TimeStamp
    ${date}    OperatingSystem.Run    echo %date%
    ${yyyy}    ${mm}    ${dd}    Split String    ${date}    /
    ${time}    OperatingSystem.Run    echo %time%
    ${hh}    ${min}    ${sec}    Split String    ${time}    :
    #Creating TimeStamp
    ${timestamp}    Set Variable    ${mm}${dd}${yyyy}_${hh}${min}
    log    ${timestamp}
    ${sfileName}    Set Variable    ${sResultFilePath}_${timestamp}.xls
    [Return]    ${sfileName}

Append Test Details to Results File
    [Documentation]    Adding Test Case Details to Results File
    #Fetch TC No
    ${sTCNo}    ${sTestDesc}    Split String    ${TESTNAME}    _
    append to file    ${sResultFile}    ${sTCNo}\t${sTestDesc}\t

Publish Test Case Result
    [Documentation]    Adding TC fail/pass results to Result File
    append to file    ${sResultFile}    ${TEST STATUS}\t${TEST MESSAGE}\n
    Close All Browsers


Learn more Robot Framework
Automation Testing using Selenium                                                                               

Robot Framework- Working with Excel Library(Part-2)

Life is short..share while you still have knowledge.

We started with installation of Excel Library in Robot Framework , today we would focus on utilizing the keywords present in the Excel Library.
Next is publishing run results into Excel

We can connect on Fb,G+,Twitter to spread more learning.

Scenario:- How we can fetch data from Excel in Robot framework to parameter our test cases.

Solution:- We need to implement ExcelLibrary keywords.

Inbuilt Keywords Used in our Example:-

  • Open Excel
  • Get Column Count
  • Read Cell Data by Coordinates
  • Get Row Count



Download Link for the Code

Code:-
*** Settings ***
Library           ExcelLibrary
Library           OperatingSystem
Library           robot.api.logger

*** Variables ***
${sFileName}      ${EXECDIR}\\Data\\TestSheet.xls    # DataSheet

*** Test Cases ***
TC_Fetch Data from Excell
    [Documentation]    Fetching the data from given Row and Column Name
    Open given Excel file    ${sFileName}
    #Passing SheetName,RowDetails and ColumnName, to fetch data
    ${sData}    Get data from Excel with given column    DataSheet    TC_02    UserName
    Log    ${sData}

*** Keywords ***
Open given Excel file
    [Arguments]    ${sFileName}
    #Check that the given Excel Exists
    ${inputfileStatus}    ${msg}    Run Keyword And Ignore Error    OperatingSystem.File Should Exist    ${sFileName}
    Run Keyword If    "${inputfileStatus}"=="PASS"    info    ${sFileName} Test data file exist    ELSE    Fail    Cannot locate the given Excel file.
    Open Excel    ${sFileName}

Get data from Excel with given column
    [Arguments]    ${sSheetName}    ${sTestCaseNo}    ${sColumnName}
    log    ${sColumnName}
    ${colCount}    Get Column Count    ${sSheetName}
    : FOR    ${y}    IN RANGE    0    ${colCount}
    \    ${header}    Read Cell Data By Coordinates    ${sSheetName}    ${y}    0
    \    #Check if this is the given header
    \    Run Keyword If    "${header}"=="${sColumnName}"    Set Test Variable    ${colNum}    ${y}
    log    ${colNum}
    #Get the total rows in the Sheet
    ${iTotalRows}    ExcelLibrary.Get Row Count    ${sSheetName}
    : FOR    ${iRowNo}    IN RANGE    1    ${iTotalRows}+1
    \    ${TC_Num}    Read Cell Data By Coordinates    ${sSheetName}    0    ${iRowNo}
    \    #Incase TestCase No is same , fetch the data from same row and given column No
    \    ${sSearchedData}    Run Keyword If    "${sTestCaseNo}"=="${TC_Num}"    ExcelLibrary.Read Cell Data By Coordinates    ${sSheetName}    ${colNum}
    \    ...    ${iRowNo}
    \    Run Keyword If    "${sTestCaseNo}"=="${TC_Num}"    Exit For Loop
    [Return]    ${sSearchedData}

Learn RobotFramework
Selenium Turorials

Robot Framework- Working with Excel Library(Part-1)

In part-1 we would discuss on Installing Excel Library to work with Robot Framework.

True Success is balance. For me, this means Health, Wealth, Happiness.
So I try and get 1% better each week in each of these areas.
Lets learn the robot framework integration with Robot Framework to enhance our skills.

Scenario: - How we can install Excel Library to work with excel files using Robot Framework.
Solution:-
Download:-
Dependencies:-

After extracting all the files we need to install all of them:-
Downloaded files of Excel library



Installation:-
Using command prompt browse to the location where files are located and use the command
Setup.py install

Installing Excel Library in Robot Framework

Repeat the above process for all the dependencies.

Verify:-
We can check that we have successfully installed all the individual components by typing python, followed by import “folder Name” in the command window after the installation.

For example:-

ExcelLibrary

Verify Excel library is installed

natsort

Verify Excel library dependencies are installed



Note: - We cannot use .xlsx extensions, due to limited support thus we need to stick to .xls extension(Excel 97-2003).

In our next post we are going to explore more on Excel integration with Robot Framework.

Configure UFT with Terminal Emulator (PCOMM)

Scenario: - How we can configure UFT to recognize Mainframe objects using Terminal Emulator?

Perquisites:- 
1.Terminal Emulator add in is already installed.
2.PComm(IBM personal Communication) is also installed, which is our Terminal Emulator in this example.

Note:- Do check the supported version of Terminal Emulator in UFT version.
Solution:- 

Step1:-Check the Terminal Emulator addin from the addin Manager.
Terminal Emulator Addin

Step2:-Create New GUI Test in UFT. (Else Terminal Emulator setting won’t be visible in Options of UFT).

Step3:- Tools –Options-GUI Test – Terminal Emulator.

Note:- Here we can configure other terminal emulators depending upon the requirements or the emulator already used by manual or dev teams in the organization.
Supported Emulators in UFT

Step4:-Configure the settings – Click on Validate.
Validate Terminal Emulator in UFT
Note: - Incase OK is not shown; this means we are facing some issues like PCOMM session is not opened.

Step5:-We can further configure the settings of PComm with UFT(like changing HLLAPI settings).
Configuration of Terminal Emulator in UFT

Step6:-Verify that UFT can recognize Terminal Emulator objects.
Object spy on Terminal Emulator and check that objects are showing the hierarchy of TeWindow-TeScreen-TeField (TE means Terminal Emulator in UFT terms)
object spy of mainframe in UFT

Note:-For more detailed reference, please read the help manual of UFT(Help-Unified Functional Testing help -Contents - Add-ins Guide for GUI Testing)

UFT addin Help guide


Difference between {{}} and ng-bind in AngularJS

To bind our data to the HTML page, Angular gives the ability to use {{}} known as double curly brackets or ng-bind.Both ways are performing the same functionality.


Eagle thinking image to learn more


{{}}

Example:-      Double Curly brackets in Angular JS

name is JS object or some variable we are referring to.
It makes your template very readable i.e Anyone going through a code such as {{ name }} can easily understand that "name"  is a variable bounded to the DOM.

Drawbacks of {{}}

Sometimes when we  load our application in the browser , we can notice flashing content for some milliseconds before {{ name }} is resolved and data is loaded.
flashing-content
Flashing content
This happens because the template is loaded before AngularJS had a chance to go in and compile the elements. To resolve this issue, you can use ng-cloak directive.

ng-bind is used inside an HTML DOM element:

Example:-
ng-bind

We are using the same expression which we used for double curly brackets.

The major difference between ng-bind and {{}} is that ng-bind creates a watcher for variable passed to it(i.e. name as in above example), while curly brackets({{}}) will (store the entire expression in memory i.e. }perform dirty-checking and refreshing the expression in every digest cycle even if it is not required.

ng-bind will only apply when the value passed is changing actually.

In the first approach(i.e. {{}}), AngularJS evaluates the expression then replaces it with some value which sometime be left with the flashing double curly brackets but ng-bind saves this time by informing AngularJS to put the contents of the expression within the element itself.
Note:-

  • {{}} sometimes cause performance issue if we have thousand of bindings in our page.In these scenario's, we should go with ng-bind.
  • For some modules, like translate module is implemented  or having binding which are not going to change , make the practice to use :: (double colon) before our binding. Example


XMLHttpRequest Cannot Load error in AngularJS

Error:- XMLhttpRequest Cannot load ? How to handle this error.


XMLHttpRequest cannot load Error
Browser Error



Solution:-
This is common error when you attempt to open load files directly in chrome.
Reason,
Chrome and other browsers have imposed security restrictions for "Cross Origin Requests", which means that you cannot load the files directly from your local hard-disk to browser hence you required to load the files on some server using some protocol. Eg: http.

There are different ways to resolve this issue:
Approach-1:- Search for the path of your Chrome executable and then, on your cmd, try :

  •  Type "where chrome" into command prompt which will give you "C:\PathTo\Chrome.exe"
  • Then type " C:\PathTo\Chrome.exe –allow-file-access-from-files "

Cmd Prompt chrome.exe

Note:-It is better to close all the browser instances before executing the above commands.

Approach-2:- If you have node setup then you can use http-server.
Execute npm install –g http-server and you will be able to access it using http-server C:\path\to\app

Approach-3:- Mount Apache server and deploy your code to run the app.

Note:-Some IDE's have default built in web servers like JetBrains, Eclipse

Do follow us for more learning and solutions Fb,G+,Twitter

Learn AngularJs

Conditional display of elements/data using Angular Js Directives.

Today we would learn frequently used Angular JS directives.

Problem:- How to achieve conditional construct in Angular js?


Love Nature

Solution:- We would achieve it by using built in directives of Angular JS.

1. ng-Switch:-We can control the conditional display of data.
It is similar to Switch-Case in JavaScript.
JavaScript syntax:-
Switch(expression) {
   Case  n:
     Code 
     Break;
   Case n1:
     Code 
     Break;
   Default:
     Default code

Angular JS syntax:-
Lets have corresponding code for above flow using directives:-
ng-switch on = expression 
   ng-switch-when = n
    Code
   ng-switch-when = n
    Code
   ng-switch-default
    Code

We also need to use ng-switch-when & ng-switch-default directives same as Case and Default in Javascript

Example:-


<div ng-app>
     EnterColor:
     <input type = "text" ng-model="Color"/>
    <div ng-switch on = "Color">
        <span ng-switch-when="red" style="color:{{Color}}"> I am very RED
       </span>
        <span ng-switch-when="green" style="color:{{Color}}"> I am very GREEN            
        </span>
        <span ng-switch-default  style="color:{{Color}}"> I am default            
        </span>
    </div>

</div>


Working Code

2. ng-If:- Used to remove/recreate the DOM element based on the expression.

Syntax:- ng-if="Conditional-Expression“


Note:-when an element is removed using ngIf its scope is destroyed and a new scope is created when the element is restored.

Example:-

<div ng-app>
     Check for Red Color:
     <input type = "checkbox" ng-model="Color"/>
    <div ng-if = "Color" style="width:50px;height:50px;background-color:red;">
    </div>
    <div ng-if = "!Color" style="width:50px;height:50px;background-color:green;">
    </div>

</div>


ng-if example code


Working Code

3. ng-Show/ng-Hide:-
Used to show/hide the DOM element based on the expression.

Note: - Unlike ng-if, it is not deleting and recreating the element from DOM but simply changing the display CSS of the element.

Syntax:-ng-Hide="expression“

How it works: - 
  • All it uses is Class =”ng-hide” and this class have CSS property of “display:none !important”.
  • !important so that this property have the maximum weight and cannot be overridden.
  • When expression is true then .ng-hide CSS is added causing element to be hidden and vice-verse.
Note: - For ng-Show we have ng-hide class added on "False" condition and removed when condition is "true" (it is reverse case as of  ng-Hide)

Example:-
<div ng-app>
     Show Me:
     <input type = "checkbox" ng-model="Color"/>
    <div ng-show = "Color" style="width:50px;height:50px;background-color:red;">
    </div>
    Hide Me:
    <input type = "checkbox" ng-model="hideColor"/>
    <div ng-hide = "hideColor" style="width:50px;height:50px;background-color:green;">
    </div>

</div>


ng-show Example


  • We can check the ng-hide class, using the inspect element.
At launch of code 

ng-hide class is applied

Check the "Show Me" checkbox

ng-hide class is removed