Archiv der Kategorie: Robot Framework

Use custom C#-libraries in Robot Framework

Read Install Robot Framework with IronPython on Windows and Use .NET libraries in Robot Framework first.
1. Save the Robot Framework file as ExampleTestCase.txt in C:\Program Files (x86)\robotframework-2.9\src\bin:

*** Settings ***
Library     FileManager
*** Test Cases ***
My Test
    Create File    fantastic.txt

2. Save the “middle-tier” Python script as FileManager.py in C:\Program Files (x86)\robotframework-2.9\src\bin:

import clr
clr.AddReferenceToFileAndPath("C:/Program Files (x86)/robotframework-2.9/src/bin/FileCreator.dll")
import FileCreator
class FileManager:
    def create_file(self, fileName):
        FileCreator().CreateFile(fileName)

Note, that in Python an object is created with brackets: FileCreator()
Note, that Robot Framework automatically matches the keyword “Create File” in ExampleTestCase.txt with “create_file” in FileCreator.py
3. Save your custom C# file as FileCreator.cs in C:\Program Files (x86)\robotframework-2.9\src\bin:

using System;
public class FileCreator
{
    public void CreateFile(String fileName)
    {
        System.IO.File.Create(fileName);
    }
}

4. Compile FileCreator.cs with csc in Command Prompt:

"C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe" /t:library /out:FileCreator.dll "C:\Program Files (x86)\robotframework-2.9\src\bin\FileCreator.cs"

5. Run the test in Command Prompt with:

ipybot ExampleTestCase.txt

Strategic link collection of Robot Framework

Do you need a good overview of all important websites regarding Robot Framework? Find my strategic link collection here:
Good introduction and overview on wikipedia: https://en.wikipedia.org/wiki/Robot_Framework
Quick start: https://github.com/robotframework/QuickStartGuide/blob/master/QuickStart.rst
 
My general considerations on robot Framework: https://it-kosmopolit.de/robot-framework-is-a-programming-language/
Install Robot Framework with IronPython on Windows: https://it-kosmopolit.de/install-robot-framework-with-ironpython-on-windows/
Use .NET libraries in Robot Framework: https://it-kosmopolit.de/use-net-libraries-in-robot-framework/
 
RIDE (Robot Framework IDE/development environment): https://github.com/robotframework/RIDE
User guide/tutorial with a lot of content: http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html
Ask you questions here: http://stackoverflow.com/questions/tagged/robotframework?sort=newest&pageSize=30
Installation instructions: https://github.com/robotframework/robotframework/blob/master/INSTALL.rst
The source code (repostiory) on gitHub: https://github.com/robotframework/robotframework

Use .NET libraries in Robot Framework

With Robot Framework on IronPython (Install Robot Framework with IronPython on Windows) you still implement the keywords in Python, but you can seamlessly access the wealth of .NET-libraries.
An example is worth a thousand words; so find an example how to use System.IO.File from .NET to create a file:
1.) IronPython (Python on .NET) file:

import System
class FileManager:
    def create_file(self, fileName):
        System.IO.File.Create(fileName)

… save as C:\Program Files (x86)\robotframework-2.9\src\bin\FileManager.py
2.) Robot Framework file:

*** Settings ***
Library    FileManager
*** Test Cases ***
My Test
    Create File    fantastic.txt

… save as C:\Program Files (x86)\robotframework-2.9\src\bin\ExampleTestCase.txt
The Keyword “Create File” in this .txt is automaically matched to the create_file method from the Python file. The underscore is automatically “translated” to a space.
3.) Execute in cmd:

cd C:\Program Files (x86)\robotframework-2.9\src\bin
ipybot ExampleTestCase.txt

Finished! Find fantactic.txt in C:\Program Files (x86)\robotframework-2.9\src\bin.
For more information on Robot Framework read: https://it-kosmopolit.de/strategic-link-collection-of-robot-framework/