Python selenium failing on same function on 2nd time

时光毁灭记忆、已成空白 提交于 2019-12-11 05:08:25

问题


I am using page object model in unittest. There is a function "screenshot" which is passing in 1 test case but failing in another. It is really strange and since it is passing in 1 test case, i am sure about having all the dependancies.

Any help would be appreciated.

Code:

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()

Error:

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

来源:https://stackoverflow.com/questions/49831841/python-selenium-failing-on-same-function-on-2nd-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!