星期三,我的代码工作了。我今天回来了,我的代码不再有效。没人触及它,不包括我自己。我收到以下错误消息:
'FirefoxBinary' object has no attribute '_get_firefox_output'
我正在使用Selenium / Python的SST框架。我的代码没有直接调用browser.py文件,因为我只调用actions,cases和config。我已经卸载并重新安装了SST和Firefox,结果相同。
这是我的代码:
import unittest
from sst.actions import *
from sst import cases, config
class TestMyTest(cases.SSTTestCase):
def test_mytestcase_home_page(self):
config.results_directory = "C:/Users/Brenda/test/SST-Test-Project/results"
go_to('http://www.myhomepage.com')
assert_title_contains('My Home Page')
take_screenshot(filename='home_page.png',add_timestamp=True)
assert_element(tag='a', text='Log in')
我已将Firefox从34.0.5降级为32.我正在运行python 2.7.8。我也在运行SST 0.2.4。完整的回溯错误消息是:
C:\Python27\python.exe C:/Users/Brenda/test/SST-Test-Project/MySSTTest.py
E
======================================================================
ERROR: test_mytestcase_home_page (__main__.TestMyTest)
----------------------------------------------------------------------
_StringException: Traceback (most recent call last):
File "C:\Python27\lib\site-packages\sst\cases.py", line 75, in setUp
self.start_browser()
File "C:\Python27\lib\site-packages\sst\cases.py", line 102, in start_browser
self._start_browser()
File "C:\Python27\lib\site-packages\sst\cases.py", line 95, in _start_browser
self.browser = self.browser_factory.browser()
File "C:\Python27\lib\site-packages\sst\browsers.py", line 211, in browser
return self.webdriver_class(self.profile)
File "C:\Python27\lib\site-packages\sst\browsers.py", line 183, in __init__
firefox_profile, FirefoxBinary(), timeout, capabilities, proxy)
File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 59, in __init__
self.binary, timeout),
File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\extension_connection.py", line 47, in __init__
self.binary.launch_browser(self.profile)
File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\firefox_binary.py", line 66, in launch_browser
self._wait_until_connectable()
File "C:\Python27\lib\site-packages\sst\browsers.py", line 172, in _wait_until_connectable
% (self._get_firefox_output(),))
AttributeError: 'FirefoxBinary' object has no attribute '_get_firefox_output'
答案 0 :(得分:3)
(取自Learn to Read the Source, Luke)
在探索selenium
python绑定的源代码之后,我发现在selenium 2.44
中_get_firefox_output()
类中没有FirefoxBinary
方法可用。与contained it:
2.43
相对
def _get_firefox_output(self):
return self.process.communicate()[0]
def _wait_until_connectable(self):
"""Blocks until the extension is connectable in the firefox."""
count = 0
while not utils.is_connectable(self.profile.port):
if self.process.poll() is not None:
# Browser has exited
raise WebDriverException("The browser appears to have exited "
"before we could connect. The output was: %s" %
self._get_firefox_output())
if count == 30:
self.kill()
raise WebDriverException("Can't load the profile. Profile "
"Dir: %s Firefox output: %s" % (
self.profile.path, self._get_firefox_output()))
count += 1
time.sleep(1)
return True
换句话说, SST 0.2.4
与硒2.44
不兼容。将selenium
降级为2.43
。
答案 1 :(得分:1)
我已经sst==0.2.4
在我的Mac上使用selenium==2.44.0
进行了测试,但只有@ alecxe的答案(回到selenium==2.43.0
非常感谢)让我的测试工作在我们的无头CI测试机器上。两者都在Python 2.7.6; Firefox 34
$ sst-run -x -d mytests
starting virtual display...Tests running...
DEBUG:SST:Starting browser (attempt: 1)
DEBUG:SST:Cannot connect to process 7424 with port: 53449, count 1
DEBUG:SST:Cannot connect to process 7424 with port: 53449, count 2
DEBUG:SST:Browser started: firefox
DEBUG:SST:Going to... http://www.ubuntu.com/
DEBUG:SST:Waiting for 'get_element'
DEBUG:SST:Stopping browser
mytests.foo ... OK (3.487 secs)
Ran 1 test in 3.487s
OK
stopping virtual display...
(selenium-simple-test)iainhouston@iain-macbook:~/Documents/web/PyProjects/selenium-simple-test
$ pip freeze
argparse==1.3.0
extras==0.0.3
junitxml==0.7
python-mimeparse==0.1.4
python-subunit==1.0.0
selenium==2.44.0
six==1.9.0
sst==0.2.4
testtools==1.5.0
unittest2==0.8.0
wsgiref==0.1.2
以前,我Found existing installation: selenium 2.44.0
获得AttributeError: 'FirefoxBinary' object has no attribute '_get_firefox_output'
;在pip install selenium==2.43
测试工作之后。
(testENV)iain@jude:~/selenium_simple_test$ sst-run -x -d mytests
starting virtual display...Tests running...
DEBUG:SST:Starting browser (attempt: 1)
DEBUG:SST:Cannot connect to process 4023 with port: 42899, count 1
DEBUG:SST:Cannot connect to process 4023 with port: 42899, count 2
DEBUG:SST:Cannot connect to process 4023 with port: 42899, count 3
DEBUG:SST:Cannot connect to process 4023 with port: 42899, count 4
DEBUG:SST:Browser started: firefox
DEBUG:SST:Going to... http://www.ubuntu.com
DEBUG:SST:Waiting for 'get_element'
DEBUG:SST:Stopping browser
mytests.tests ... OK (5.951 secs)
Ran 1 test in 5.951s
OK
stopping virtual display...
(testENV)iain@jude:~/selenium_simple_test$ pip freeze
argparse==1.2.1
extras==0.0.3
junitxml==0.7
python-mimeparse==0.1.4
python-subunit==1.0.0
selenium==2.43.0
six==1.9.0
sst==0.2.4
testtools==1.5.0
unittest2==0.8.0
wsgiref==0.1.2