我试图运行一些测试,并且遇到了障碍,
这是脚本被捕获的开始。
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)
答案 0 :(得分:0)
计算出
dirname(__file__)
返回一个空字符串,因此搜索到了这个:Find current directory and file's directory
所以Piotr Dobrogost发布的答案就是使用
dirname(realpath(__file))