發現一個很有意思的事情:
def tearDown(self):
self.driver.close()
會報錯:
/opt/homebrew/anaconda3/envs/Selenium/bin/python /Users/mokin.li/PycharmProjects/pythonProject/main.py
./opt/homebrew/anaconda3/envs/Selenium/lib/python3.9/unittest/suite.py:84: ResourceWarning: unclosed <socket.socket fd=6, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('127.0.0.1', 56646), raddr=('127.0.0.1', 56642)>
return self.run(*args, **kwds)
ResourceWarning: Enable tracemalloc to get the object allocation traceback
----------------------------------------------------------------------
Ran 1 test in 17.560s
OK
但是將tearDown中的內容進行修改:
def tearDown(self):
self.driver.quit()
最後的返回結果:
/opt/homebrew/anaconda3/envs/Selenium/bin/python /Users/mokin.li/PycharmProjects/pythonProject/main.py
.
----------------------------------------------------------------------
Ran 1 test in 17.397s
OK
Process finished with exit code 0
有趣有趣~
要去看看quit() & close()