IronPython, RobotFramework and SeleniumLibrary

766 views
Skip to first unread message

WilliamK

unread,
Nov 15, 2010, 11:01:02 AM11/15/10
to robotframework-users
Hi all,

I have managed to get an implementation of IronPython and the
RobotFramework going without any previous installation of Python,
following the ongoing discussion “How to use IronPython with RF?” on
the users’ group. Big thanks to all the people who provided help as
that solved most of my issues.
It wasn’t straightforward and involved copying some missing modules
from a Python installation on another machine to the IronPython
repository or getting some other modules from the Web.
I plan to go through the whole exercise again soon, on a clean machine
and using the latest steps documented by Pekka at
http://code.google.com/p/robotframework/issues/detail?id=154#c16.
I will then give some feedback.

On my current implementation, so far, I’ve been able to run
RobotFramework tests against a simple C# Dll, having created a Python
module that calls that Dll’s methods via the custom keywords.

-------------------------------------
[Side note]
For those attempting something similar, it appears to work fine with
IronPython 2.6 but I ran into what looks like a bug in IronPython 2.7:
clr.AddReferenceToFileAndPath(path_to_my_dll_file) seems broken in
that it never seems to find the C# library I reference and indicates
the files does not exist.
IronPython 2.6 has no such issues and loads the same file just fine. I
found some reports by other users having similar issues but no
solution yet.
So for now, I’ll be sticking with IP 2.6.
-------------------------------------

Anyway, I now want to add the Selenium library to the mix so I
installed it: IronPython 2.6, RobotFramework 2.5.4 and SeleniumLibrary
2.4
If I try to run the Selenium library demo or adapt it to run my own
tests, I get an error:

C:\Robot\Tests>ipy rundemo.py DbTests
Traceback (most recent call last):
File "rundemo.py", line 32, in <module>
ImportError: No module named subprocess

If I get the subprocess.py module from an Python installation:

C:\Robot\Tests>ipy rundemo.py DbTests
Traceback (most recent call last):
File "rundemo.py", line 86, in <module>
File "rundemo.py", line 47, in run_tests
File "rundemo.py", line 61, in start_selenium_server
File "C:\Program Files\IronPython 2.6 for .NET 4.0\lib\site-packages
\SeleniumLibrary\__init__.py", line 71, in start_selenium_server
File "C:\Program Files\IronPython 2.6 for .NET 4.0\Lib
\subprocess.py", line 616, in __init__
File "C:\Program Files\IronPython 2.6 for .NET 4.0\Lib
\subprocess.py", line 1027, in _execute_child
AttributeError: 'module' object has no attribute 'pipe'

Although I understand what the above error message means, I can't
quite figure out what would be required in IronPython to get this
working.

I also tried running the demo using pybot (updated to point to
IronPython files) and the suggested workflow:
ipy rundemo.py selenium start
ipy rundemo.py demoapp start
pybot --variable BROWSER:Firefox --outputdir firefox login_tests
pybot --variable BROWSER:IE --outputdir ie login_tests
ipy rundemo.py demoapp stop
ipy rundemo.py selenium stop

This resulted in the same error about the pipe attribute. The
difference is that it went further, proceeding to 'ipy rundemo.py
demoapp start' and running all the login tests but they all fail with
a message saying "Could not connect to Selenium Server in 40 seconds.
Please make sure Selenium Server is running."

Any suggestions much appreciated. Thanks in advance.

William

Janne Härkönen

unread,
Nov 15, 2010, 3:13:47 PM11/15/10
to willia...@firsthelpline.com, robotframework-users
On Mon, Nov 15, 2010 at 6:01 PM, WilliamK
<willia...@firsthelpline.com> wrote:
> Hi all,
>
> I have managed to get an implementation of IronPython and the
> RobotFramework going without any previous installation of Python,
> following the ongoing discussion “How to use IronPython with RF?” on
> the users’ group. Big thanks to all the people who provided help as
> that solved most of my issues.
> It wasn’t straightforward and involved copying some missing modules
> from a Python installation on another machine to the IronPython
> repository or getting some other modules from the Web.
> I plan to go through the whole exercise again soon, on a clean machine
> and using the latest steps documented by Pekka at
> http://code.google.com/p/robotframework/issues/detail?id=154#c16.
> I will then give some feedback.

This sounds awesome. If you have time to give detailed feedback, we
could create a Wiki page describing this procedure.

