Showing posts with label Library. Show all posts
Showing posts with label Library. Show all posts

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, June 24, 2015

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, 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}