def main(): commands = ['init', 'gen', 'test', 'trans', 'help'] if len(sys.argv) < 2: print "Missing argument! Arguments must be [ %s ]" % " ".join( commands) sys.exit(1) command = sys.argv[1] if command not in commands: print "Wrong argument! Arguments must be [ %s ]" % " ".join(commands) sys.exit(1) if command == commands[0]: op_init_project() print 'project init successfull!' sys.exit(0) if command == commands[1]: generate_project() print 'project generated successfull!' sys.exit(0) if command == commands[2]: test_project() print 'project test successfull!' sys.exit(0) if command == commands[3]: start_server() sys.exit(0) if command == commands[4]: print '----help end----' sys.exit(0)
def prepare_test_setup(request): """Run an HTTP server during the tests.""" print "\nCalling create_xpi", create_xpi() print "\nStarting local_http_server" server, server_thread = utilities.start_server() def local_http_server_stop(): print "\nClosing server thread..." server.shutdown() server_thread.join() request.addfinalizer(local_http_server_stop)
def start_jpm(): cmd_jpm_run = "jpm run --prefs %s --binary-args 'url %s' -b %s" % ( PREF_FILE, BASE_TEST_URL, FF_BIN_PATH) server, thread = start_server() try: # http://stackoverflow.com/a/4417735/3104416 for line in get_command_output(cmd_jpm_run, cwd=EXT_PATH): print colorize(line), bcolors.ENDC, except KeyboardInterrupt: print "Keyboard Interrupt detected, shutting down..." print "\nClosing server thread..." server.shutdown() thread.join()
def start_jpm(): cmd_jpm_run = "jpm run --binary-args 'url %s' -b %s" % (BASE_TEST_URL, FF_BIN_PATH) server, thread = start_server() try: # http://stackoverflow.com/a/4417735/3104416 for line in get_command_output(cmd_jpm_run, cwd=EXT_PATH): print colorize(line), bcolors.ENDC, except KeyboardInterrupt: print "Keyboard Interrupt detected, shutting down..." print "\nClosing server thread..." server.shutdown() thread.join()
def start_manual_test(): cmd_cd = "cd ../automation/Extension/firefox/" cmd_jpm = "jpm run --binary-args '%s' -b `which firefox`" % BASE_TEST_URL server, thread = start_server() try: # http://stackoverflow.com/a/4417735/3104416 for line in run_cmd("%s && %s" % (cmd_cd, cmd_jpm)): print bcolors.OKGREEN, line, bcolors.ENDC, except KeyboardInterrupt: print "Keyboard Interrupt detected, shutting down..." print "\nClosing server thread..." server.shutdown() thread.join()
def start_webdriver(with_extension=False): """ Open a webdriver instance and a server for the test pages This is meant to be imported and run manually from a python or ipython shell. A webdriver instance is returned and both the webdriver and server will automatically clean up when the shell is exited. Parameters ---------- with_extension : boolean Set to True to also load OpenWPM extension instrumentation Returns ------- webdriver A selenium webdriver instance. """ fb = FirefoxBinary(FF_BIN_PATH) server, thread = start_server() def register_cleanup(driver): driver.get(BASE_TEST_URL) def cleanup_server(): print "Cleanup before shutdown..." server.shutdown() thread.join() print "...sever shutdown" driver.quit() print "...webdriver closed" atexit.register(cleanup_server) return driver if not with_extension: return register_cleanup(webdriver.Firefox(firefox_binary=fb)) # add openwpm extension to profile create_xpi() fp = webdriver.FirefoxProfile() ext_xpi = join(EXT_PATH, 'openwpm.xpi') fp.add_extension(extension=ext_xpi) fp.set_preference("*****@*****.**", "all") return register_cleanup( webdriver.Firefox(firefox_binary=fb, firefox_profile=fp))
def trans(): start_server() sys.exit(0)
def setup_class(cls): cls.server, cls.server_thread = utilities.start_server()