vitaliis
vitaliis

Reputation: 4212

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. Geckodriver is located in my project root folder. I run the file named siteTest.py from PyCharm command line:

python3 siteTest.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. 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()

Upvotes: 2

Views: 185

Answers (2)

undetected Selenium
undetected Selenium

Reputation: 193338

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:

as:

class siteTest(unittest.TestCase):

Upvotes: 2

rahul rai
rahul rai

Reputation: 2326

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.

Upvotes: 1

Related Questions