美文网首页web前端自动化测试(selenium3 for python3)
1、使用unittest进行功能的自动化测试

1、使用unittest进行功能的自动化测试

作者: 测试星云 | 来源:发表于2020-02-03 19:21 被阅读0次

1、unittest框架
2、路径自动读取
3、截图命名灵活
4、智能显示等待

from selenium import webdriver
import time
import unittest
import datetime,os
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class TestBingSo(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        print("这是初始化开始测试")
        parent_abspath = os.path.abspath(os.path.dirname(os.getcwd()))
        driver_path =os.path.join(parent_abspath,"driver/chromedriver")
        cls.driver = webdriver.Chrome(executable_path=driver_path)
        cls.driver.get("https://cn.bing.com/?ensearch=1&FORM=BEHPTB")
        cls.driver.maximize_window()
        assert 'Bing' in cls.driver.title

    @classmethod
    def tearDownClass(cls):
        print("执行完成环境销毁")
        cls.driver.quit()

    def test_soso(self):

        self.driver.find_element_by_id("sb_form_q").send_keys("python")
        self.driver.find_element_by_id("sb_form_go").click()
        self.driver.get_screenshot_as_file(str(datetime.datetime.now())+"_soso.png")
        wait = WebDriverWait(self.driver,10)
        wait.until(EC.title_contains("python"),'页面没加载上')
        assert 'python' in self.driver.page_source


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

相关文章

网友评论

    本文标题:1、使用unittest进行功能的自动化测试

    本文链接:https://www.haomeiwen.com/subject/lpdkxhtx.html