|
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
两个错误都不太能理解,各位大佬能帮我看看,是我哪里有问题吗? |
|