> On my current implementation, so far, I’ve been able to run
> RobotFramework tests against a simple C# Dll, having created a Python
> module that calls that Dll’s methods via the custom keywords.

This is also really cool, and a generic example would be great ;)

It might just be that the subprocess module is not compatible with
IronPython, in which case the rundemo.py should be rewritten for IPY.
If the only thing not working is the PIPE attribute (which is just
used for output redirection), this would be relatively easy task.

>
> I also tried running the demo using pybot (updated to point to
> IronPython files) and the suggested workflow:
>    ipy rundemo.py selenium start
>    ipy rundemo.py demoapp start
>    pybot --variable BROWSER:Firefox --outputdir firefox login_tests
>    pybot --variable BROWSER:IE --outputdir ie login_tests
>    ipy rundemo.py demoapp stop
>    ipy rundemo.py selenium stop

The tasks that fail (selenium start and demoapp start) just start
those applications using Python's subprocess module but you may just
open two separate command prompts for starting the applications.

The command to start Selenium Server would be:
java -jar <Python installation
dir>\site-packages\SeleniumLibrary\lib\selenium-server.jar

The command to start the demo application is:
python <demo-dir>\demoapp\server.py start

Once you have these two commands running, executing the test with your
pybot script (from a third prompt) as you already tried should work.

hth,
__j

Pekka Klärck

unread,
Nov 15, 2010, 6:44:14 PM11/15/10
to willia...@firsthelpline.com, robotframework-users
Hi William,

First of all thanks for the report on using Robot on IronPython. As
Janne already commented, we are highly interested to hear experiences
about it. Although we cannot put too much resources on the IronPython
support, we try to fix at least the simple problems. On Monday I did,
for example, notice using Unicode didn't work due to an IronPython bug
and already implemented an initial workaround for it (not yet
committed).

2010/11/15 WilliamK <willia...@firsthelpline.com>:


>
> I also tried running the demo using pybot (updated to point to
> IronPython files) and the suggested workflow:
>    ipy rundemo.py selenium start
>    ipy rundemo.py demoapp start
>    pybot --variable BROWSER:Firefox --outputdir firefox login_tests
>    pybot --variable BROWSER:IE --outputdir ie login_tests
>    ipy rundemo.py demoapp stop
>    ipy rundemo.py selenium stop
>
> This resulted in the same error about the pipe attribute. The
> difference is that it went further, proceeding to 'ipy rundemo.py
> demoapp start' and running all the login tests but they all fail with
> a message saying "Could not connect to Selenium Server in 40 seconds.
> Please make sure Selenium Server is running."

Above you try to start up the Selenium Server and the demo application
with IronPython but then run tests using normal Python. You should do
it just the other way round, starting first the Selenium Server and
the demo application with Python:
python rundemo.py selenium start
python rundemo.py demoapp start

Then you should be able to run the tests with:
ipy path/to/robot/runner.py login_tests

Alternatively, you can try to search is it possible to install a fully
working subprocess module for IronPython.

Cheers,
.peke


--
Agile Tester/Developer/Consultant :: http://eliga.fi
Lead Developer of Robot Framework :: http://robotframework.org

WilliamK

unread,
Nov 17, 2010, 6:38:08 AM11/17/10
to robotframework-users
Hi all,

Thanks Anne and Pekka for your replies.

Remember I am interested in testing an implementation that does not
include Python, only IronPython.
So I cannot run any commands starting with python.

That said, I've got two separate environments for play:
one with Python, IronPython, RF and SeleniumLibrary

On Nov 15, 11:44 pm, Pekka Klärck <p...@iki.fi> wrote:
> Hi William,
>
> First of all thanks for the report on using Robot on IronPython. As
> Janne already commented, we are highly interested to hear experiences
> about it. Although we cannot put too much resources on the IronPython
> support, we try to fix at least the simple problems. On Monday I did,
> for example, notice using Unicode didn't work due to an IronPython bug
> and already implemented an initial workaround for it (not yet
> committed).
>
> 2010/11/15 WilliamK <william.ko...@firsthelpline.com>:

WilliamK

unread,
Nov 17, 2010, 8:54:20 AM11/17/10
to robotframework-users
Hi all,

Sorry about the previous incomplete post. Wrong move and before I knew
it, the message was sent out!
Starting again:

===========================================================================

Thanks Janne (not Anne, apologies for that) and Pekka for your
replies.

Remember I am interested in testing an implementation that does not
include Python, only IronPython.
So I am not supposed to run any commands starting with python.

