使用Firefox geckodriver的绝对路径时,不会运行Python Selenium测试
我正在尝试在Linux Ubuntu环境下用Python运行Selenium测试。 Geckodriver位于我的项目根文件夹中。 我从PyCharm命令行运行名为siteTest.py的文件: python3 siteTest.py 但是,我没有看到Selenium的任何输出。 在我将其分为设置、测试和拆卸并将self添加为参数之前,测试工作正常。 有什么建议我做错了什么? 提前谢谢使用Firefox geckodriver的绝对路径时,不会运行Python Selenium测试,python,linux,selenium,python-unittest,geckodriver,Python,Linux,Selenium,Python Unittest,Geckodriver,我正在尝试在Linux Ubuntu环境下用Python运行Selenium测试。 Geckodriver位于我的项目根文件夹中。 我从PyCharm命令行运行名为siteTest.py的文件: python3 siteTest.py 但是,我没有看到Selenium的任何输出。 在我将其分为设置、测试和拆卸并将self添加为参数之前,测试工作正常。 有什么建议我做错了什么? 提前谢谢 import os import unittest from selenium import webdri
import os
import unittest
from selenium import webdriver
class siteTest:
def setUp(self):
ROOT_DIR = os.path.abspath(os.curdir)
self.driver = webdriver.Firefox(executable_path=ROOT_DIR + '/geckodriver')
def test(self):
driver = self.driver
driver.get('https://google.com/')
def tearDown(self):
self.driver.quit()
if __name__ == "__main__":
unittest.main()
您可能需要对设置和拆卸方法进行注释
@classmethod
def setUp(self)
.
.
@classmethod
def tearDown(self)
.
.
在这里,我已经注释为class方法,因此它只会为类运行一次。您的程序近乎完美。您只需要将
siteTest
类注释为unittest.TestCase
。因此,您需要有效地重写该行:
class siteTest:
作为:
谢谢,我试着用你的建议,但还是没有效果。我稍后再做实验。非常感谢!
class siteTest(unittest.TestCase):