Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Firefox geckodriver的绝对路径时,不会运行Python Selenium测试_Python_Linux_Selenium_Python Unittest_Geckodriver - Fatal编程技术网

使用Firefox geckodriver的绝对路径时,不会运行Python Selenium测试

使用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

我正在尝试在Linux Ubuntu环境下用Python运行Selenium测试。 Geckodriver位于我的项目根文件夹中。 我从PyCharm命令行运行名为siteTest.py的文件:

python3 siteTest.py

但是,我没有看到Selenium的任何输出。 在我将其分为设置、测试和拆卸并将self添加为参数之前,测试工作正常。 有什么建议我做错了什么? 提前谢谢

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):