That said, I've got two separate environments for play:
- env 1: Python, IronPython, RF and SeleniumLibrary
- env2: IronPython, RF and SeleniumLibrary

In env1, I tried Pekka's suggestion below:

> Above you try to start up the Selenium Server and the demo application
> with IronPython but then run tests using normal Python. You should do
> it just the other way round, starting first the Selenium Server and
> the demo application with Python:
>     python rundemo.py selenium start
>     python rundemo.py demoapp start
>
> Then you should be able to run the tests with:
>     ipy path/to/robot/runner.py login_tests

The demoapp login_tests run but all fail.
The following is reported as the cause:

-----------------
Suite setup failed:
TypeError: create_connection() takes at most 2 arguments (3 given)

Also suite teardown failed:
TypeError: create_connection() takes at most 2 arguments (3 given)
-----------------
The symptom is that the browser never starts.

With the command 'python path/to/robot/runner.py login_tests', there
is no such problem.


> Alternatively, you can try to search is it possible to install a fully
> working subprocess module for IronPython.
>

I have. There is this article: http://www.ironpython.info/index.php/Launching_Sub-Processes.
Someone subsequently created a partial .NET-specific version of
subprocess.py (http://www.ironpython.info/index.php/
The_subprocess_module).
Limitations:
* Popen.communicate doesn't work
* Can't redirect stdin except for PIPE
* Can't redirect stderr to stdout (i.e. using
stderr=subprocess.STDOUT)
* Can't redirect to a file descriptor
* univeral_newlines is not supported
* Command strings are flaky (lists work much better). Use
shell=True if using command strings.
I updated its code to avoid some exceptions.

I'm trying to use that subprocess.py in env2 (Pyhton-free).
I created an updated version of rundemo.py that references IronPython
wherever it's supposed to reference Python.
Even other entities like pybot, runner.py and the PYHTONPATH env var
were updated accordingly.

If I run 'ipy rundemo.py login_tests', I get error:

Traceback (most recent call last):
File "rundemo.py", line 86, in <module>
File "rundemo.py", line 48, in run_tests
File "rundemo.py", line 54, in start_demo_application
File "C:\Program Files\IronPython 2.6 for .NET 4.0\Lib\tempfile.py",
line 49,
in _set_cloexec
AttributeError: 'module' object has no attribute 'fcntl'
I'm stuck there. Will have to check this out.

Still in env2, moving on, I can try running the main steps separately
instead of the top rundemo.py.
Starting the Selenium server can be done independently calling command
'java -jar ...\...\selenium-server.jar' as mentioned by Janne.
But the issue is then starting the demo. I would like to do that with
IronPython.
If I try 'ipy server.py start', I get the following:

Demo application starting on port 7272
Traceback (most recent call last):
File "server.py", line 81, in <module>
File "server.py", line 65, in start_server
File "C:\Program Files\IronPython 2.7\Lib\SocketServer.py", line
408, in __init__
File "C:\Program Files\IronPython 2.7\Lib\BaseHTTPServer.py", line
109, in server_bind
ValueError: IPv4 address 0.0.0.0 and IPv6 address ::0 are unspecified
addresses that cannot be used
as a target address.
Parameter name: hostNameOrAddress

I got the same error when experimenting with an alternative simple
Python web server solution (http://fragments.turtlemeat.com/
pythonwebserver.php) earlier.

It appears that I would need to find/create an IronPython-specific web
server solution for the tests if I wanted to go the "start selenium
server - start demo" route.
That's what I'm researching at the moment.

In the meantime, I welcome any suggestions.

Thanks.

William


Pekka Klärck

unread,
Nov 17, 2010, 12:05:51 PM11/17/10
to willia...@firsthelpline.com, robotframework-users
2010/11/17 WilliamK <willia...@firsthelpline.com>:

> I've got two separate environments for play:
> - env 1: Python, IronPython, RF and SeleniumLibrary
> - env2: IronPython, RF and SeleniumLibrary
>
> In env1, I tried Pekka's suggestion below:
>
>> Above you try to start up the Selenium Server and the demo application
>> with IronPython but then run tests using normal Python. You should do
>> it just the other way round, starting first the Selenium Server and
>> the demo application with Python:
>>     python rundemo.py selenium start
>>     python rundemo.py demoapp start
>>
>> Then you should be able to run the tests with:
>>     ipy path/to/robot/runner.py login_tests
>
> The demoapp login_tests run but all fail.
> The following is reported as the cause:
>
> -----------------
> Suite setup failed:
> TypeError: create_connection() takes at most 2 arguments (3 given)
>
> Also suite teardown failed:
> TypeError: create_connection() takes at most 2 arguments (3 given)
> -----------------
> The symptom is that the browser never starts.
>
> With the command 'python path/to/robot/runner.py login_tests', there
> is no such problem.

