远程浏览器关闭时避免测试失败

时间:2016-01-08 19:25:59

标签: python selenium

我每10分钟运行一次测试来测试登录功能。但是,如果远程浏览器关闭,我不希望我的测试失败。我怎样才能做到这一点?

这是我的代码:

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

import unittest
import sys


class BaseTestCase(object):

    def setUp(self):
        self.driver = webdriver.Remote(command_executor='http://***.**.**.**:****/wd/hub', desired_capabilities={'browserName': 'firefox'})
        self.driver.maximize_window()
        self.driver.get("https://example.com/login")
        self.assertEqual("Login | example.com", self.driver.title)

    def test_LoginTest(self):
        self.fill_out_field("name", "j_username", "abc")
        self.fill_out_field("name", "j_password", "xyz")
        self.click(10, "cssSelector", "input.freeze-login")
        self.driver.implicitly_wait(10)
        assert "Dashboard" in self.driver.title

    def tearDown(self):

        if sys.exc_info()[0]:
            test_method_name = self._testMethodName
            self.driver.save_screenshot(test_method_name + ".png")

        self.driver.quit()

0 个答案:

没有答案