我正在與django-selenium在我參與的django應用程序上運行Selenium測試。這個django應用程序在本地使用Qt和本地網絡服務器運行。什麼是正確的方式來關閉套接字&避免errno 10054與python/django
所以要運行測試,我需要啓動服務器的應用程序,硒服務器,然後webdriver實例來執行測試。
django-selenium建立它的服務器與subprocess.Popen('java -jar <path_to_server.jar>')
然後我運行我們的網絡服務器的應用程序類似如果服務器沒有運行;
def run():
path = os.path.join(os.getcwd(), 'main.py')
server_running = is_server_running()
if server_running is False:
subprocess.Popen(['python', path, '-a'])
現在在測試設置看起來像這樣;
def setUp(self):
self.server = Process(target= startServer.run)
self.server.start()
並拆解;
def tearDown(self):
# stop our server
self.ff.get('http://localhost:{0}/QUIT'.format(settings.LISTEN_PORT))
# stop the selenium server
self.ff.get('http://localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer')
# close the browser
self.ff.quit()
self.server.terminate()
現在在做這件事,我得到一個error: [Errno 10054] An existing connection was forcibly closed by the remote host
。我已經嘗試在兩次呼叫之間添加sleep
以關閉連接,但這並沒有幫助。
你能看到我可能犯了什麼錯誤嗎?我想如果閉包來自遠程主機,那麼如果我先關閉服務器,然後關閉selenium服務器,然後在服務器關閉後終止進程,那麼不應該有問題。
2年後,這個奇怪的解決方案仍然有效,謝謝!我使用的Django 1.8.4,硒2.48.0。 – 2015-12-22 10:07:26