51Testing软件测试论坛

标题: python selenium如何实现一组数据执行后测试报告产生一条测试记录 [打印本页]

作者: 春来    时间: 2016-3-17 17:29
标题: python selenium如何实现一组数据执行后测试报告产生一条测试记录
python selenium如何实现一组数据执行后测试报告产生一条测试记录


# coding=utf-8
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
import unittest
import time,re
import csv
from test import test_support
import HTMLTestRunner
class Login(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Firefox()
        self.driver.implicitly_wait(30)
        self.base_url = ""
        self.verificationErrors = []
        self.accept_next_alert = True

    def testlogin(self,i1,i2,i3,i4):
        #"""%s""" % i1
        driver = self.driver
        driver.get(self.base_url)
        driver.maximize_window()
        driver.find_element_by_name("username").clear()
        driver.find_element_by_name("username").send_keys(i2)
        driver.find_element_by_name("passwordtxt").send_keys(i3)
        driver.find_element_by_class_name("login_button").click()
        time.sleep(3)
        text = driver.title
        self.assertEqual(text,i4.decode("gbk"),"%s" % i1)#.decode("gbk").encode("utf-8"))
        
    @staticmethod
    def getTestFunc(i1,i2,i3,i4):
        def func(self):
            self.testlogin(i1,i2,i3,i4)
        return func

    def tearDown(self):
        self.driver.quit()
        self.assertEqual([],self.verificationErrors)
testunit = unittest.TestSuite()

def __generateTestCase():
    csvfile = file("login_table.csv","rb")
    numbers = csv.reader(csvfile)
    a = 0
    for i in numbers:
        if a == 0:
            a = 1
            continue
        setattr(Login,'test_func_%s' % (i[0].decode("gbk").encode("utf-8")),
                Login.getTestFunc(*i))
        testunit.addTest(unittest.makeSuite(Login))

__generateTestCase()

filename = 'result/inquiry.html'
fp = file(filename,'wb')

runner = HTMLTestRunner.HTMLTestRunner(
    stream=fp,
    title=u"测试",
    description = u"用例执行情况: "
)

runner.run(testunit)
错误信息:
D:\python\python.exe E:/codings/yntest/login_1.py
FETraceback (most recent call last):
  File "E:/codings/yntest/login_1.py", line 67, in <module>
    runner.run(testunit)
  File "D:\python\lib\HTMLTestRunner.py", line 630, in run
    self.generateReport(test, result)
  File "D:\python\lib\HTMLTestRunner.py", line 677, in generateReport
    report = self._generate_report(result)
  File "D:\python\lib\HTMLTestRunner.py", line 741, in _generate_report
    self._generate_report_test(rows, cid, tid, n, t, o, e)
  File "D:\python\lib\HTMLTestRunner.py", line 787, in _generate_report_test
    status = self.STATUS[n],
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe7 in position 87: ordinal not in range(128)

Process finished with exit code 1


求各位大大帮忙看看


作者: 春来    时间: 2016-3-17 17:30
求大神路过指点一下
作者: 春来    时间: 2016-3-17 17:37
拜托啦,大神们
作者: 春来    时间: 2016-3-18 09:27
自顶,希望大神们能看到




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2