2

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

2 Answers 2

2

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):
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much!
1

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.

1 Comment

Thanks, I tried to use you suggestion, but still no effect. I'll experiment later.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.