Question

I am running a a selenium functional test using nose from inside a django function using:

arg = sys.argv[:1]
arg.append('--verbosity=2')
arg.append('-v')
out = nose.run(module=ft1.testy1, argv=arg, exit=False)

I have created the functional test using the selenium IDE. Part of the test looks like:

class y1(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Firefox()
        self.driver.implicitly_wait(30)
        self.base_url = "https://www.yahoo.com/"
        self.verificationErrors = []
        self.accept_next_alert = True

    def test_y1(self):
        driver = self.driver
        driver.get(self.base_url)
        driver.find_element_by_link_text("Weather").click()
        driver.save_screenshot('out1.png')
        return " this is a returned value"

I want to return a string value (" this is a returned value") to the calling function. How can I do this?

Was it helpful?

Solution

The output of your nose.run() does not correspond to your test method. The default behavior for unittest.TestCase is to throw an exception. If you would like to signal an external code some specific detail, you can always do it through global/class variables, files, etc.

For example, this is how to do it with a class variable (results)

ft1_runner.py:

import nose

import ft1_test

if __name__ == '__main__':
    out = nose.run(module=ft1_test, exit=False)
    print 'Y1.test_y1 test results returned:', ft1_test.Y1.results['test_y1']

ft1_test.py:

import unittest

class Y1(unittest.TestCase):
    results = {}

    def test_y1(self):
        Y1.results['test_y1'] = "this is a returned value"

I think it would help if you can describe the problem you are trying to solve: this seems a little awkward and error prone (what if the test is called twice, or test skipped, etc.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top