[英]Python Selenium test does not run when using absolute path to Firefox geckodriver
I am trying to run Selenium test in Python on Linux Ubuntu environment.我正在尝试在 Linux Ubuntu 环境中的 Python 中运行 Selenium 测试。 Geckodriver is located in my project root folder.
Geckodriver 位于我的项目根文件夹中。 I run the file named siteTest.py from PyCharm command line:
我从 PyCharm 命令行运行名为 siteTest.py 的文件:
python3 siteTest.py
python3 站点测试.py
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.但是,我没有从 Selenium 中看到任何 output。在我将其分为 setUp、test 和 tearDown 并添加self作为参数之前,测试有效。 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()
Your program was near perfect.你的程序近乎完美。 You just need to annotate the
siteTest
class as unittest.TestCase
.您只需
siteTest
class注释为unittest.TestCase
。 So effectively, you need to rewrite the line:如此有效,您需要重写该行:
class siteTest:
as:作为:
class siteTest(unittest.TestCase):
You probably need to annotate your set up and tear down methods.您可能需要注释您的设置和拆卸方法。
@classmethod
def setUp(self)
.
.
@classmethod
def tearDown(self)
.
.
Here, I have annotated as class method so it will run only once for the class.在这里,我已经注释为 class 方法,因此它只会为 class 运行一次。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.