第二次Python selenium在同一个函数上失败了

时间:2018-04-14 13:13:47

标签: python selenium selenium-webdriver marionette selenium-firefoxdriver

我在unittest中使用页面对象模型。有一个功能“截图”,它传入1个测试用例但在另一个测试用例中失败。这真的很奇怪,因为它传递了1个测试用例,我确信拥有所有的依赖性。

任何帮助都将不胜感激。

代码:

import ... 

class Abc(unittest.TestCase):

    def setUp(self):
        self.xvfb = Xvfb(width=1280, height=720)
        self.xvfb.start()
        self.driver = webdriver.Firefox()
        self.driver.get(data.baseurl)

    def test_001_login(self):
        home_page = home.HomePage(self.driver)
        home_page.login(data.username, data.password)
        home_page.screenshot(self.id() + "_login_success")


    def test_002_test_scenario(self):
        home_page = home.HomePage(self.driver)
        self.driver.get(data.baseurl)
        home_page.screenshot(self.id() + "_home_page")

    def tearDown(self):
        self.driver.close()
        self.xvfb.stop


if __name__ == "__main__":
    unittest.main()

错误:

Traceback (most recent call last):
  File "/opt/buildagent/work/a8b2d36194b9264b/webtest/functions/alerts/test_alerts.py", line 65, in test_002_scenario
    home_page.screenshot(self.id() + "_home_page")
  File "/opt/buildagent/work/a8b2d36194b9264b/webtest/functions/home/home.py", line 107, in screenshot
    self.driver.save_screenshot(tmp)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 1031, in save_screenshot
    return self.get_screenshot_as_file(filename)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 1008, in get_screenshot_as_file
    png = self.get_screenshot_as_png()
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 1040, in get_screenshot_as_png
    return base64.b64decode(self.get_screenshot_as_base64().encode('ascii'))
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 1050, in get_screenshot_as_base64
    return self.execute(Command.SCREENSHOT)['value']
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 312, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
WebDriverException: Message: Failed to decode response from marionette

0 个答案:

没有答案