The status of Python bindings

已查看 17 次
跳至第一个未读帖子

Adam Dziendziel

未读,
2009年1月25日 08:44:572009/1/25
收件人 webdriver
Hello,

I'm thinking about using WebDriver instead of Selenium in a project
I'm working on. It is written in Python and to keep the codebase
homogeneous, I'd like to use Python for writing tests.

I'm curious about the state of Python bindings for WebDriver. From
other posts on this group I see that something is available in the
repository, but I haven't seen any example or details. Are they
CPython bindings or just the Pythonic interface to be used via Jython?

I'm wondering what would be the best approach for today. I'd like to
have my tests written in Python. Should I use Jython and write the
lower layer (Page Objects) that imports and operates on WebDriver's
Java classes? Maybe write the entire lower lower Page Objects in Java
so that I can use PageFactory, @FindBy etc.? Or use the Python
bindings from repository?

Greetings,
Adam


Jiayao Yu

未读,
2009年1月25日 17:46:542009/1/25
收件人 webd...@googlegroups.com
Hi Adam,

The Python binding for Firefox driver is in good shape and you can find it in the first_python branch. I will check it into trunk soon. We plan to add IE driver in the binding this quarter too.
 
Most of the smarts in the Firefox driver is written in Javascript in the Firefox extension. The Python binding talks directly to the extension via sockets. The APIs doesn't match the Java APIs exactly because we try to make it more Pythonic. Hence I believe your Python developers will prefer using the Python binding to the Jython approach.

I encourage you to have a look and play with the Python binding. And let us know if you find anything missing or needs changing. 

To checkout the code: svn checkout http://webdriver.googlecode.com/svn/branches/first_python

There is an test that shows the usage of the APIs. You can run it by executing py_test.sh or py_tests.bat in the base directory. depending on your OS.

Thanks,
Jiayao


2009/1/25 Adam Dziendziel <adam.dz...@gmail.com>

Adam Dziendziel

未读,
2009年1月26日 16:39:442009/1/26
收件人 webdriver
Thanks! I will try the binding.

