我试图进行一些测试,却遇到了障碍,
这是被捕获的脚本的开始。
from selenium import selenium
import subprocess
import time
import sys
import socket
from os.path import dirname
import unittest
from pushdata import push
class selenium_tests(unittest.TestCase):
@classmethod
def setUpClass(self):
directory = dirname(__file__)
path = directory + '/selenium-server-standalone-2.28.0.jar'
sub = subprocess.Popen('exec java -jar ' + path,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
shell=True)
self.selenium_server = sub
count = 0
while True: # ensure the server is established
try:
self.selenium = selenium("localhost",
4444,
"*chrome",
"http://127.0.0.1:8000/resources/")
self.selenium.start()
break
except socket.error, v:
count += 1
if count == 10:
message = "- Selenium server took to long to establish"
print "\n", v, message
sys.exit()
time.sleep(1)
要运行测试,我使用以下命令:
python -m unittest -v selenium_tests_mod
这引发了:
[Errno 111] Connection refused - Selenium server took to long to establish
所以我知道它无法建立连接,只是不知道为什么?
注意:当我使用 django 测试框架运行它时,它可以工作,而不是当我尝试手动运行它时
编辑:
当我在单独的 shell 中运行 selenium 服务器时,它可以工作
java -jar selenium-server-standalone-2.28.0.jar
所以现在我假设这可能是原因:
sub = subprocess.Popen('exec java -jar ' + path,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
shell=True)