2016-06-14 8 views
4

私はUbuntu 16.04を使用しています。私は、仮想環境でDjango 1.9.7とSerenium 2.53.5をセットアップしました。ランダムなエラーがあると思われるすべてのURLでセレンテストが失敗する

私はHarry J.W.に従っています。今

from selenium import webdriver 
from selenium.webdriver.common.keys import Keys 
import unittest 

class NewVisitorTest(unittest.TestCase): 

    def setUp(self): 
     self.browser = webdriver.Firefox() 
     self.browser.implicitly_wait(3) 

    def tearDown(self): 
     self.browser.quit() 

    def test_can_start_a_list_and_retrieve_it_later(self): 
     # Edith has heard about a cool new online to-do app. She goes to check out its homepage 
     self.browser.get('http://localhost:8000') 

     # She notices the page title and header mention to-do lists 
     self.assertIn('To-Do', self.browser.title) 
     header_text = self.browser.find_element_by_tag_name('h1').text 
     self.assertIn('To-Do', header_text) 

     # She is invited to enter a to-do item straight away 
     inputbox = self.browser.find_element_by_id('id_new_item') 
     self.assertEqual(
      inputbox.get_attribute('placeholder'), 
      'Enter a to-do item' 
     ) 

     # She types "Buy peacock feathers" into a text box (Edith's hobby is tying fly-fishing lures) 
     inputbox.send_keys('Buy peacock feathers') 

     # When she hits enter, the page updates, and now the page lists "1: Buy peacock feathers" as an item in a to-do list 
     inputbox.send_keys(Keys.ENTER) 

     table = self.browser.find_element_by_id('id_list_table') 
     rows = table.find_elements_by_tag_name('tr') 
     self.assertTrue(
      any(row.text == '1: Buy peacock feathers' for row in rows) 
     ) 

     # There is still a text box inviting her to add another item. She enters "Use peacock feathers to make a fly" (Edith is very methodical) 
     self.fail('Finish the test!') 

     # The page updates again, and now shows both items on her list 

     # Edith wonders whether the site will remember her list. Then she sees that the site has generated a unique URL for her -- there is some explanatory text to that effect. 

     # She visits that URL - her to-do list is still there. 

     # Satisfied, she goes back to sleep 

if __name__ == '__main__': 
    unittest.main(warnings='ignore') 

を次のようにパーシバルの本「のPythonでテスト駆動開発」、と私は、コードが行く第4章の機能テストのために(「セレンは、ユーザーの対話をテストするために使用する」)最初のチュートリアルで、現在よ私はpython3 functional_tests.pyとセレンスクリプトを実行する場合Djangoのサーバを起動した後、私は

