Showing posts with label robotframework. Show all posts
Showing posts with label robotframework. Show all posts

Tuesday, April 17, 2018

Generate Robot framerwork keyword documentation from custom library?

Let say, I've created my own python library for robot framework and now I want to generate documentation from the python class file.

How to do it?

Step 1:
In python, add your documentation

def delete_excel_row(self, varFileName, varSheetName, varCellName):
"""
Delete a row in the excel file.
Arguments:
| FileName | Excel file with full path |
| SheetName | Sheetname in the excel file |
| CellValue | Row to be deleted in the sheet |

Example:
Delete row
| Delete Excel Row | C:\\Python27\\ExcelRobotTest\\ExcelRobotTest.xlsx | Sheet1 | A1 |
"""
self.varFileName = varFileName
self.varSheetName = varSheetName
self.varCellName = varCellName
varExcel = win32com.client.DispatchEx('Excel.Application')
varWB = varExcel.Workbooks.Open(self.varFileName)
varSheet = varWB.Sheets(self.varSheetName)
varSheet.Range(self.varCellName).EntireRow.Delete(Shift=-4162)
varWB.Save()
varWB.Close()
varExcel.Quit()

Step 2:
Now generate documentation using command

 python -m robot.libdoc filename.py  filename.html

Saturday, May 21, 2016

Robot Framework with Sikuli 1.1.0

Integration of Robot Framework with Sikuli 1.1.0

Pre-requsities:
1. Jython, Robot Framework (Jybot) should be installed and environment variables should be configured properly.
// Installation of Jython and Jybot are not covered here.

Sikuli installation steps:
1. Download the sikuli1.1.0 jar file from the website https://launchpad.net/sikuli/+download
2. Open the command prompt and install the sikuli as below

3. Choose the option 2

 4. Installation will be progress from internet and will be completed automatically


5. Once installation is completed, "sikulixapi.jar" file will be available in the corresponding folder.
6. To use the methods of sikuli in our jython script,  we have to add it in the jythonpath


7. Now open the command prompt and check its working properly.


8. Develop a sample jython script