Could you run the test with `--loglevel debug` so that the traceback
of the failure is also logged?

Btw, yesterday when creating SeleniumLibrary 2.5 release I actually
tested running the demo with IronPython and they run fine. There was
one problem (fixed before the release) but it was in the new code
related to taking screenshots automatically. Perhaps you could also
try installing the new version and see does it work for you.

>> Alternatively, you can try to search is it possible to install a fully
>> working subprocess module for IronPython.
>>
>
> I have. There is this article: http://www.ironpython.info/index.php/Launching_Sub-Processes.

[snip]


> If I run 'ipy rundemo.py login_tests', I get error:

It seems getting subprocess setup with IronPython isn't too easy.
Hopefully a fully working version is included into IronPython in the
future.

> Still in env2, moving on, I can try running the main steps separately
> instead of the top rundemo.py.
> Starting the Selenium server can be done independently calling command
> 'java -jar ...\...\selenium-server.jar' as mentioned by Janne.

Yes, you can start the server also like this.

> But the issue is then starting the demo. I would like to do that with
> IronPython.
> If I try 'ipy server.py start', I get the following:
>
> Demo application starting on port 7272
> Traceback (most recent call last):
>  File "server.py", line 81, in <module>
>  File "server.py", line 65, in start_server
>  File "C:\Program Files\IronPython 2.7\Lib\SocketServer.py", line
> 408, in __init__
>  File "C:\Program Files\IronPython 2.7\Lib\BaseHTTPServer.py", line
> 109, in server_bind
> ValueError: IPv4 address 0.0.0.0 and IPv6 address ::0 are unspecified
> addresses that cannot be used
> as a target address.
> Parameter name: hostNameOrAddress

This appears to be an IronPython bug and I reported it [1]. I also
already added a workaround for it into the SeleniumLibrary demo code
[2], and you can do the same simple change into your local version.

[1] http://ironpython.codeplex.com/workitem/29477
[2] http://code.google.com/p/robotframework-seleniumlibrary/source/detail?r=88440f0c8524d4de83a88dc7d05a6e480b34fb0d

> It appears that I would need to find/create an IronPython-specific web
> server solution for the tests if I wanted to go the "start selenium
> server - start demo" route.
> That's what I'm researching at the moment.

Notice that you need this demo server only for the demo itself. You
don't need it if plan to use IronPython/RobotFramework/SeleniumLibrary
combination for testing some real application.

> In the meantime, I welcome any suggestions.

Hope this has helped.

WilliamK

unread,
Nov 17, 2010, 9:00:15 PM11/17/10
to robotframework-users
Thanks Pekka for the workaround to the IronPython bug.
It seems to do the trick and allow me to start server.py.

I was still experiencing issues at work so I tried a new IronPython
2.6/RF 2.5.4/SeleniumLibrary 2.5 implementation (including the updated
ElementTree) on my machine at home and well, well...
It appears to be working. I can run the RF/SeleniumLibrary demo and my
own tests and they pass.

[Note: like at work, I had to recreate the expected Python registry
entries (copied from a Python installation on another machine) but
pointing to my IronPython installation.
This is for the cases where I used a windows installer that tries to
detect a Python installation (e.g SeleniumLibrary installer).]

Here is a sample processing batch file for the tests:

----------------------------------------------------------------------

start java -jar "C:\Program Files\IronPython 2.6 for .NET 4.0\Lib\site-
packages\SeleniumLibrary\lib\selenium-server.jar"

start ipy C:\Robot\demoapp\server.py start

cd C:\Robot\DbTests
ipy "C:\Program Files\IronPython 2.6 for .NET 4.0\Lib\site-packages
\robot\runner.py" Database_Access.html

ipy C:\Robot\demoapp\server.py stop
----------------------------------------------------------------------

Since runner.py calls pythonpathsetter.py which references the env var
PYTHONPATH, I've set PYTHONPATH to "C:\Program Files\IronPython 2.6
for .NET 4.0".
I will document all this.