E 
====================================================================== 
ERROR: test_can_start_a_list_and_retrieve_it_later (__main__.NewVisitorTest) 
---------------------------------------------------------------------- 
Traceback (most recent call last): 
    File "functional_tests.py", line 8, in setUp 
    self.browser = webdriver.Firefox() 
    File "/home/adipanda/.virtualenvs/goat/lib/python3.5/site-packages/selenium/webdriver/firefox/webdriver.py", line 81, in __init__ 
    self.binary, timeout) 
    File "/home/adipanda/.virtualenvs/goat/lib/python3.5/site-packages/selenium/webdriver/firefox/extension_connection.py", line 51, in __init__ 
    self.binary.launch_browser(self.profile, timeout=timeout) 
    File "/home/adipanda/.virtualenvs/goat/lib/python3.5/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 68, in launch_browser 
    self._wait_until_connectable(timeout=timeout) 
    File "/home/adipanda/.virtualenvs/goat/lib/python3.5/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 98, in _wait_until_connectable 
    raise WebDriverException("The browser appears to have exited " 
selenium.common.exceptions.WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details. 


---------------------------------------------------------------------- 
Ran 1 test in 3.081s 

FAILED (errors=1) 

または

E 
====================================================================== 
ERROR: test_can_start_a_list_and_retrieve_it_later (__main__.NewVisitorTest) 
---------------------------------------------------------------------- 
Traceback (most recent call last): 
    File "functional_tests.py", line 9, in setUp 
    self.browser.implicitly_wait(3) 
    File "/home/adipanda/.virtualenvs/goat/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 689, in implicitly_wait 
    self.execute(Command.IMPLICIT_WAIT, {'ms': float(time_to_wait) * 1000}) 
    File "/home/adipanda/.virtualenvs/goat/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 234, in execute 
    response = self.command_executor.execute(driver_command, params) 
    File "/home/adipanda/.virtualenvs/goat/lib/python3.5/site-packages/selenium/webdriver/remote/remote_connection.py", line 401, in execute 
    return self._request(command_info[0], url, body=data) 
    File "/home/adipanda/.virtualenvs/goat/lib/python3.5/site-packages/selenium/webdriver/remote/remote_connection.py", line 432, in _request 
    resp = self._conn.getresponse() 
    File "/usr/lib/python3.5/http/client.py", line 1197, in getresponse 
    response.begin() 
    File "/usr/lib/python3.5/http/client.py", line 297, in begin 
    version, status, reason = self._read_status() 
    File "/usr/lib/python3.5/http/client.py", line 266, in _read_status 
    raise RemoteDisconnected("Remote end closed connection without" 
http.client.RemoteDisconnected: Remote end closed connection without response 

---------------------------------------------------------------------- 
Ran 1 test in 2.437s 

FAILED (errors=1) 
の下に与えられているそのうちの3つのトレースバックの束、と一見ランダムエラーレポートを取得しますでも、前にこれらのエラーへ

または

E 
====================================================================== 
ERROR: test_can_start_a_list_and_retrieve_it_later (__main__.NewVisitorTest) 
---------------------------------------------------------------------- 
Traceback (most recent call last): 
    File "functional_tests.py", line 20, in test_can_start_a_list_and_retrieve_it_later 
    header_text = self.browser.find_element_by_tag_name('h1').text 
    File "/home/adipanda/.virtualenvs/goat/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 389, in find_element_by_tag_name 
    return self.find_element(by=By.TAG_NAME, value=name) 
    File "/home/adipanda/.virtualenvs/goat/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 745, in find_element 
    {'using': by, 'value': value})['value'] 
    File "/home/adipanda/.virtualenvs/goat/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 234, in execute 
    response = self.command_executor.execute(driver_command, params) 
    File "/home/adipanda/.virtualenvs/goat/lib/python3.5/site-packages/selenium/webdriver/remote/remote_connection.py", line 401, in execute 
    return self._request(command_info[0], url, body=data) 
    File "/home/adipanda/.virtualenvs/goat/lib/python3.5/site-packages/selenium/webdriver/remote/remote_connection.py", line 432, in _request 
    resp = self._conn.getresponse() 
    File "/usr/lib/python3.5/http/client.py", line 1197, in getresponse 
    response.begin() 
    File "/usr/lib/python3.5/http/client.py", line 297, in begin 
    version, status, reason = self._read_status() 
    File "/usr/lib/python3.5/http/client.py", line 266, in _read_status 
    raise RemoteDisconnected("Remote end closed connection without" 
http.client.RemoteDisconnected: Remote end closed connection without response 

---------------------------------------------------------------------- 
Ran 1 test in 3.693s 

、セレンはランダムRemote end closed connectionを表示し、コマンドは、コードを変更せずに、再び実行された場合は、エラーのない動作します。

誰かが何が起こっているか説明できますか?

+0

どのブラウザですか?とブラウザのバージョン? – ravigadila

+1

Firefox 47.0(セレン2.53.5)にアップグレードして以来、「ブラウザーが終了したようです」というエラーが表示されます。 – user3468054

+0

@RaviKumarうん問題は、私が走っているFirefoxがバージョン47.0だと思われます –

答えて

3

簡単な答えは、Firefoxを46にダウングレードするか、Marionette Web Driverをインストールする必要があるということです。私も同様の問題がありました。

下記の質問のトップ定格の回答をご覧ください。

Can't open browser with Selenium after Firefox update

+0

私のFirefoxは現在、バージョン47.0で動作しています。あなたがリンクしている質問の指示に従います。もしうまくいけば、あなたの答えを受け入れたものとしてマークします。ありがとう! –

+0

それは働いた。ありがとう! –

関連する問題