1

I am running some unittests with Selenium Webdriver that tests a couple websites.

I am basically trying to submit an order through a store, take the order number, and search for that order number on a different website.

I need these to be two separate tests.

I do not want to include the 'search for order number' within the first test, because 1. The 'submit an order' test is already 100+ lines, and 2. There needs to be a clear division between submitting an order pass/fails, and the order is then in the database pass/fail (if that makes sense).

Please see a snippet of my tests below.

class SmokeTest(unittest.TestCase):

    def setUp(self):
        self.driver = webdriver.Firefox()
        self.driver.implicitly_wait(30)
        self.base_url = "http://test.com"
        self.verificationErrors = []
        self.accept_next_alert = True


    def test_complete_an_order(self):
        '''complete an order'''
        return ordernumber

    def check_ordernum_exists(self):
        driver = self.driver
        driver.get("https://testdb.com")
        csp_user = driver.find_element_by_id("j_username")
        csp_user.send_keys("test")
        csp_pass = driver.find_element_by_id("j_password")
        csp_pass.send_keys("test")
        ordernum = driver.find_element_by_id('tb_order_number')
        ordernum.send_keys(ordernumber)

As you can see, I'm trying to return "ordernumber" from the first test, and fill out a field in the next test using this ordernumber?

My question is, is this even possible within the unittest framework and how can I accomplish this?

david
  • 6,303
  • 16
  • 54
  • 91
  • Possible duplicate of [Python unittest.TestCase execution order](http://stackoverflow.com/questions/5387299/python-unittest-testcase-execution-order) – Lex Scarisbrick May 23 '16 at 19:17
  • 1
    Remember that even if you could, tests should be independent of each other. – timgeb May 23 '16 at 19:19
  • I know that, I just can't think of any other solution. I guess I am going to be forced to bundle it all up into a single test since I cannot return/pass a value from one test to another – david May 23 '16 at 20:22
  • Part of the dilemma is that I'm not unit testing functions or code, I'm running selenium tests against a website. I'm thinking of maybe just converting my unittests to "test scripts" so I can be more flexible. – david May 23 '16 at 20:24

0 Answers0