How to create a custom Python code library for the Robot Framework - libraries

I already have Python source files for some custom tasks. Can I create a custom library of these tasks as keywords and use in the Robot Framework?

Yes, you can. This is all documented fairly extensively in the Robot Framework user guide, in the section titled Creating test libraries.
You have a couple of choices. You can use your module directly, which makes every method in the module available as a keyword. This is probably not what you want since the library probably wasn't designed to be used as a collection of keywords. Your second choice is to create a new library that imports your modules, and your new library provides keywords that call the functions in the other library.
As a simple example, let's say you have a module named MyLibrary.py with the following contents:
def join_two_strings(arg1, arg2):
return arg1 + " " + arg2
You can use this directly in a test suite as in the following example, assuming that MyLibrary.py is in the same folder as the suite, or is in a folder in your PYTHONPATH:
*** Settings ***
| Library | MyLibrary.py
*** Test Cases ***
| Example that calls a Python keyword
| | ${result}= | join two strings | hello | world
| | Should be equal | ${result} | hello world

Related

dynamically generate filesets and use them as parameters

I want to generate one jar per sub-package using an ant build script on a project looking like this :
basepackage
|__ subpackage1
| |_ Class11
| |_ Class12
|
|__ subackage2
|_ Class21
|_ Class22
...
So I have a target makejar that should build the jar from a given fileset and a target makeAll responsible for making all the filesets and calling the makejar target in these. The problem is that I don't understand how to build one fileset for each subpackage and how to transfer these filesets to the makejar target.
Is it the good way to do this or should I use an other tool ?
I'd prefer don't using user inputs and parse the directory structure automately.
I've seen a lot of answers talking about antcontrib but I don't know if it will solve my problems.

What is the best way to avoid duplicate symbols in project that will use my iOS framework and one of the dependencies?

