场景:
登录后执行一个脚本,然后退出。
再登录,再执行一个,再退出。
问题:执行第一个脚本后,执行下一个是报错,如图。
单独运行每一个测试方法都可以成功,但是运行一个test.class时就不行了。
import pytest, logging,allure
from tools.time_tools import get_id
from subjectlib.yecai_page_object.browser_engine import BrowserEngine
from subjectlib.yecai_page_object.login_page import Main
from time import sleep
class Test_Apply_Query:
'''
测试用例包含:业务申请,申请查询
'''
driver = BrowserEngine().init_driver()
def setup(self):
'''
每次运行这个测试方法开始时,执行一次
:return:
'''
logging.info("setup-------")
self.main = Main(driver=self.driver)
self.main.open()
self.welcome = self.main.login()
def teardown(self):
'''
每次运行这个测试方法结束时,执行一次
:return:
'''
logging.info("teardown----")
sleep(3)
self.driver.find_element_by_xpath("//img[@class='icon-logout']").click()
self.driver.quit()
@allure.feature('业财协同管理系统')
@allure.story('用户进入我的工作台')
@allure.title('从欢迎页面跳转到我的工作台')
def test_go_to_my_work(self):
"""
从欢迎页面跳转到我的工作台
:return:
"""
menu = self.welcome.open_menu()
expected = menu.goto_my_work()
assert expected is not None
@allure.feature('业财协同管理系统')
@allure.story('用户进入我的工作台')
@allure.title('在工作台跳转我发起的列表页面')
def test_goto_i_sub_list(self):
'''
在工作台跳转我发起的列表页面
:return:
'''
menu = self.welcome.open_menu()
mywork = menu.goto_my_work()
expected = mywork.goto_i_sub_list()
assert expected is not None
@allure.feature('业财协同管理系统')
@allure.story('用户提交资金交易申请')
@allure.title('提交集团借款申请成功,返回我发起的列表页面')
def test_jituan_jiekuan_tijiao(self):
'''
提交集团借款,提交成功,返回我发起的列表页面,否则返回None
:return:
'''
title = "集团间借款{}".format(get_id(pre="pre"))
expected = self.welcome.open_menu().goto_my_work().go_to_jituan_jiekuan().store_jiekuan(title=title)
assert expected is not None
@allure.feature('业财协同管理系统')
@allure.story('用户提交资金交易申请')
@allure.title('在我发起的页面,按标题、用例执行当天日期进行查询')
def test_isublist_select(self):
'''
在我发起的页面,按标题、用例执行当天日期进行查询,并验证有查询结果,否则返回None
:return:
'''
expected = self.welcome.open_menu().goto_my_work().goto_i_sub_list().select_jiekuan("集团间借款")
assert expected is not None