pyatom / pyatom

Python Automated Testing on Mac
http://pyatom.com/
GNU General Public License v2.0
380 stars 107 forks source link

Infinite recursion sending * #128

Open sglebs opened 9 years ago

sglebs commented 9 years ago

Hi,

try this and you will get an infinite loop when it tries to process the *:

import atomac
import time
atomac.launchAppByBundleId('com.apple.calculator')
calc = atomac.getAppRefByBundleId('com.apple.calculator')
time.sleep(2)
window = calc.windows()[0]
window.sendKeys ("234*2")
sglebs commented 9 years ago

the infinite recursion:

Traceback (most recent call last):
Traceback (most recent call last):
Traceback (most recent call last):
  File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 2357, in <module>
    globals = debugger.run(setup['file'], None, None, is_module)
  File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1777, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/Users/mqm/git/webdriver-python/scratch/atomac-test.py", line 13, in <module>
    window.sendKeys ("234*2")
  File "/Users/mqm/venvs/webdriver-python/lib/python2.7/site-packages/atomac-1.1.0-py2.7-macosx-10.8-intel.egg/atomac/AXClasses.py", line 831, in sendKeys
  File "/Users/mqm/venvs/webdriver-python/lib/python2.7/site-packages/atomac-1.1.0-py2.7-macosx-10.8-intel.egg/atomac/AXClasses.py", line 288, in _sendKeys
  File "/Users/mqm/venvs/webdriver-python/lib/python2.7/site-packages/atomac-1.1.0-py2.7-macosx-10.8-intel.egg/atomac/AXClasses.py", line 278, in _sendKey
  File "/Users/mqm/venvs/webdriver-python/lib/python2.7/site-packages/atomac-1.1.0-py2.7-macosx-10.8-intel.egg/atomac/AXClasses.py", line 227, in _addKeyToQueue
  File "/Users/mqm/venvs/webdriver-python/lib/python2.7/site-packages/atomac-1.1.0-py2.7-macosx-10.8-intel.egg/atomac/AXClasses.py", line 378, in _sendKeyWithModifiers
  File "/Users/mqm/venvs/webdriver-python/lib/python2.7/site-packages/atomac-1.1.0-py2.7-macosx-10.8-intel.egg/atomac/AXClasses.py", line 278, in _sendKey
  File "/Users/mqm/venvs/webdriver-python/lib/python2.7/site-packages/atomac-1.1.0-py2.7-macosx-10.8-intel.egg/atomac/AXClasses.py", line 227, in _addKeyToQueue
  File "/Users/mqm/venvs/webdriver-python/lib/python2.7/site-packages/atomac-1.1.0-py2.7-macosx-10.8-intel.egg/atomac/AXClasses.py", line 378, in _sendKeyWithModifiers
  File "/Users/mqm/venvs/webdriver-python/lib/python2.7/site-packages/atomac-1.1.0-py2.7-macosx-10.8-intel.egg/atomac/AXClasses.py", line 278, in _sendKey
  File "/Users/mqm/venvs/webdriver-python/lib/python2.7/site-packages/atomac-1.1.0-py2.7-macosx-10.8-intel.egg/atomac/AXClasses.py", line 227, in _addKeyToQueue
  File "/Users/mqm/venvs/webdriver-python/lib/python2.7/site-packages/atomac-1.1.0-py2.7-macosx-10.8-intel.egg/atomac/AXClasses.py", line 378, in _sendKeyWithModifiers
  File "/Users/mqm/venvs/webdriver-python/lib/python2.7/site-packages/atomac-1.1.0-py2.7-macosx-10.8-intel.egg/atomac/AXClasses.py", line 278, in _sendKey
  File "/Users/mqm/venvs/webdriver-python/lib/python2.7/site-packages/atomac-1.1.0-py2.7-macosx-10.8-intel.egg/atomac/AXClasses.py", line 227, in _addKeyToQueue
  File "/Users/mqm/venvs/webdriver-python/lib/python2.7/site-packages/atomac-1.1.0-py2.7-macosx-10.8-intel.egg/atomac/AXClasses.py", line 378, in _sendKeyWithModifiers
  File "/Users/mqm/venvs/webdriver-python/lib/python2.7/site-packages/atomac-1.1.0-py2.7-macosx-10.8-intel.egg/atomac/AXClasses.py", line 278, in _sendKey
  File "/Users/mqm/venvs/webdriver-python/lib/python2.7/site-packages/atomac-1.1.0-py2.7-macosx-10.8-intel.egg/atomac/AXClasses.py", line 227, in _addKeyToQueue
  File "/Users/mqm/venvs/webdriver-python/lib/python2.7/site-packages/atomac-1.1.0-py2.7-macosx-10.8-intel.egg/atomac/AXClasses.py", line 378, in _sendKeyWithModifiers
  File "/Users/mqm/venvs/webdriver-python/lib/python2.7/site-packages/atomac-1.1.0-py2.7-macosx-10.8-intel.egg/atomac/AXClasses.py", line 278, in _sendKey
  File "/Users/mqm/venvs/webdriver-python/lib/python2.7/site-packages/atomac-1.1.0-py2.7-macosx-10.8-intel.egg/atomac/AXClasses.py", line 227, in _addKeyToQueue
  File "/Users/mqm/venvs/webdriver-python/lib/python2.7/site-packages/atomac-1.1.0-py2.7-macosx-10.8-intel.egg/atomac/AXClasses.py", line 378, in _sendKeyWithModifiers
  File "/Users/mqm/venvs/webdriver-python/lib/python2.7/site-packages/atomac-1.1.0-py2.7-macosx-10.8-intel.egg/atomac/AXClasses.py", line 278, in _sendKey
  File "/Users/mqm/venvs/webdriver-python/lib/python2.7/site-packages/atomac-1.1.0-py2.7-macosx-10.8-intel.egg/atomac/AXClasses.py", line 227, in _addKeyToQueue
  File "/Users/mqm/venvs/webdriver-python/lib/python2.7/site-packages/atomac-1.1.0-py2.7-macosx-10.8-intel.egg/atomac/AXClasses.py", line 378, in _sendKeyWithModifiers
  File "/Users/mqm/venvs/webdriver-python/lib/python2.7/site-packages/atomac-1.1.0-py2.7-macosx-10.8-intel.egg/atomac/AXClasses.py", line 278, in _sendKey
...
sglebs commented 9 years ago

The problem is that _sendKey is calling _sendKeyWithModifiers indirectly via _addKeyToQueue (when it is an upperSymbol) but _sendKeyWithModifiers calls _sendKey. Infinite recursive loop.

bzzzzzz commented 9 years ago

Your isssue is a dublicate of https://github.com/pyatom/pyatom/issues/63. https://github.com/pyatom/pyatom/issues/63 is fixed, but fix is not released and it can still be reproduced if you install atomac from pypi

sglebs commented 9 years ago

Thanks! Are you saying that installing from a git clone should work? I tried that before patching and it was still bombing. I had to fork & patch. But I definitely prefer a better fix from the maintainers, for sure.

bzzzzzz commented 9 years ago

Yes. I've just tried it on clean virtualenv (test.py contains sample code from your issue):

$ mkdir atotest
$ cd atotest
$ virtualenv pa
$ source pa/bin/activate
$ git clone git@github.com:pyatom/pyatom.git
$ cd pyatom
$ python setup.py install
$ cd ../
$ vim test.py
$ python test.py

and it definetely works without throwing any exceptions.