def setup_module(module): authoring.setup_module(module) application = FileServerApplication(os.path.dirname(__file__)) server.add_namespace('windmill-unittests', application)
def handle(self, *labels, **options): from windmill.conf import global_settings from windmill.authoring.djangotest import WindmillDjangoUnitTest if 'ie' in labels: global_settings.START_IE = True sys.argv.remove('ie') elif 'safari' in labels: global_settings.START_SAFARI = True sys.argv.remove('safari') elif 'chrome' in labels: global_settings.START_CHROME = True sys.argv.remove('chrome') else: global_settings.START_FIREFOX = True if 'firefox' in labels: sys.argv.remove('firefox') if 'manage.py' in sys.argv: sys.argv.remove('manage.py') if 'test_windmill' in sys.argv: sys.argv.remove('test_windmill') server_container = ServerContainer() server_container.start_test_server() global_settings.TEST_URL = 'http://localhost:%d' % server_container.server_thread.port # import windmill # windmill.stdout, windmill.stdin = sys.stdout, sys.stdin from windmill.authoring import setup_module, teardown_module from django.conf import settings tests = [] for name in settings.INSTALLED_APPS: for suffix in ['tests', 'wmtests', 'windmilltests']: x = attempt_import(name, suffix) if x is not None: tests.append((suffix,x,)); wmtests = [] for (ttype, mod,) in tests: if ttype == 'tests': for ucls in [getattr(mod, x) for x in dir(mod) if ( type(getattr(mod, x, None)) in (types.ClassType, types.TypeType) ) and issubclass(getattr(mod, x), WindmillDjangoUnitTest) ]: wmtests.append(ucls.test_dir) else: if mod.__file__.endswith('__init__.py') or mod.__file__.endswith('__init__.pyc'): wmtests.append(os.path.join(*os.path.split(os.path.abspath(mod.__file__))[:-1])) else: wmtests.append(os.path.abspath(mod.__file__)) if len(wmtests) is 0: print 'Sorry, no windmill tests found.' else: testtotals = {} x = logging.getLogger() x.setLevel(0) from windmill.server.proxy import logger from functest import bin from functest import runner runner.CLIRunner.final = classmethod(lambda self, totals: testtotals.update(totals) ) import windmill setup_module(tests[0][1]) sys.argv = sys.argv + wmtests bin.cli() teardown_module(tests[0][1]) if testtotals['fail'] is not 0: sleep(.5) sys.exit(1)
mydir = "/Users/analutzky/Desktop/data/scrapping_ETS/data/15_08_2017" " # je définis mon répertoire où seront créés mes fichiers scrapés // defining the directory where the scraped data will be stored date = "_15_08_2017" ###### PHASE 0: initialisation, lancer windmill // PHASE 0: initialization from BeautifulSoup import BeautifulSoup # pour scraper on va utiliser windmill. windmill va ouvrir firefox et faire semblant d'etre un utilisateur humain // In order to scrape, we're going to use windmill. windmill is going to open firefox and behave like a human # on commence par charger les fonctions nécessaires // we start by importing the necessary modules from windmill.authoring import setup_module, WindmillTestClient from windmill.conf import global_settings import sys # On configure windmill pour qu'il utilise firefox // we configure windmill in order to have it use firefox global_settings.START_FIREFOX = True # This makes it use Firefox setup_module(sys.modules[__name__]) client = WindmillTestClient(__name__) # temps avant timeout (pour ne pas bloquer si la page ne s'ouvre pas) // a certain amount of time before it gives up opening a page, so that it doesn't get stuck timeOut=u'8000' # 8 secondes avant time out // 8 sec before timeout # temps de pause entre deux requêtes (pour ne pas surcharger les serveurs) // time lapse between two requests (not to overwhelm the servers) timeSleep=u'100' # 0.1 seconde // 0.1 sec # l'url qu'on va vouloir scraper // the url we want to scrape rootServer="http://ec.europa.eu" BASE_URL="http://ec.europa.eu/environment/ets/napMgt.do" # la liste des pays qu'on va scrapper // the list of countries we want to scrape cntryList=['France','Germany','Austria','Belgium','Bulgaria','Croatia','Cyprus','Czech Republic','Denmark', 'Estonia','Finland','Greece','Hungary','Iceland','Ireland','Italy','Latvia','Liechtenstein','Lithuania','Luxembourg','Malta','Netherlands','Norway','Poland','Portugal','Romania','Slovakia','Slovenia','Spain','Sweden','United Kingdom'] # ouvrir la page // open the page client.open(url=BASE_URL)
def handle(self, *labels, **options): from windmill.conf import global_settings from windmill.authoring.djangotest import WindmillDjangoUnitTest if 'ie' in labels: global_settings.START_IE = True sys.argv.remove('ie') elif 'safari' in labels: global_settings.START_SAFARI = True sys.argv.remove('safari') elif 'chrome' in labels: global_settings.START_CHROME = True sys.argv.remove('chrome') else: global_settings.START_FIREFOX = True if 'firefox' in labels: sys.argv.remove('firefox') if 'manage.py' in sys.argv: sys.argv.remove('manage.py') if 'test_windmill' in sys.argv: sys.argv.remove('test_windmill') server_container = ServerContainer() server_container.start_test_server() global_settings.TEST_URL = 'http://127.0.0.1:%d' % server_container.server_thread.port # import windmill # windmill.stdout, windmill.stdin = sys.stdout, sys.stdin from windmill.authoring import setup_module, teardown_module from django.conf import settings tests = [] for name in settings.INSTALLED_APPS: for suffix in ['tests', 'wmtests', 'windmilltests']: x = attempt_import(name, suffix) if x is not None: tests.append((suffix,x,)); wmtests = [] for (ttype, mod,) in tests: if ttype == 'tests': for ucls in [getattr(mod, x) for x in dir(mod) if ( type(getattr(mod, x, None)) in (types.ClassType, types.TypeType) ) and issubclass(getattr(mod, x), WindmillDjangoUnitTest) ]: wmtests.append(ucls.test_dir) else: if mod.__file__.endswith('__init__.py') or mod.__file__.endswith('__init__.pyc'): wmtests.append(os.path.join(*os.path.split(os.path.abspath(mod.__file__))[:-1])) else: wmtests.append(os.path.abspath(mod.__file__)) if len(wmtests) is 0: print 'Sorry, no windmill tests found.' else: testtotals = {} x = logging.getLogger() x.setLevel(0) from windmill.dep import functest bin = functest.bin runner = functest.runner runner.CLIRunner.final = classmethod(lambda self, totals: testtotals.update(totals) ) setup_module(tests[0][1]) sys.argv = sys.argv + wmtests bin.cli() teardown_module(tests[0][1]) if testtotals['fail'] is not 0: sleep(.5) sys.exit(1)
from windmill.authoring import WindmillTestClient from windmill.authoring import setup_module, WindmillTestClient from windmill.conf import global_settings import sys global_settings.START_FIREFOX = True setup_module(sys.modules[__name__]) def test(): client = WindmillTestClient(__name__) client.open(url="http://us.playstation.com/publictrophy/index.htm?onlinename=terminator") client.waits.forPageLoad(timeout=u'6000') print "Test" print client.commands.getPageText() test()
def handle(self, *labels, **options): from windmill.conf import global_settings from windmill.authoring.djangotest import WindmillDjangoUnitTest # Find a browser name in the command line arguments. # One it's found, remove the browser from the arguments list. if 'ie' in labels: global_settings.START_IE = True sys.argv.remove('ie') elif 'safari' in labels: global_settings.START_SAFARI = True sys.argv.remove('safari') elif 'chrome' in labels: global_settings.START_CHROME = True sys.argv.remove('chrome') else: # If no browser is specified, default to firefox. global_settings.START_FIREFOX = True if 'firefox' in labels: sys.argv.remove('firefox') # Now remove from the arguments list the command call. if 'manage.py' in sys.argv: sys.argv.remove('manage.py') if 'test_windmill' in sys.argv: sys.argv.remove('test_windmill') # At this point, sys.argv only contains the name of the tests to run # (if any). # Start a Django server. It will automatically find a port it is # allowed to listen on. server_container = ServerContainer() server_container.start_test_server() # We access this port using .server_thread.port global_settings.TEST_URL = 'http://127.0.0.1:%d' % server_container.server_thread.port from windmill.authoring import setup_module, teardown_module from django.conf import settings # Let's try to automatically discover tests in installed Django # applications. # For example, if you have # INSTALLED_APPS = ('foo', 'bar') # Windmill will try to load: # foo.tests # foo.wmtests # foo.windmilltests # bar.tests # bar.wmtests # bar.windmilltests # tests = [] for name in settings.INSTALLED_APPS: # TODO put this suffix list in the configuration file. for suffix in ['tests', 'wmtests', 'windmilltests']: x = attempt_import(name, suffix) if x is not None: tests.append((suffix,x,)); # Now `tests` contains the list of modules which **could** contain some # Windmill tests. wmtests = [] # In `tests`, modules are stored in the form (module_name, module). # As we import *.a_suffix, module_name can only be one of the suffixes. for (ttype, mod) in tests: if ttype == 'tests': # For each attribute of the module which is a Class and is # subclass of WindmillDjangoUnitTest for ucls in [getattr(mod, x) for x in dir(mod) if ( type(getattr(mod, x, None)) in (types.ClassType, types.TypeType) ) and issubclass(getattr(mod, x), WindmillDjangoUnitTest)]: # Add it tot the test list wmtests.append(ucls.test_dir) else: # If the file is __init.py(c) if mod.__file__.endswith('__init__.py') or mod.__file__.endswith('__init__.pyc'): # We add the whole submodule to the tests wmtests.append(os.path.join(*os.path.split(os.path.abspath(mod.__file__))[:-1])) else: # Otherwise we just add the module itself wmtests.append(os.path.abspath(mod.__file__)) # We check if we finally found some usable tests if len(wmtests) is 0: # Seriously, testing with `is`, seriously? print 'Sorry, no windmill tests found.' else: # (Note: this is probably the hairiest and the most # incomprehensible piece of code I ever read. Perl scripts don't # count) # If we have something to test testtotals = {} # Prepare the logger x = logging.getLogger() x.setLevel(0) from windmill.dep import functest bin = functest.bin # We grab the CLIRunner class. This class wraps each tests and how # they are displayed on the console screen. runner = functest.runner # We override the `final` classmethod (which seems to be called # when the test suite is over). We want it to update the totals # (FIXME I think they should be called `status` because it's # a record of how many tests passed/failed/skipepd). runner.CLIRunner.final = classmethod(lambda self, totals: testtotals.update(totals) ) # FIXME OK so why only the very first module found should be # loaded? setup_module(tests[0][1]) # Update the command line arguments (SRSLY guys, have you ever # heard of functions arguments?) sys.argv = sys.argv + wmtests # Run the command line function (the one which does the full job). bin.cli() # Teardown the tested module (let's call it "The One"). teardown_module(tests[0][1]) # OK. If we failed, quit the program. if testtotals['fail'] is not 0: sleep(.5) sys.exit(1)