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:






 

Thursday, August 20, 2015

Python Matrix Multiplication

def MatrixProduct(a, b):
    d=[]
    i=0
    while i<len(a):
        j=0
        e=[]
        while j<len(b[0]):
            k=0
            r=0
            while k<len(a[0]):
                r+=a[i][k]*b[k][j]
                k+=1
            j+=1
            e.append(r)
        d.append(e)
        i+=1
    return d