#!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2018/11/23 11:23 # @File : unittest_test2_2.py ‘‘‘Testsuits测试套件‘‘‘ import unittest from selenium import webdriver from selenium.common.exceptions import NoSuchElementException from selenium.webdriver.common.by import By #from __builtin__ import classmethod class HomePageTest(unittest.TestCase): @classmethod def setUpClass(cls): cls.driver = webdriver.Chrome() cls.driver.implicitly_wait(30) cls.driver.maximize_window() cls.driver.get(‘https://www.baidu.com/?tn=78000241_12_hao_pg‘) def test_search_field(self): self.assertTrue(self.is_element_present(By.NAME,‘wd‘)) def test_vip_promo(self): vip_promo = self.driver.find_element_by_xpath(‘//*[@id="u1"]/a[1]‘) self.assertTrue(vip_promo.is_displayed()) vip_promo.click() self.assertEqual(u‘百度新闻——全球最大的中文新闻平台‘,self.driver.title) #如果点击的链接跳转出来的页面 # 不是在当前页面的话会报错,因为self.driver表示的是当前页面 def test_login(self): login = self.driver.find_element_by_css_selector(‘#u1 > a.lb‘) login.click() login.next = self.driver.find_element_by_css_selector(‘#TANGRAM__PSP_10__qrcode > p.tang-pass-qrcode-title‘) self.assertEqual(u‘请使用百度App扫码登录‘,login.next.text) login.close = self.driver.find_element_by_css_selector(‘#TANGRAM__PSP_4__closeBtn‘) login.close.click() @classmethod def tearDownClass(cls): cls.driver.quit() def is_element_present(self,how,what): try:self.driver.find_element(by=how,value=what) except NoSuchElementException: return False return True if __name__==‘__main__‘: unittest.main(verbosity=2)
python3.6+selenium_Testsuits测试套件
原文:https://www.cnblogs.com/xiuxiu123456/p/10384189.html