I see that you are using mixedCase for method names. PEP 8 (
http://www.python.org/dev/peps/pep-0008/ ) recommends
lower_case_with_underscores ...if you want the code to be more
Pythonic.


Adam

On 25 Sty, 23:46, Jiayao Yu <jiayao...@gmail.com> wrote:
> Hi Adam,
> The Python binding for Firefox driver is in good shape and you can find it
> in the first_python branch. I will check it into trunk soon. We plan to add
> IE driver in the binding this quarter too.
>
> Most of the smarts in the Firefox driver is written in Javascript in the
> Firefox extension. The Python binding talks directly to the extension via
> sockets. The APIs doesn't match the Java APIs exactly because we try to make
> it more Pythonic. Hence I believe your Python developers will prefer using
> the Python binding to the Jython approach.
>
> I encourage you to have a look and play with the Python binding. And let us
> know if you find anything missing or needs changing.
>
> To checkout the code: svn checkout *http*://
> webdriver.googlecode.com/svn/branches/first_python
>
> There is an test that shows the usage of the APIs. You can run it by
> executing py_test.sh or py_tests.bat in the base directory. depending on
> your OS.
>
> Thanks,
> Jiayao
>
> 2009/1/25 Adam Dziendziel <adam.dziendz...@gmail.com>

Jiayao Yu

未读,
2009年1月27日 00:13:072009/1/27
收件人 webd...@googlegroups.com
Thanks Adam. I have seen different conventions used for Python function names so I took the one used in my company. I will switch to the PEP convention.

Jiayao

2009/1/27 Adam Dziendziel <adam.dz...@gmail.com>

Adam Dziendziel

未读,
2009年2月3日 16:21:372009/2/3
收件人 webdriver
I'm trying to use the binding and getting errors:

1. Traceback (most recent call last):
File "bindings\py\tests\api_examples.py", line 8, in <module>
from webdriver.firefox.webdriver import WebDriver
File "E:\memo\webdriver\bindings\py\src\webdriver\firefox
\webdriver.py", line
14
def __init__(self):
^
IndentationError: unindent does not match any outer indentation level

The indentation standard for Python is 4 spaces, it is recommended in
PEP8.

2. When I run install_firefox or test_firefox the browser seems to do
nothing and it doesn't quit.
It looks similar to:
http://groups.google.com/group/webdriver/browse_thread/thread/883f2f0dbd657a33/9519f93fc3eb3584?lnk=gst&q=quit#9519f93fc3eb3584

Thanks,
Adam


On 27 Sty, 06:13, Jiayao Yu <jiayao...@gmail.com> wrote:
> Thanks Adam. I have seen different conventions used for Python function
> names so I took the one used in my company. I will switch to the PEP
> convention.
>
> Jiayao
>
> 2009/1/27 Adam Dziendziel <adam.dziendz...@gmail.com>
>
>
>
> > Thanks! I will try the binding.
>
> > I see that you are using mixedCase for method names. PEP 8 (
> >http://www.python.org/dev/peps/pep-0008/) recommends

Jiayao Yu

未读,
2009年2月3日 17:32:482009/2/3
收件人 webd...@googlegroups.com
Hi Adam,

Sorry about the problem. I have fixed the code. And thanks for the suggestion, I will change the indentation to 4 space this week.
The rake install_firefox usually fails because there is already a problem with the profile, you may want to try removing the profile directory. I will fix this problem more properly by porting the profile management code from the Java code base. It's high on my todo list.
I'm just back from holiday last weekend, so you will see my promised changes start to happen soon.

Jiayao


2009/2/3 Adam Dziendziel <adam.dz...@gmail.com>

Simon Stewart

未读,
2009年2月4日 07:39:352009/2/4
收件人 webd...@googlegroups.com
On Tue, Feb 3, 2009 at 9:21 PM, Adam Dziendziel
<adam.dz...@gmail.com> wrote:

> 2. When I run install_firefox or test_firefox the browser seems to do
> nothing and it doesn't quit.
> It looks similar to:
> http://groups.google.com/group/webdriver/browse_thread/thread/883f2f0dbd657a33/9519f93fc3eb3584?lnk=gst&q=quit#9519f93fc3eb3584

The "install_firefox" target isn't really needed any more (at least on
trunk) We used it to set up a named profile, but since the profile is
set up on the fly now this is no longer necessary. Hopefully, we'll do
the Right Thing with the Python bindings too, though it may take us a
while to get there. :)

Simon

Adam Dziendziel

未读,
2009年2月4日 09:46:552009/2/4
收件人 webdriver
When the Python bindings will be merged into trunk?

The profile is created and the extension is installed. But the client
can't connect to the browser. All tests fail.
I have tried to connect manually, using "telnet localhost 7055", also
without success.

I'm using Firefox 3.0.5.
What am I doing wrong?

Thanks,
Adam

On 4 Lut, 13:39, Simon Stewart <simon.m.stew...@gmail.com> wrote:
> On Tue, Feb 3, 2009 at 9:21 PM, Adam Dziendziel
>
> <adam.dziendz...@gmail.com> wrote:
> > 2. When I run install_firefox or test_firefox the browser seems to do
> > nothing and it doesn't quit.
> > It looks similar to:
> >http://groups.google.com/group/webdriver/browse_thread/thread/883f2f0...

Jiayao Yu

未读,
2009年2月4日 13:29:142009/2/4
收件人 webd...@googlegroups.com
The python binding is in trunk now.
Please run the "rake install_firefox" in trunk, not in the first_python branch. Then run the py_tests.bat in the trunk.
If this still doesn't work, have a look at the error console in the firefox and copy it to this thread.

Thanks,
Jiayao

2009/2/4 Adam Dziendziel <adam.dz...@gmail.com>

Adam Dziendziel

未读,
2009年2月4日 15:38:392009/2/4
收件人 webdriver
Thanks, it finally started working, but still not all tests pass for
me (Firefox 3.0.6):

From Python binding suite (py_tests.bat):

