使用Firefox geckodriver的绝对路径时,Python Selenium测试无法运行 [英] Python Selenium test does not run when using absolute path to Firefox geckodriver

查看:65
本文介绍了使用Firefox geckodriver的绝对路径时,Python Selenium测试无法运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to run Selenium test in Python on Linux Ubuntu environment. Geckodriver is located in my project root folder. I run the file named siteTest.py from PyCharm command line:

python3 siteTest.py

python3 siteTest.py

但是,我看不到Selenium的任何输出.在将测试分为setUp,test和tearDown并添加了 self 作为参数之前,该测试已经奏效.有什么建议我做错了吗?预先感谢.

However, I do not see any output from Selenium. The test worked before I divided it into setUp, test and tearDown and added self as a parameter. Any suggestions what I am doing wrong? Thanks in advance.

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

推荐答案

您的程序接近完美.您只需要将 siteTest class 注释为 unittest.TestCase .如此有效,您需要重写以下行:

Your program was near perfect. You just need to annotate the siteTest class as unittest.TestCase. So effectively, you need to rewrite the line:

class siteTest:

为:

class siteTest(unittest.TestCase):

这篇关于使用Firefox geckodriver的绝对路径时,Python Selenium测试无法运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