【问题标题】:Selenium not connecting硒没有连接
【发布时间】:2013-02-15 02:48:07
【问题描述】:

我正在尝试运行一些测试,但遇到了障碍,

这是被捕获的脚本的开始。

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)

【问题讨论】:

    标签: python unit-testing sockets selenium


    【解决方案1】:

    解决了

    dirname(__file__)
    

    返回的是一个空字符串,所以四处搜索发现:Find current directory and file's directory

    所以 Piotr Dobrogost 发布的答案是使用

    dirname(realpath(__file)) 
    

    【讨论】:

      猜你喜欢
      • 2015-05-15
      • 1970-01-01
      • 2019-01-30
      • 2018-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多