======================================================================
FAIL: testSwitchToWindow (__main__.ApiExampleTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "bindings\py\tests\api_examples.py", line 58, in
testSwitchToWindow
self.assertEquals(title_1, self.driver.get_title())
AssertionError: 'XHTML Test Page' != u'We Arrive Here'


From JUnit test suite (rake test_firefox):

There were 9 errors:
1)
testClickingOnAButtonThatClosesAnOpenWindowDoesNotCauseTheBrowserToHang
(org.openqa.selenium.WindowSwitchingTest)
org.openqa.selenium.NoSuchWindowException: No window found
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1',
java.version: '1.6.0_12'
Driver info: driver.version: firefox
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance
(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance
(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.openqa.selenium.firefox.Response.ifNecessaryThrow
(Response.java:94)
at org.openqa.selenium.firefox.FirefoxDriver.sendMessage
(FirefoxDriver.java:261)
at org.openqa.selenium.firefox.FirefoxDriver.sendMessage
(FirefoxDriver.java:255)
at org.openqa.selenium.firefox.FirefoxDriver.access$300
(FirefoxDriver.java:75)
at org.openqa.selenium.firefox.FirefoxDriver
$FirefoxTargetLocator.window(FirefoxDriver.java:535)
at
org.openqa.selenium.WindowSwitchingTest.testClickingOnAButtonThatClosesAnOpenWindowDoesNotCauseTheBrowserToHang
(WindowSwitchingTest.java:86)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)
at junit.extensions.TestDecorator.basicRun(TestDecorator.java:24)
at junit.extensions.TestSetup$1.protect(TestSetup.java:23)
at junit.extensions.TestSetup.run(TestSetup.java:27)
at junit.extensions.TestDecorator.basicRun(TestDecorator.java:24)
at junit.extensions.TestSetup$1.protect(TestSetup.java:23)
at junit.extensions.TestSetup.run(TestSetup.java:27)
2)
testShouldThrowAnExceptionWhenThereIsNoLinkToClickAndItIsFoundWithXPath
(org.openqa.selenium.XPathElementFindingTest)
org.openqa.selenium.WebDriverException: Unable to find browser with id
undefined
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1',
java.version: '1.6.0_12'
Driver info: driver.version: firefox
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance
(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance
(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.openqa.selenium.firefox.Response.ifNecessaryThrow
(Response.java:94)
at org.openqa.selenium.firefox.FirefoxDriver.sendMessage
(FirefoxDriver.java:261)
at org.openqa.selenium.firefox.FirefoxDriver.sendMessage
(FirefoxDriver.java:255)
at org.openqa.selenium.firefox.FirefoxDriver.get(FirefoxDriver.java:
140)
at
org.openqa.selenium.XPathElementFindingTest.testShouldThrowAnExceptionWhenThereIsNoLinkToClickAndItIsFoundWithXPath
(XPathElementFindingTest.java:29)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)
at junit.extensions.TestDecorator.basicRun(TestDecorator.java:24)
at junit.extensions.TestSetup$1.protect(TestSetup.java:23)
at junit.extensions.TestSetup.run(TestSetup.java:27)
at junit.extensions.TestDecorator.basicRun(TestDecorator.java:24)
at junit.extensions.TestSetup$1.protect(TestSetup.java:23)
at junit.extensions.TestSetup.run(TestSetup.java:27)
3) testShouldThrowAnExceptionWhenThereIsNoLinkToClick
(org.openqa.selenium.XPathElementFindingTest)
org.openqa.selenium.WebDriverException: Unable to find browser with id
undefined
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1',
java.version: '1.6.0_12'
Driver info: driver.version: firefox
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance
(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance
(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.openqa.selenium.firefox.Response.ifNecessaryThrow
(Response.java:94)
at org.openqa.selenium.firefox.FirefoxDriver.sendMessage
(FirefoxDriver.java:261)
at org.openqa.selenium.firefox.FirefoxDriver.sendMessage
(FirefoxDriver.java:255)
at org.openqa.selenium.firefox.FirefoxDriver.get(FirefoxDriver.java:
140)
at
org.openqa.selenium.XPathElementFindingTest.testShouldThrowAnExceptionWhenThereIsNoLinkToClick
(XPathElementFindingTest.java:40)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)
at junit.extensions.TestDecorator.basicRun(TestDecorator.java:24)
at junit.extensions.TestSetup$1.protect(TestSetup.java:23)
at junit.extensions.TestSetup.run(TestSetup.java:27)
at junit.extensions.TestDecorator.basicRun(TestDecorator.java:24)
at junit.extensions.TestSetup$1.protect(TestSetup.java:23)
at junit.extensions.TestSetup.run(TestSetup.java:27)
(...)

FAILURES!!!
Tests run: 273, Failures: 1, Errors: 9


When I run "rake installfirefox" I'm getting:

E:\memo\webdriver>rake install_firefox
(in E:/memo/webdriver)
java -cp common/build/webdriver-common.jar;firefox/build/webdriver-
firefox.jar;firefox/lib/runtime/json-20080701.jar -
Dwebdriver.firefox.development="E:\memo\webdriver\firefox\src
\extension" org.openqa.selenium.firefox.FirefoxLauncher
Creating WebDriver
Profile created
Exception in thread "main"
org.openqa.selenium.firefox.NotConnectedException: Unable to connect
after 1000 ms
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1',
java.version: '1.6.0_12'
Driver info: driver.version: firefox
at
org.openqa.selenium.firefox.internal.AbstractExtensionConnection.connectToBrowser
(AbstractExtensionConnection.java:130)
at
org.openqa.selenium.firefox.internal.RunningInstanceConnection.<init>
(RunningInstanceConnection.java:32)
at
org.openqa.selenium.firefox.FirefoxLauncher.repeatedlyConnectUntilFirefoxAppearsStable
(FirefoxLauncher.java:112)
at org.openqa.selenium.firefox.FirefoxLauncher.main
(FirefoxLauncher.java:56)
rake aborted!
Command failed with status (1): [java -cp common/build/webdriver-
common.jar...]
E:/memo/webdriver/rakefile:82
(See full trace by running task with --trace)

The browser window is not opened but the profile is created.

On 4 Lut, 19:29, Jiayao Yu <jiayao...@gmail.com> wrote:
> The python binding is in trunk now.
> Please run the "rake install_firefox" in trunk, not in the first_python
> branch. Then run the py_tests.bat in the trunk.
> If this still doesn't work, have a look at the error console in the firefox
> and copy it to this thread.
>
> Thanks,
> Jiayao
>
> 2009/2/4 Adam Dziendziel <adam.dziendz...@gmail.com>

Adam Dziendziel

未读,
2009年2月4日 16:06:432009/2/4
收件人 webdriver
I did something and now all Python tests pass. The same with JUnit
tests.

It is necessary to run "rake clean" to be able to run "rake
test_firefox" again, otherwise the rake script exits. I don't know if
it is by design.

Python tests run correctly only when no other Firefox instance is
running. If FireFox is already running another profile, a new window
with the same profile is opened instead of a one with the WebDriver
profile.

Simon Stewart

未读,
2009年2月6日 06:33:382009/2/6
收件人 webd...@googlegroups.com
Hi Adam,

The rake tests only run if the JAR containing the tests needs to be
rebuilt. Which is lame, but something I've never got round to fixing.

The Python Firefox driver doesn't yet handle setting up and creating
its own isolated profile in the same way that the java one does. I
know that Jiayao is aware of the problem and has been working on it.

Regards,

Simon

Jiayao Yu

未读,
2009年2月6日 08:38:332009/2/6
收件人 webd...@googlegroups.com


2009/2/6 Simon Stewart <simon.m...@gmail.com>


Hi Adam,

The rake tests only run if the JAR containing the tests needs to be
rebuilt. Which is lame, but something I've never got round to fixing.

The Python Firefox driver doesn't yet handle setting up and creating
its own isolated profile in the same way that the java one does. I
know that Jiayao is aware of the problem and has been working on it.
回复全部
回复作者
转发
0 个新帖子