Python自动化测试系列[v1.0.0][html-testRunner测试报告]

安装

pip install html-testRunner

测试代码

# encoding = utf-8
'''
@Time    : 2018/8/14 20:41
@Author  : davieyang
@File    : test_AjaxElement.py
@Software: PyCharm
'''
import traceback
 
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys
import unittest
import time
import HtmlTestRunner
 
 
class TestAjaxElement(unittest.TestCase):
 
    def setUp(self):
        self.driver = webdriver.Chrome()
 
    def test_AjaxDivOptionByKeys(self):
        """simulate keyboadr keydonw and enter and by circulating"""
        url = 'http://www.sogou.com'
        self.driver.get(url)
        searchBox = self.driver.find_element_by_id('query')
        searchBox.send_keys("selenium")
        time.sleep(3)
        for i in range(3):
            searchBox.send_keys(Keys.DOWN)
            time.sleep(3)
        searchBox.send_keys(Keys.ENTER)
        time.sleep(3)
 
    def test_AjaxDivOptionByWords(self):
        """using xpath to fuzzy match"""
        url = 'http://www.sogou.com'
        self.driver.get(url)
        try:
            searchBox = self.driver.find_element_by_id('query')
            searchBox.send_keys(u'光荣之路')
            time.sleep(3)
            suggetion_option = self.driver.find_element_by_xpath("//ul/li[contains(.,'@#')]")
            suggetion_option.click()
            time.sleep(3)
        except NoSuchElementException as e:
            print(traceback.print_exc())
 
    def test_error(self):
        """ This test should be marked as error one. """
        raise ValueError
 
    def test_fail(self):
        """ This test should fail. """
        self.assertEqual(1, 2)
 
    @unittest.skip("This is a skipped test.")
    def test_AjaxDivOptionByIndex(self):
        """using xpath to locate"""
        url = 'http://www.sogou.com'
        self.driver.get(url)
        try:
            searchBox = self.driver.find_element_by_id('query')
            searchBox.send_keys(u'光荣之路')
            time.sleep(3)
            suggetion_option = self.driver.find_element_by_xpath("//*[@id='vl']/div[1]/ul/li[3]")
            suggetion_option.click()
            time.sleep(3)
        except NoSuchElementException as e:
            print(traceback.print_exc())
 
    def tearDown(self):
        self.driver.quit()
 
 
if __name__ == '__main__':
    unittest.main(testRunner=HtmlTestRunner.HTMLTestRunner(output='D:\\Programs\\Python\\PythonUnittest\\Reports\\'))

测试报告

Python自动化测试系列[v1.0.0][html-testRunner测试报告]_第1张图片

你可能感兴趣的:(Python自动化测试系列[v1.0.0][html-testRunner测试报告])