【发布时间】:2013-02-21 01:19:48
【问题描述】:
我正在与 django-selenium 合作,在我参与的 django 应用程序上运行 Selenium 测试。这个 django 应用使用 Qt 和本地网络服务器在本地运行。
所以要运行测试,我需要启动应用程序的服务器、selenium 服务器,然后是 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 服务器,然后在服务器关闭后终止进程,应该不会有问题。
【问题讨论】:
标签: python django unit-testing selenium