Here is a quotation from the other post:
I'm working in a iOS project that includes a static library created by another company. The library include an old version of AFNeworking and I don't have any source files.
Now i need to use a more recent (and less bugged) version of afneworking, but i cannot include the same class twice in the project (of course) because all the "duplicate symbols"
My problem is that I'm preparing an iOS framework and I want to avoid this kind of situation in the future. I'm not talking about AFNetworking, but other quite popular iOS framework. In addition I applied some custom changes in the original framework code.
The one way to avoid "duplicate symbols" and "Class X is implemented in both Y and Z. One of the two will be used" that comes to my mind is to add some prefix to the original framework classes, but is this the right solution?
UPDATE 1:
I tried to apply John's solution but no joy. I have created a simplified project (here is the link to the repo) with two classes FrameworkClass which is present in framework target only, and SharedClass which is present in both framework and application targets, so maybe you can see if I'm doing something wrong. After application did launch I'm still getting:
objc[96426]: Class SharedClass is implemented in both .../TestFramework.framework/TestFramework and .../SymbolsVisibilityTest.app/SymbolsVisibilityTest. One of the two will be used. Which one is undefined
UPDATE 2:
Here is my output from nm based on the provided sample project's framework-output:
0000000000007e14 t -[FrameworkClass doFramework]
0000000000007e68 t -[SharedClass doShared]
U _NSLog
U _NSStringFromSelector
00000000000081f0 s _OBJC_CLASS_$_FrameworkClass
U _OBJC_CLASS_$_NSObject
0000000000008240 s _OBJC_CLASS_$_SharedClass
00000000000081c8 s _OBJC_METACLASS_$_FrameworkClass
U _OBJC_METACLASS_$_NSObject
0000000000008218 s _OBJC_METACLASS_$_SharedClass
0000000000007fb0 s _TestFrameworkVersionNumber
0000000000007f70 s _TestFrameworkVersionString
U ___CFConstantStringClassReference
U __objc_empty_cache
U _objc_release
U _objc_retainAutoreleasedReturnValue
U dyld_stub_binder`
UPDATE 3:
I did manage to "hide" SharedClass symbols by applying the solution by #bleater and my output from nm is now:
U _NSLog
U _NSStringFromSelector
00001114 S _OBJC_CLASS_$_FrameworkClass
U _OBJC_CLASS_$_NSObject
00001100 S _OBJC_METACLASS_$_FrameworkClass
U _OBJC_METACLASS_$_NSObject
U ___CFConstantStringClassReference
U __objc_empty_cache
U _objc_release
U _objc_retainAutoreleasedReturnValue
U dyld_stub_binder`
But I'm still getting double implementation warning in Xcode.
You should limit the visibility of symbols in any framework or library you are developing. Set the default visibility to hidden, and then explicitly mark all the functions in the public interface as visible.
This avoids all the problems you have described. You can then include any version of any public library (AFNetworking, SQLite, etc.), without fear of future conflict because anything linking to your framework or library won't be able to "see" those symbols.
To set the default visibility to hidden you can go into the project settings and set "Symbols Hidden by Default" to YES. It is set to NO unless you change it.
There are at least a couple of ways to mark the symbols from your public interface as "Visible". One is by using an exports file, another is to go through and explicitly mark certain functions as visible:
#define EXPORT __attribute__((visibility("default")))
EXPORT int MyFunction1();
The define is obviously just for convenience. You define EXPORT once and then just add EXPORT to all of your public symbols.
You can find official apple documentation on this here:
Runtime Environment Programming Guide
Update:
I took a look at your sample project, and it looks like I pointed you in the wrong direction. It appears that you can only truly hide C and C++ symbols. So if your were having this problem with a C lib (like sqlite), setting the default visibility to hidden would work. It looks like the nature of the Objective C runtime prevents you from truly making the symbols invisible. You CAN mark the visibility on these symbols, but with Objective-C it appears that is just a way to have the linker enforce what you should or shouldn't be able to use from the library (while still leaving them visible).
So if you redefine a Objective-C symbol in different compilation unit with the same name (by perhaps compiling in a new version of a popular open source library), then you will still have a conflict.
I think your only solution at this point is to do what you first suggested and prefix the symbols you are including into your framework with a unique identifier. It isn't a very elegant solution, but with the limits of the objective C runtime I believe it is probably the best solution available.
So the blog post by Kamil Burczyk was a good starting point, thanks for the hint MichaƂ Ciuba! It has covered most of the symbols, but it didn't cope with categories and class clusters. You can see what category methods are still exposed without any change by invoking nm with parameter list sth like:
nm MyLibrary | grep \( | grep -v "\[LIBRARYPREFIX" | grep -v \(MyLibrary | grep -v ") prefix_"
When it comes to categories we have 3 groups of categories, and they all require a specific, different approach:
Categories on classes that has been renamed by NamespacedDependencies.h
Categories on classes not renamed by NamespacedDependencies.h
Categories on class clusters like NSString, NSArray...
Ad 1.
Everything is ok - class name will be prefixed so category will exist on prefixed sumbol in object file
Ad 2.
This problem occours whenever inside of the dependency we have category on a class like NSObject. It would be exposed without any change in object file, thus would cause a conflict. My approach was to internally rename NSObject to PREFIX_NSObject, this ofcourse requires me also to create and add the PREFIX_NSObject class implementation to the project (empty implementation, just a subclass of original NSObject)
#import "PREFIX_NSObject.h"
#ifndef NSValueTransformer
#define NSValueTransformer __NS_SYMBOL(NSObject)
#endif
Ad 3.
We cannot apply Ad 2. approach here. Actual objects created by let's say PREFIX_NSArray class methods are still of type that wont derive from my presumable PREFIX_NSArray class, so this doesn't make sense as category methods defined on PREFIX_NSArray won't be visible on NSArray derived objects. I ended up by manually prefixing methods of those categories in source code.
It's kind of crazy workflow, but at least gives warranty that everything will be 'invisible' and won't cause a conflict.
It's always good idea to run nm to check if all category symbols are hidden:
nm MyLibrary | grep \( | grep -v "\[LIBRARYPREFIX" | grep -v \(MyLibrary | grep -v ") prefix_"

Can I use tags in SpecFlow to determine the right environment to use?

I have been working to get a SpecFlow framework in place for my Test environment, now I'd like
to extend the ability to use this for multiple environments. I was wondering if I could do this with BeforeFeature so that I can use Tags to say which environment I want to run, and which tests I'd like to be able to do on any/each environment. Part of the problem I have in
figuring this out is one of the Feature Scenarios I have to run contains an example table that will have different values for Test and Local.
Can I set up something like this in my Step Definition file?
[BeforeFeature("Test")]
public static void BeforeFeature_Test()
{
setupEnvironment("Test");
}
[BeforeFeature("Local")]
public static void BeforeFeature_Local()
{
setupEnvironment("Local");
}
If I have the tags #Test and #Local set up in my Feature files can I
run BeforeFeature like this to get the correct settings I might need
for my tests or environment?
With the Example Table I have something like:
Then I should be able to access <weblinks> pages
#Test
Examples:
| weblinks |
| http://test/url1 |
| http://test/url2|
#Local
Examples:
| weblinks |
| http://local/url1 |
| http://local/url2 |
Can the #Test and #Local tags work for both the Feature tests I want to run and the example tables?
I'm running this in NUnit, and I have my configuration set up with allowRowTests="false" as I noticed someone mentioned on the list before, but that may have been in an earlier SpecFlow, I am using 1.8 in Visual Studio 2010 with WebDriver and C#.
It looks like I can do this, it just took me a bit to understand how to link the two together. The Setup issue is separate, and still an issue, than the Examples issue, but I know how to work the table issue out.

How to describe gen_server visually?

Disclaimer: The author is a newbie in OTP having some basic knowledge of Erlang's syntax, processes and messages.
I am trying to grasp the notion of behaviours in Erlang, but a lot of questions spring in my head preventing me from understanding the whole principle of such a behaviour like gen_server.
Okay, the official documentation for gen_server shows a nice diagram of a server and three clients connected with Query and Reply arrows:
http://www.erlang.org/doc/design_principles/gen_server_concepts.html
But each time I try to understand the concept further, I get stuck.
There is a lot of concepts which I cannot build into one larger concept in my head:
behaviour implementation;
behaviour container;
behaviour interface;
callback module;
callback functions;
API functions.
I use the following resources:
Erlang/OTP in Action book;
Introduction to OTP behaviours presentation, http://www.slideshare.net/gamlidek/ceug-introduction-to-otp-behaviors-part-i-genserver;
'ErlyBank' at http://spawnlink.com/articles/an-introduction-to-gen_server-erlybank/index.html.
I am still in the state "we call one function in one module, this function calls the other function, that function creates a process... stuck"
Is there any way to describe the notion of gen_server in a diagram? How can an interaction flow between clients and a server be shown visually? (to help a not so smart newcomer to understand the concept visually)
For example like here: http://support.novell.com/techcenter/articles/img/dnd2003080506.gif
UPD: I have tried to draw a diagram of my own, but I still don't get the purpose of any connector in the diagram: http://postimage.org/image/qe215ric/full/
UPD2: This is something similar to what I would like to see: http://cryptoanarchy.org/wiki/Worker_patterns (The Model). However, it doesn't show the interaction between modules, functions and processes.
I don't have a precise drawing to explain it, but I have this chapter and the one after showing how to build gen_server starting with the abstraction principles behind it.
To help with the individual components:
behaviour implementation
The behaviour itself is a bit like what is shown in the chapter I linked before. It's a module with a bunch of functions doing all the generic stuff for you: receiving messages, defining functions and hidden protocols to communicate, etc. Advanced OTP stuff contains special kinds of messages used to do software upgrades and also special code for tracing options.
behaviour container
I'm not sure what this is supposed to be. Maybe just the module with the name of the behaviour?
behaviour interface
In the same module your behaviour implementation is, you have to define a behaviour_info/1 function. That function will let the Erlang compiler know that some callbacks are expected from any module that has -behaviour(SomeModuleName) in it. The SomeModuleName is equivalent to a SomeModuleName.erl (and .beam) file that contains the implementation and the behaviour_info function.
callback module
The module that will contain all the specific code, handling all the custom stuff.
callback functions
Everything that isn't generic gets to be delegated to the callback module in the form of YourModule:SomeCall(Args). These are provided by your module, the one that has the -behaviour(gen_server). line in it.
API functions
The callback module has two interfaces, if you want: the one for the gen_server behaviour (init/0, handle_call/3, handle_info/2, handle_cast/2, terminate/2, code_change/3), and the one for the user (start the server, send some information, ask for some information back).
I could try to describe it that way
---------------------------------------------------------------------
| some process | server process |
------------------------+--------------------------------------------
[client] | [callback] : [behaviour]
| :
callback:start >-------|---------------------:--> starting the process
| : V
| : |
| init() <-----:-----------`
| | :
| `-----------:------> initial state
{ok, Pid} <----------|---------------------:----------,/
| :
callback:store >------|---------------------:--> handles message
(calls the process) | (formats msg) : V
| : |
| handle_call() <--:-----------`
| | :
| `----------:--> updates state, sends reply
| : V
| : |
gets result <--------|---------------------:--------`
| :
All the generic parts are on the right of the server process, within the behaviour, and all the specific parts are on the left (callback). The client uses the callback module's API/interface to contact the server process and have effects on it.
You have to see the behaviour as some kind of very generic code segment that sometimes gives up its execution flow (for more precise parts, like receiving and sending messages) to the specific code (how to react to these messages).
Hopefully this helps.

How to execute a exe file using fitnesse

I want to call an exe file in my fitnesse test case.
Help me in calling an exe file in my test cases
With fitnesse, you'll need to write a fixture to run the EXE (and/or find a fitnesse plugin to do it for you). The easiest way is to write a simple fixture and just run
Runtime.getRuntime().exec(<cmd>);
While #Steven Mastandrea's answer is right but it does require you to write you a Java class extending one of the provided fixture's from Fitnesse and compile and put the class files in Fitnesse classpath and then use it.
There is a much simpler way of doing it if you use Generic Fixture like this:
!| Generic Fixture |
| exec | mycommand.exe | | expected outpout |
Disclaimer: Generic Fixture was written and distributed by me as open source 2 years ago on sourceforge.
With fitSharp on Windows, you can write this:
|with|type|System.Diagnostics.Process|
|with|start|C:\dev\myFileImporter.exe||-f c:\dev\data\file.txt|
|wait for exit|
I would suggest taking the CommandLineFixture as a baseline, and expand it from there. The CommandLineFixture has a lot of functionality and is well commented and easily extended should you wish to do so.
This fixture incorporates Steven's code, but has a lot more functionality than simply exec, including being able to asynchronously spawn processes, search output for expected results, etc.
Post a command if you feel some examples of how to use it would be helpful!

Resources