请稍等 ...
×

采纳答案成功!

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

求助,报错TypeError: main() missing 1 required positional argument: 'self'

老师,按照您说的授课流程一步步写的为什么报错TypeError: main() missing 1 required positional argument: ‘self’。 请老师帮我看看哪里有问题?

具体报错信息:
E:\Python3.7.1\python.exe F:/test_project/case/first_case.py
Traceback (most recent call last):
File “F:/test_project/case/first_case.py”, line 5, in
class FirstCase(object):
File “F:/test_project/case/first_case.py”, line 52, in FirstCase
main()
TypeError: main() missing 1 required positional argument: ‘self’

Process finished with exit code 1

代码详情
#PO模式:case、页面、数据全部分离开来
#下面是一条条的用例,case,只管输入
from selenium import webdriver
from business.register_business import RegisterBusiness
class FirstCase(object):
def init(self):
driver = webdriver.Chrome()
driver.get(‘http://www.5itest.cn/register’)
self.login = RegisterBusiness(driver)

#判断邮箱检验是否正确
def test_login_email_error(self):
    email_error = self.login.login_email_error('14','user111','111111','test1')
    if email_error == True:
        print('注册成功,此条case失败')
    #通过assert  判断是否是  error

# 判断用户名检验是否正确
def test_login_username_error(self):
    username_error = self.login.login_name_error('14@qq.com', '@#$', '111111', 'test1')
    if username_error == True:
        print('注册成功,此条case失败')

# 判断密码检验是否正确
def test_login_password_error(self):
    password_error = self.login.login_password_error('14@qq.com', 'user111', '1', 'test1')
    if password_error == True:
        print('注册成功,此条case失败')

# 判断验证码检验是否正确
def test_login_code_error(self):
    code_error = self.login.login_code_error('14@qq.com', 'user111', '1', 'test1')
    if code_error == True:
        print('注册成功,此条case失败')

# 是否注册成功,true是成功
def test_login_success(self):
    success = self.login.user_base('14@qq.com','user111','111111','test1')
    if self.login.register_sucess()== True:
        print("注册成功")

#把整体的结构分解出来,再一步步填入
def main(self):
    first = FirstCase()
    first.test_login_email_error()
    first.test_login_code_error()
    first.test_login_password_error()
    first.test_login_username_error()
    first.test_login_success()

if __name__ == '__main__':
    main()

正在回答

1回答

Mushishi 2020-07-31 20:02:03

https://img1.sycdn.imooc.com//szimg/5f24079f0901751207050431.jpg你这个是一个类

https://img1.sycdn.imooc.com/szimg/5f2407d409c9864506490345.jpg这个是类下面得方法 还是本身类里面的方法还是不是?如果是里面的方法这么肯定不是,如果是单独的方法 你这个写得不对呀。不是类里面得东西为啥要self?

0 回复 有任何疑惑可以回复我~
  • 提问者 仲夏rww #1
    非常感谢!这个main()他是类里边的方法
    回复 有任何疑惑可以回复我~ 2020-08-03 17:51:16
  • 提问者 仲夏rww #2
    File "E:\Python3.7.1\lib\configparser.py", line 696, in read
        self._read(fp, filename)
      File "E:\Python3.7.1\lib\configparser.py", line 1014, in _read
        for lineno, line in enumerate(fp, start=1):
    UnicodeDecodeError: 'gbk' codec can't decode byte 0xaf in position 354: illegal multibyte sequence
    
    
    
    
    老师,不知道这个错误是什么原因引起的。
    回复 有任何疑惑可以回复我~ 2020-08-03 18:07:33
  • Mushishi 回复 提问者 仲夏rww #3
    你ini里面是不是又中文?然后里面你是不是没有加utf-8
    回复 有任何疑惑可以回复我~ 2020-08-03 22:02:10
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信