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





Monday, June 22, 2015

How to install sikuli for Jython?

How to install sikuli for Jython?

Before starting with sikuli installation, Install Jython 2.5.2 (In my windows 8.1, it not works with jython 2.5.3, So I used the earlier one). Refer my earlier post for jython installation

1. Download sikuli-setup.jar file and save it in a location: Eg: "C:\sikulix"

2. Now open the command prompt and go to the "C:\sikulix" location and execute command
      java -jar sikuli-setup.jar

3. It will generate a file named "runSetup.cmd" and available in the same location.

4. Now execute the command, it opens a installer window.

5. Choose the options for jython (2,4)

6. It will automatically download the required files from internet.

7. Once installation is completed, declare the following values in the system enviroment table




8. Now close the command prompt and open a new one

9. Open jython and import sikuli to verify everything works fine


Thursday, June 18, 2015

How to install jython in windows?

How to install jython in windows?

1. Download jython installer jar file from http://www.jython.org/downloads.html

          jython-installer-2.5.3.jar

2. Open command prompt and go to that downloaded location and execute

         java -jar jython-installer-2.5.3.jar

3. It will open a installer window, follow the instructions and install it.

4. Now open a  new command prompt and type "jython" and check it opens the interpreter window.


Note: To set path in environment variable, use path where the jython folder is available, in my case it's "C:\jython2.5.3"





Wednesday, June 17, 2015

Sikuli + Eclipse + java

How to execute sikuli script using Eclipse + java?

1. Download sikuli-setup.jar

2. Execute in cmd prompt "java -jar sikuli-setup.jar" file. It will generate runSetup.cmd in the same folder.

3. Execute it via cmd prompt.

4. It will lauch a window, choose the options "Download for IDE, eclipse" and for "windows, mac"

5. It will download sikuli-java.jar file.

6. Now open the eclipse, create a package -> create a project -> Add TestNG library and Sikuli-java.jar.

7. Save and reboot the pc (It requires a logout and login to activate)

8. Lauch eclipse and create a TestNG Class and write your code.(Note:- TestNG installation for eclipse is not covered here)

Sample code:

package sample_sikuli;

import org.sikuli.script.FindFailed;
import org.sikuli.script.Screen;
import org.testng.annotations.Test;

public class NewTest {
Screen s = new Screen();
  @Test
  public void Sample() {
 try {
s.click("C:/Users/USER/Desktop/1.png");
s.click("C:/Users/USER/Desktop/2.png");
s.click("C:/Users/USER/Desktop/3.png");
s.type("notepad.exe");
} catch (FindFailed e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
  }
}




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