views:

196

answers:

1

Hi, starting with a base URL, I'm trying to have selenium loop through a short list of subdomains in csv format (ie: one column of 20 subdomains) and printing the html for each. I'm having trouble figuring it out. Thanks!

from selenium import selenium
import unittest, time, re, csv, logging

subds = csv.reader(open('listofsubdomains.txt', 'rb'))
for subd in subds:
        try:
            class Untitled(unittest.TestCase):
                def setUp(self):
                    self.verificationErrors = []
                    self.selenium = selenium("localhost", 4444, "*firefox", "http://www.sourcedomain.com")
                    self.selenium.start()

                def test_untitled(self):
                    sel = self.selenium
                    sel.open(subd[0])
                    html = sel.get_html_source()
                    print html

                def tearDown(self):
                    self.selenium.stop()
                    self.assertEqual([], self.verificationErrors)

            if __name__ == "__main__":
                unittest.main()

        except Exception, e:
            print>>sys.stderr, "Url % not processed: error (%s) % (url, e)"
+1  A: 

You're defining the same function again and again in the body of the class. The class is completely created before unittest.main() starts, so only one test method will remain in the class.

nosklo
Thanks, I tried to improve syntax, but still wont run.
KenBurnsFan1
Yeah, that's the same, but for classes. You create a lot of classes with the same name, so at the end (when you run `unittest.main()` ) only one remain.
nosklo