I guess I'll have to check my work machine's environment to figure out
what could be different from my home machine's.
In any case, if I keep getting errors, I'll make sure I use --loglevel
debug for a better output.

Eventually, I will do without server.py.

Question: how do you stop the Selenium server programmatically using a
java command?

William

Pekka Klärck

unread,
Nov 18, 2010, 3:22:15 AM11/18/10
to willia...@firsthelpline.com, robotframework-users
2010/11/18 WilliamK <willia...@firsthelpline.com>:

> Thanks Pekka for the workaround to the IronPython bug.
> It seems to do the trick and allow me to start server.py.
>
> I was still experiencing issues at work so I tried a new IronPython
> 2.6/RF 2.5.4/SeleniumLibrary 2.5 implementation (including the updated
> ElementTree) on my machine at home and well, well...
> It appears to be working. I can run the RF/SeleniumLibrary demo and my
> own tests and they pass.

Great!

> [Note: like at work, I had to recreate the expected Python registry
> entries (copied from a Python installation on another machine) but
> pointing to my IronPython installation.
> This is for the cases where I used a windows installer that tries to
> detect a Python installation (e.g SeleniumLibrary installer).]

You could consider installing RF and SeleniumLibrary using the source
distribution. Just open the archives and run `ipy setup.py install
--no-compile` inside them. The `--no-compile` option prevents you from
getting errors when compiling files to bytecode fails -- that's not
fully supported on IronPython -- although those errors wouldn't really
matter.

> Here is a sample processing batch file for the tests:
>
> ----------------------------------------------------------------------
>
> start java -jar "C:\Program Files\IronPython 2.6 for .NET 4.0\Lib\site-
> packages\SeleniumLibrary\lib\selenium-server.jar"
>
> start ipy C:\Robot\demoapp\server.py start
>
> cd C:\Robot\DbTests
> ipy "C:\Program Files\IronPython 2.6 for .NET 4.0\Lib\site-packages
> \robot\runner.py" Database_Access.html
>
> ipy C:\Robot\demoapp\server.py stop
> ----------------------------------------------------------------------
>
> Since runner.py calls pythonpathsetter.py which references the env var
> PYTHONPATH, I've set PYTHONPATH to "C:\Program Files\IronPython 2.6
> for .NET 4.0".
> I will document all this.

Looks good.

> I guess I'll have to check my work machine's environment to figure out
> what could be different from my home machine's.
> In any case, if I keep getting errors, I'll make sure I use --loglevel
> debug for a better output.

Yeah, it would be nice to know why tests fail on that environment.

> Eventually, I will do without server.py.
>
> Question: how do you stop the Selenium server programmatically using a
> java command?

The server can be stopped using the Selenium RC API directly. That's
how `rundemo.py` stops is so `ipy rundemo.py selenium stop` should
actually work. Alternatively you can create a simple Python script
with contents `import SeleniumLibrary;
SeleniumLibrary.shut_down_selenium_server()` or even close the server
with a keyword as part of your test execution.

WilliamK

unread,
Nov 18, 2010, 11:36:31 AM11/18/10
to robotframework-users
Pekka,

FYI, I've found out that one of the errors I mentioned previously that
I was getting at work

TypeError: create_connection() takes at most 2 arguments (3
given)

wass caused in IronPython 2.7 by the file <IP>\Lib\httplib.py
It contains 2 incriminated lines that read:

self.sock = socket.create_connection((self.host,self.port),
self.timeout,
self.source_address)

The 3rd argument is the problem (self.source_address).

In the same file in IP 2.6, the same calls only used 2 arguments.
So I commented out the 3rd argument in the IP 2.7 version and the
error disappeared:

self.sock = socket.create_connection((self.host,self.port),
self.timeout) #,
self.source_address)


Where I'm at:

On my work environments, the IP/RF/SeleniumLibrary works with IP
2.6.4, like at home.

I'm nearly there with another IP/RF/SeleniumLibrary implementation
with IP 2.7. But when I run the Selenium demo, the tests fail with
error:

----------------------------------------
Failed to start new browser session: Browser not supported: ???????
(Did you forget to add a *?)

and then the list of supported browser (*firefox, *mock, etc)
---------------------------------------

I thought that one was obvious and all I needed was to add the browser
exe's folder to my system PATH but it doesn't seem to work.

Any idea? I'm using the original demo, i.e., I haven't changed the
resource.txt to point to another browser. Firefox is installed and in
my PATH.

William

Reply all
Reply to author
Forward
0 new messages