"""Created on May 21, 2016
@author: vallikkv @ Vallinayagam.K
'''""

import org.sikuli.basics.SikuliXforJython
from sikuli import *


class Sikuli11Lib(object):
    ROBOT_CONTINUE_ON_FAILURE = True
    #Configure the path of image files
    myImagePath = "E:\\Sikuli11\\Images"
    addImagePath(myImagePath)


    def SampleMethod(self):
        click("1.PNG")
        click("2.PNG")

if __name__ == '__main__':
    a = Sikuli11Lib()
    a.SampleMethod()

9. Sample execution of  the script without integration of RF




10. To integrate with RF (Eg: Same script can be used to integrate with RF). Make sure the script file path is accessible by the RF+ Jybot, if not add it in the environment variable path

11, RF script by using the above sikuli script

*** Settings ***
Documentation  Testing with Sikuli 1.1.0 version

Library  Sample.Sikuli11Lib

*** Test Cases ***
Checking the version
    SampleMethod


12. Execute it using jybot



Note: This is a sample script, you can develop wrapper for sikuli methods and make it as common library which can be reused in robot framework like other libraries eg: Selenium2library


Reference: https://answers.launchpad.net/sikuli/+question/136170

Saturday, September 12, 2015

Robot framework + SSH Library + Monitor a log file until a string matches using Jython

SSH library installation.

1. Download SSH library and install using "jython setup.py install" command
2. Download Trilead-ssh2-1.0.0-build217.jar file and put it in a folder
3. Add that folder in the "CLASSPATH"

Eg: E:\Robot\trilead-ssh2-1.0.0-build217.jar;C:\Python27\Lib\site-packages

4. Similarly add "robot" folder in the JYTHONPATH

Eg: C:\Python27\Lib\site-packages\robot;C:\Python27\Lib\site-packages

5. Execute command jython -c "import SSHLibrary" for verification

Sample SSH Robot script

*** Settings ***
Documentation  Open Notepad using Sikuli and Robotframework

Library    SSHLibrary

*** Variables ***
${HOST}                192.168.10.135
${USERNAME}            test
${PASSWORD}            test

*** Test Cases ***
Open Connection And Log In
    Open Connection    ${HOST}
    Login    ${USERNAME}    ${PASSWORD}

Execute and expect a new session
    ${OUT}=    Execute Command    timeout 5 tail -f -n 1 /var/log/messages | awk '/vallikkv/;/vallikkv/ { exit }'
    BuiltIn.Log to console    ${OUT}
    BuiltIn.Should Not Be Equal    ${OUT}    \  
    

Closing the connections
    BuiltIn.Log to console    Test
    Close All Connections


ButiltIn.Log to console -> This is how, use the inbuilt keywords of robot(python) in jython scripts

Shell command to monitor log file until specific "word" matches, if not exit the script in 5 seconds


timeout 5 tail -f -n 1 /var/log/messages | awk '/vallikkv/;/vallikkv/ { exit }'  







Wednesday, September 9, 2015

Jython remote library

Remote library for Jython/Jybot with sikuli

Machine 1:
1. Installed jython 2.5.2, Jybot, Sikuli
2. Install robot remote server using command "jython setup.py install"
       Note: Download robotremoteserver.tgz file and install
3. Own library for sikuli


Machine 2:
1.Robot framework, jython 2.5.2, jybot
2. Test scripts (Eg: Notepad.robot)

STEPS:

1. Run the sikuli library using command "jython <sikulilibrary>"

It will start the Remote library for the interface configured in the library file and exposed keywords

2.  Now run the robot script from any network machines using command

"jybot <Notepad.robot>"


The testresults will be available in the local machine (i.e Machine2)

Tuesday, September 8, 2015

Robot framework: Remote library

How to use simple remote library in robot framework? (Only for Python)

Pre-requisities:
1. Robot framework should be installed
2. Pybot command should work fine.

STEP 1:
Install robot remote server using command.

pip install robotremoteserver

Refer: https://github.com/robotframework/PythonRemoteServer

STEP 2:
Create a file as mentioned in the above link


from robotremoteserver import RobotRemoteServer
from mylibrary import MyLibrary

RobotRemoteServer(MyLibrary())

Remotelib.py:

if __name__ == '__main__':
    import sys
    from robotremoteserver import RobotRemoteServer
    from Example import test

    RobotRemoteServer(test(), host='192.168.10.104', port=8270, allow_stop=False)

192.168.10.104 - Remote machine ip where remote library exists


Here i have created a sample Example library with class "test"

Example.py

#!/usr/bin/env python

class test(object):
    """ Sample doc"""

    def add(self,x,y):
        self.x = int(x)
        self.y = int(y)
        return str(self.x + self.y)

STEP 3:
Start the Remoteserver  - command python Remotelib.py



STEP 4:
Sample Robot script


*Settings*
Documentation               This is just a tutorial for Remote library

Library    Remote    http://192.168.10.104:8270

*** Test Cases ***
Check Remote library first keyword
    [Documentation]         Check ADD keyword of remote library
    ${ANS}=    Add    1    6
    Should Be Equal    ${ANS}    7



STEP 5:
Test execution:






 

Wednesday, June 24, 2015

Sikuli Robotframework general libary + Robot testcase + Open a notepad

General sikuli robotframework library:

'''
Created on Jun 24, 2015

@author: vallikkv @ Vallinayagam.K
'''

from sikuli import *
from Screenshot import *


class SikuliLib(object):
    ROBOT_CONTINUE_ON_FAILURE = True
    myImagePath = "C:\\sikulix\\Images"
    addImagePath(myImagePath)

    def __init__(self):
        self.screen = Screenshot()

    def click_window(self, inputfile):
        self.inputfile = inputfile
        if exists(self.inputfile):
            find(self.inputfile)
            click(self.inputfile)
        else:
            self.screen.take_screenshot()
            raise AssertionError("Required screen to click is not available")

    def Type_and_enter(self, inputtotype, inputfile1):
        self.inputtotype = inputtotype
        self.inputfile1 = inputfile1
        if exists(self.inputfile1):
            find(self.inputfile1)
            type(self.inputtotype + Key.ENTER)
        else:
            self.screen.take_screenshot()
            raise AssertionError("Typing To inputfile is failed")

    def expected_screen(self, expectedfile):
        self.expectedfile = expectedfile
        if not exists(self.expectedfile):
            self.screen.take_screenshot()
            raise AssertionError("Error, Failed")
        else:
            pass



Robot Testcase using above library:

*** Settings ***
Documentation  Open Notepad using Sikuli and Robotframework

Library  Sikulilibrary.SikuliLib

*** Test Cases ***
Open a Notepad
    click window    windowicon.PNG
    click window    search.png
    Type and enter  notepad.exe    typerun.png
    expected screen  notepad.png

Failed Log:

By Giving wrong File name in the "Type and enter" keyword




Passed Log:







Sikuli + Robotframework + jybot - Execution with screenshot

Sample code:

Created on Jun 24, 2015

@author: vallikkv @ Vallinayagam.K
'''

from robot.api import *
import org.sikuli.basics.SikuliXforJython
from sikuli import *
from Screenshot import *

##Screenshot.py is copied and available in the location "C:\Python27\Lib\site-packages", or declare ##the path where screenshot.py is located.


class Notepad(object):
    ROBOT_CONTINUE_ON_FAILURE = True
    myImagePath = "C:\\sikuli\\Tests.sikuli\Notepad"
    addImagePath(myImagePath)

    def __init__(self):
        self.screen = Screenshot()

    def click_window(self):
        try:
            find("WindowsIcon.PNG")
            click("WindowsIcon.PNG")
        except Exception:
            print "Error in the click window"

    def Type_in_run_and_enter(self):
        try:
            wait("Runwindow.PNG", 5)
            type("notepad.exed"+ Key.ENTER)
        except Exception:
            print "Problem in second step"

    def verify_result(self):
        if not exists("Notepad.PNG"):
            self.screen.take_screenshot()
            raise AssertionError("Error, Failed")
        else:
            pass



Command used to execuet - jython C:\Python27\Lib\site-packages\robot\run.py C:\sikuli\Tests.sikuli\Notepad\Robot.txt


It will embeed screenshots when failed, I've used only for the verify_result method, It should be included for all the methods.

Tuesday, June 23, 2015

How to create Robot Framework Test library for Sikuli jython scripts: (Content Not yet Finalized: Warning)

1. Create Jython script, Filename -  Sample1.py

import org.sikuli.basics.SikuliXforJython
from sikuli import *


class Sample(object):

    def testing(self):
        print "testing"
        try:
            click("1.PNG")
            wait("1.PNG", FOREVER)
        except:
            print "Click windows icon is not occured - Failed "
        
       
#if __name__=='__main__':
#    test = Sample()
#    test.testing()
    
2.  Create Robot Library for the created script

*** Settings ***
Library    Sample1.Sample              

*** Test Cases ***
Sample testcase
    testing


3. Sikuliwrapper details: TO DO

4. Execute it as below





Tuesday, June 16, 2015

Robotframework + Selenium2Library + Jenkins

Robotframework + Selenium2Library + Jenkins

How to run robotframework selenium testcases using jenkins - UI Based.

1. Download Jenkins.war file and start via cmd.



2.  Once its started, it can be accessible via 'http://localhost:8080'

3.  Install the  Robotframework plugin using Manage Jenkin -> Plugin option.

4. Once it's installed, it will be displayed in the "Installed" tab



5. Now create a job and Configure as below. (I explained here with having build management as None).




6. Once its created, You can start the job and see the robot output files in


Tuesday, April 7, 2015

Robotframework - Parallel test execution of two different testsuites on two different machines.

Robotframework - Parallel test execution of two different testsuites on two different machines.





Step 1:
Install the selenium server "http://docs.seleniumhq.org/download/" from the location.

Filename -  selenium-server-standalone-3.8.1.jar (Version will be different in your case)

Step 2:
From Machine1 command prompt, Go to the jar application location and launch it as 'hub' by giving commmand

java -jar selenium-server-standalone-3.8.1.jar -role hub

Step 3:
From Machine2 command prompt, Go to the jar application location and launch it as 'node' by giving command

java -jar selenium-server-standalone-3.8.1.jar -role node -hub http://<Machine 1 IP address>:4444/grid/register -port 5566

Test cases:

Open Browser    ${URL}    ${BROWSER}    None    http://<HUB Machine IP ADDRESS>:5566/wd/hub

Sunday, April 5, 2015

Robotframework: AutoIt Library installation steps

Robot Framework: AutoIT library installation steps

Step 1: Install python 2.7 (64 or 32 bit, based on the machine) and you can verify it by typing python in command prompt. you can see the version in the top of the console.
           

Step 2: Install robotframework using pip command: "pip install robotframework" and you can verify it by command "pybot --version"



Step 3: Install pywinauto (32 or 64 bit, based on the python version which you installed) and you can verify by importing the pywin module in the python or Install wxpython for corresponding python version.



Step 4: Install robotframework AutoIT library by downloading the package and install the setup.py file using the command "python setup.py install"

Note: To install AutoIT library, launch the command prompt in administrator mode.

Once the installation is successful, AutoIT library folder will be created in the location

"C:\RobotFramework\Extensions"

Note: Its better to install 32 bit windows of Python, pywin or Wxpython to avoid problems.


           

Tuesday, March 31, 2015

Robotframework Jmeter testcase example with assertion

*** Settings ***
Library           JMeterLib.py
Library           Collections

*** Test Cases ***
tc1_justRunJMeter
    run jmeter    C:/Users/USER/Desktop/apache-jmeter-2.12/apache-jmeter-2.12/bin/jmeter.bat    C:/Users/USER/Desktop/apache-jmeter-2.12/apache-jmeter-2.12/bin/vallikkv/Soap.jmx    E:/Robot/jmeter/log/output_tc1.jtl

tc2_analyseAndConvertExistingJtlLog
    ${result}    analyse Jtl convert    E:/Robot/jmeter/log/output_tc1.jtl
    log    ${result}
    : FOR    ${ELEMENT}    IN    @{result}
    \    log dictionary    ${ELEMENT}
    \    ${check}    Get From Dictionary    ${ELEMENT}    samplesSuccessRateInclAssert
    \    log to console    ${check}
    Should Be Equal As Integers    ${check}    100

tc3_runJMeterAndAnalyseAndConvertLog
    ${result}    run jmeter analyse jtl convert    C:/Users/USER/Desktop/apache-jmeter-2.12/apache-jmeter-2.12/bin/jmeter.bat    C:/Users/USER/Desktop/apache-jmeter-2.12/apache-jmeter-2.12/bin/vallikkv/Soap.jmx    E:/Robot/jmeter/log/output_tc3.jtl
    log    ${result}
    :FOR    ${ELEMENT}    IN    @{result}
    \    log dictionary    ${ELEMENT}

Monday, March 23, 2015

Robot Framework

Installation







Read data from Excel


Manual Installation

To install robotframework-excellibrary manually, install all dependency libraries before installing robotframework-excellibrary.
1) Install Robot Framework installed.
2) Download source distributions (*.tar.gz / *.zip) for the library and its dependencies.
robotframework-excellibrary and dependencies:
Note: Internet Connection is required

command
python setup.py install


***Settings***
Library    ExcelLibrary

***Variables***
${Excel_File_Path}    C:\Test.xls

***Test Case***
Read Data from Excel and fill in text box Open Excel ${Excel_File_Path} ${username}= Read Cell Data By Name Sheet1 B1 ${password}= Read Cell Data By Name Sheet1 B2 Input Text id=Username ${username} Input Text id=Password ${password}

Tuesday, March 3, 2015

Robot framework - Selenium2Library test execution


*** Settings ***
Documentation  Test suite-2 Verify the connect webpage is logged in with valid logon credentials
Library  Selenium2Library

*** Variables ***
${HOMEPAGE}     http://192.168.10.132:8080/connectserver
${BROWSER}  FireFox
${DELAY}    1
${USERNAME}    admin
${PASSWORD}    connect


*** Test Cases ***
connect login
    open connect webpage
    enter login credentials
    click login

connect logout
    logout connect webgui


*** Keywords ***
Open connect webpage
    open browser    ${HOMEPAGE}    ${BROWSER}
    Maximize Browser Window
    Set Selenium Speed    ${DELAY}

enter login credentials
    Input Text    id=username    ${USERNAME}
    Input Text    id=password    ${PASSWORD}

click login
    Click Button    id=loginAction_login_submit

logout connect webgui
    Get Location
    Select Frame    xpath=//div[1][@class='ui-layout-north ui-layout-pane ui-layout-pane-north open']
    Click Button    xpath=//div[1]/table/tbody/tr/td[3]/table/tbody/tr[2]/td/a[@class='siLink1']