【发布时间】:2016-07-22 12:01:14
【问题描述】:
我希望能够在同一个测试文件中使用同一个浏览器会话进行多个测试。
我为登录设置了一个类:
class Loginpage ():
url="http://appsv01:8084/#/"
def __init__(self, workbook):
self.workbook=workbook
def login(self,value_Name,worksheet):
#Open a new mymobile suite window in Chrome and maximize
driver = webdriver.Chrome('C:/temp/chromedriver.exe')
driver.get("http://appsv01:8084")
driver.maximize_window()
我一直在关闭浏览器会话,然后在每次测试时打开一个新会话,但我尝试更改它以使结构看起来像(在名为 test_mytests.py 的文件中):
#open the browser and log in
mylogin=Loginpage('C:\Automation\Common_Objects.xlsx')
driver=mylogin.login("AutoSMS", "Users")
#perform the first test
def test_one():
task1
task2
#perform the second test
def test_two():
task3
task4
这失败并出现错误:
E ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
如果我将#open the browser 的代码分别放在每个测试下,那么一切正常。是否可以只打开一次浏览器并让文件中的所有测试在同一个浏览器会话上运行?
【问题讨论】: