Selenium错误:BadStatusLine

时间:2016-06-02 02:21:06

标签: python selenium webdriver

您好我是Selenium Webdriver的新手,我目前正在为特定功能创建测试用例。

我有一个当前的测试用例已经在为另一个函数工作,但是当我包含一个新的测试用例并运行它时。我收到错误:BadStatusLine

此外,当我运行单个测试用例时,它工作得非常好,但是当我运行整个测试时,我将收到错误:BadStatusLine

ERROR: test_task_xml (__main__.TestActuserLayouts)
Test if the task xml is hidden
----------------------------------------------------------------------
Traceback (most recent call last):
  File "acttemplate_layouts.py", line 25, in setUp
    driver.find_element_by_name("password").submit()
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webelement.py", line 84, in submit
    self._execute(Command.SUBMIT_ELEMENT)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webelement.py", line 457, in _execute
    return self._parent.execute(command, params)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 231, in execute
    response = self.command_executor.execute(driver_command, params)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/remote_connection.py", line 395, in execute
    return self._request(command_info[0], url, body=data)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/remote_connection.py", line 426, in _request
    resp = self._conn.getresponse()
  File "/usr/lib/python2.7/httplib.py", line 1051, in getresponse
    response.begin()
  File "/usr/lib/python2.7/httplib.py", line 415, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python2.7/httplib.py", line 379, in _read_status
    raise BadStatusLine(line)
BadStatusLine: ''

这是整个测试:

    import unittest


from selenium import webdriver



class TestActuserLayouts(unittest.TestCase):
    """Test user functions """
    driver = webdriver.Firefox()
    driver.implicitly_wait(30)
    base_url = "http://samplepage.com"


    def setUp(self):
        """Base setting before test
        """
        driver = self.driver
        # Login
        driver.get(self.base_url + "/")
        driver.find_element_by_name("user_name").clear()
        driver.find_element_by_name("user_name").send_keys("userme")
        driver.find_element_by_name("password").clear()
        driver.find_element_by_name("password").send_keys("123")
        driver.find_element_by_name("password").submit()
        self.assertEqual(self.base_url + "/userme/inbox/", driver.current_url)

    def test_task_xml(self):
        """Test if the task xml is hidden
        """
        driver = self.driver
        # Get page by URL
        driver.get(self.base_url + "/userme/mission/")
        # Get page by URL
        driver.get(self.base_url + "/mission/update/0000000a-0000-0000-0000-000000000000/")
        self.assertEqual(self.base_url + "/mission/update/0000000a-0000-0000-0000-000000000000/", driver.current_url)
        driver.find_element_by_id("discussion-btn").click()
        # Scan browser if Task xml is not present
        self.assertFalse('Task xml' in self.driver.page_source)

    def test_task_list(self):
        """Test if the number of task for each mission is null
        """
        driver = self.driver
        #Get page url
        driver.get(self.base_url + "/userme/mission/")
        #Get page url
        driver.get(self.base_url + "/acttemplate/list-all/")
        #Scan browser if the number of task is null
        self.assertEqual(driver.find_element_by_xpath("//tr[3]/td[4]").text != "", True)


    def tearDown(self):
        """Clear setting after test
        """
        self.driver.close()



# Run unit test directly
if __name__ == "__main__":
    unittest.main()

而另一个测试用例是失败的。所以,我对selenium并不熟悉,我需要帮助才能找到这个错误。有人可以在这个问题上帮助我。非常感谢。

1 个答案:

答案 0 :(得分:0)

我不确定,但我会猜一猜。不知何故,浏览器在执行诸如按下按钮,单击等操作时会死亡。

这是httplib(低级python http库)引发的错误,意味着浏览器内的服务器没有响应任何已知的http状态代码(200,300,500等),相反,响应是''(空字符串)。