请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

报错TypeError: object of type 'float' has no len()

import ddt
import unittest
from handle.register_business import RegisterBusiness
from selenium import webdriver
from time import sleep
import os
import HTMLTestRunner
from util.exlcel_util import ExcelUtil

ex = ExcelUtil()
data = ex.get_data()

@ddt.ddt
class FirstDdtCase(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.driver = webdriver.Chrome()
        cls.driver.get('http://www.5itest.cn/register')
        cls.driver.maximize_window()

    def setUp(self):
        self.driver.refresh()
        self.registerb = RegisterBusiness(self.driver)

    def tearDown(self):
        sleep(3)
        for method_name, error in self._outcome.errors:
            if error:
                case_name = self._testMethodName
                file_path = os.path.join(r'..\\report\\' + case_name + '.png')
                self.driver.save_screenshot(file_path)

    @classmethod
    def tearDownClass(cls):
        cls.driver.close()

    '''
    @ddt.data(
        ['982364','ddff343','111111','111111','user_email_error','请输入有效的电子邮件地址'],
        ['121998734@qq.com','l1','111111','111111','user_email_error','请输入有效的电子邮件地址'],
        ['@qq.com', 'l1', '111111', '111111', 'user_email_error', '请输入有效的电子邮件地址']
    )
    @ddt.unpack
    '''
    @ddt.data(*data)
    def test_register_case(self,data):
        email,username,password,code,codeerror,errortext = data
        error_text = self.registerb.register_functiom(email,username,password,code,codeerror,errortext)
        self.assertFalse(error_text,'执行失败')

if __name__ == '__main__':
    file_path = os.path.join(r'..\\report\\' + "first_case.html")
    f = open(file_path,'wb')
    suite = unittest.TestLoader().loadTestsFromTestCase(FirstDdtCase)
    runner = HTMLTestRunner.HTMLTestRunner(stream=f,title='测试报告1',description="这个是测试报告1",verbosity=2)
    runner.run(suite)

图片描述

正在回答 回答被采纳积分+3

2回答

慕尼黑8578524 2021-01-07 11:00:34

https://img1.sycdn.imooc.com//szimg/5ff67901095edfc908150161.jpg转换为文本格式后,需要有文本小标,或者直接转换一下password的格式:

    @ddt.data(*data)

    def test_register_case(self,data):

        email,username,password,code,assertCode,assertText = data

        password = str(password)

        email_error = self.login.register_function(email,username,password,code,assertCode,assertText)

        self.assertFalse(email_error,"测试失败")


2 回复 有任何疑惑可以回复我~
Mushishi 2019-08-24 10:04:19

把你register handle层那一行代码前面的元素信息打印出来,你现在这个类型错误,你看一下你是否定位元素有问题

0 回复 有任何疑惑可以回复我~
  • 提问者 把悲伤留给自己 #1
    def send_email(self,email):
            self.driver01.get_email_element().send_keys(email)
    
        def send_username(self,username):
            self.driver01.get_username_element().send_keys(username)
    
        def send_password(self,password):
            self.driver01.get_password_element().send_keys(password)
    
        def send_code(self,code):
            self.driver01.get_code_element().send_keys(code)
    
        def get_user_text(self,info,user_info):
            try:
                if info == 'user_email_error':
                    text = self.driver01.get_email_error_element().text
                elif info == 'user_name_error':
                    text = self.driver01.get_username_error_element().text
                elif info == 'password_error':
                    text = self.driver01.get_username_error_element().text
                else:
                    text = self.driver01.get_code_error_element().text
            except:
                text = None
            return text
    回复 有任何疑惑可以回复我~ 2019-08-24 16:33:34
  • 提问者 把悲伤留给自己 #2
    handle层的代码之前也是运行过呀,之前都没问题
    回复 有任何疑惑可以回复我~ 2019-08-24 16:34:23
  • Mushishi 回复 提问者 把悲伤留给自己 #3
    get_password_element这个层次的输出信息或者定位信息打印出来
    回复 有任何疑惑可以回复我~ 2019-08-25 21:03:26
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信