51Testing软件测试论坛

标题: 初学者写自动化的邮箱登陆出现了问题,各位大佬能帮帮我吗?谢谢了 [打印本页]

作者: jiaotangnatie    时间: 2019-12-4 20:45
标题: 初学者写自动化的邮箱登陆出现了问题,各位大佬能帮帮我吗?谢谢了
base.py 中写的是

import time

class BasePage:
    def __init__(self, driver):
        self.driver = driver

    def open(self, url=None):
        if url is None:
            self.driver.get(self.url)
        else:
            self.driver.get(url)

    def by_id(self,id_):
        return self.driver.find_element_by_id(id_)

    def switch_to_frame(self,iframe):
        return self.driver.switch_to.frame(iframe)

    def switch_return_iframe(self):
        return self.driver.switch_to.default_content()



在qqmail_login_page.py 中写的是
from page.base import BasePage

class QQmailLogin(BasePage):
    url='https://mail.qq.com/'

    def switch_iframe(self):
        self.switch_to_frame('login_frame')

    def switch_return_iframe(self):
        self.switch_return_iframe()

    def input_username(self,username):
        self.by_id('u').send_keys(username)

    def input_password(self,password):
        self.by_id('p').send_keys(password)

    def login_button(self):
        self.by_id('login_button').click()




最后在test_qqmail_login.py 中写的是
import csv
import codecs
from itertools import islice
from time import sleep
from page.qqmail_login_page import QQmailLogin
import unittest
from selenium import webdriver
import sys

# sys.setrecursionlimit(100000)

class TestLogin(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.driver=webdriver.Firefox()
        cls.test_data=[]
        cls.page=QQmailLogin(cls.driver)
        cls.page.open()
        with codecs.open('./data/qqmail_login_data.csv', 'r', 'utf_8_sig') as f:
            data=csv.reader(f)
            for line in islice(data,1,None):
                cls.test_data.append(line)

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

    def test_qqmail_login(self,name,ps):
        self.page.switch_iframe()
        self.page.input_username(name)
        sleep(3)
        self.page.input_password(ps)
        sleep(3)
        self.page.login_button()
        self.page.switch_return_iframe()
        sleep(3)


    def test_qqmail_loginin_success(self):
        self.test_qqmail_login(self.test_data[0][0],self.test_data[0][1])



    # def test_qqmail_login_fail1(self):
    #     self.test_qqmail_login(self.test_data[1][0],self.test_data[1][1])


    # def test_qqmail_login_fail2(self):
    #     self.test_qqmail_login(self.test_data[2][0],self.test_data[2][1])
    #
    #
    #
    # def test_qqmail_login_fail2(self):
    #     self.test_qqmail_login(self.test_data[3][0],self.test_data[3][1])





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



但是在运行test_qqmail_login.py 时出现
F:\Python37\python.exe F:/Users/jiaot/PycharmProjects/pyautoTest-master/test_dir/test_qqmail_login.py
test_qqmail_login (__main__.TestLogin) ... ERROR
test_qqmail_loginin_success (__main__.TestLogin) ... ERROR

======================================================================
ERROR: test_qqmail_login (__main__.TestLogin)
----------------------------------------------------------------------
TypeError: test_qqmail_login() missing 2 required positional arguments: 'name' and 'ps'

======================================================================
ERROR: test_qqmail_loginin_success (__main__.TestLogin)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "F:/Users/jiaot/PycharmProjects/pyautoTest-master/test_dir/test_qqmail_login.py", line 40, in test_qqmail_loginin_success
    self.test_qqmail_login(self.test_data[0][0],self.test_data[0][1])
  File "F:/Users/jiaot/PycharmProjects/pyautoTest-master/test_dir/test_qqmail_login.py", line 35, in test_qqmail_login
    self.page.switch_return_iframe()
  File "F:\Users\jiaot\PycharmProjects\pyautoTest-master\page\qqmail_login_page.py", line 10, in switch_return_iframe
    self.switch_return_iframe()
  File "F:\Users\jiaot\PycharmProjects\pyautoTest-master\page\qqmail_login_page.py", line 10, in switch_return_iframe
    self.switch_return_iframe()
  File "F:\Users\jiaot\PycharmProjects\pyautoTest-master\page\qqmail_login_page.py", line 10, in switch_return_iframe
    self.switch_return_iframe()
  [Previous line repeated 977 more times]
RecursionError: maximum recursion depth exceeded

----------------------------------------------------------------------
Ran 2 tests in 21.064s

FAILED (errors=2)

Process finished with exit code 1


两个错误都不太能理解,各位大佬能帮我看看,是我哪里有问题吗?
作者: jj52314    时间: 2019-12-5 08:36
类QQmailLogin中,这个方法死循环了
  1. def switch_return_iframe(self):
  2.         self.switch_return_iframe()
复制代码

作者: qqq911    时间: 2019-12-6 11:00
maximum recursion  满了
作者: jingzizx    时间: 2019-12-6 12:25
参数有问题报错的,依次调试
作者: litingting0214    时间: 2019-12-6 12:50
QQmailLogin中的方法循环有问题
作者: bellas    时间: 2019-12-6 15:22
参数有问题
作者: jiaotangnatie    时间: 2019-12-9 20:24
jj52314 发表于 2019-12-5 08:36
类QQmailLogin中,这个方法死循环了

是的,后来发现我有个地方自己调用自己了,无限循环了,谢谢了
作者: Miss_love    时间: 2019-12-14 14:31





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