class Baidu(unittest.TestCase): def setUp(self) -> None: self.driver = Browser("chrome", r".\tools\chromedriver.exe") self.driver.open_browser("http://www.baidu.com") logging.info("打开浏览器") logging.info( f"浏览器名称:{self.driver.browser_name},浏览器版本:{self.driver.browser_version}" ) self.homepage = HomePage(self.driver) self.newspage = NewsPage(self.driver) def tearDown(self) -> None: self.driver.quit() logging.info("关闭浏览器") def test_search(self): """测试百度搜索框输入selenium能搜索出包含selenium相关的信息""" logging.info("用例1:测试百度搜索框输入selenium能搜索出包含selenium相关的信息") # 输入搜索信息 self.homepage.input_box.send_keys("selenium") logging.info("输入搜索信息") # 点击按钮 self.homepage.search_button.click() logging.info("点击搜索按钮") time.sleep(2) # 校验搜索结果 els = self.driver.find_element_by_partial_link_text("selenium") self.assertIsNotNone(els) def test_access_game_news(self): """测试通过百度首页能进入新闻界面的游戏专题""" logging.info("用例2:测试通过百度首页能进入新闻界面的游戏专题") # 点击新闻链接 self.homepage.news_link.click() logging.info("点击新闻链接") # 切换窗口 self.driver.switch_to_new_page() logging.info("切换窗口") # 点击游戏链接 self.newspage.game_link.click() logging.info("点击游戏链接") # 校验url current_url = self.driver.current_url self.assertEqual(current_url, "http://news.baidu.com/game")
class Platform(abc.ABC): def __init__(self, platform): self.browser = Browser() self.config = Config(platform) self.email_alert = EmailAlert() self.By = By @abc.abstractmethod def login(self): pass @abc.abstractmethod def get_account_value(self): pass @abc.abstractmethod def get_available_funds(self): pass def get_project_value(self, project_id): return 0 def get_name(self): return self.__class__.__name__ def get_username(self): return self.config.username def get_password(self): return self.config.password def get_account(self): return self.config.account def get_currency(self): return self.config.currency def has_projects(self): return self.config.has_projects() def get_projects(self): return self.config.projects def send_alert_email(self, platform_name, message): self.email_alert.send_email_alert(platform_name, message) def quit(self): self.browser.quit()
def teardown_function(function): Browser.quit()