<s> """<STR_LIT>""" <EOL> import time <EOL> import os <EOL> from nose . plugins import Plugin <EOL> from selenium import webdriver <EOL> from pyvirtualdisplay import Display <EOL> from seleniumbase . core import selenium_launcher <EOL> from seleniumbase . core import browser_launcher <EOL> from seleniumbase . fixtures import constants <EOL> class SeleniumBrowser ( Plugin ) : <EOL> """<STR_LIT>""" <EOL> name = '<STR_LIT>' <EOL> def options ( self , parser , env ) : <EOL> super ( SeleniumBrowser , self ) . options ( parser , env = env ) <EOL> parser . add_option ( '<STR_LIT>' , action = '<STR_LIT:store>' , <EOL> dest = '<STR_LIT>' , <EOL> choices = constants . Browser . VERSION . keys ( ) , <EOL> default = constants . Browser . FIREFOX , <EOL> help = """<STR_LIT>""" ) <EOL> parser . add_option ( '<STR_LIT>' , action = '<STR_LIT:store>' , <EOL> dest = '<STR_LIT>' , <EOL> default = "<STR_LIT>" , <EOL> help = """<STR_LIT>""" ) <EOL> parser . add_option ( '<STR_LIT>' , action = '<STR_LIT:store>' , dest = '<STR_LIT>' , <EOL> default = '<STR_LIT:localhost>' , <EOL> help = """<STR_LIT>""" ) <EOL> parser . add_option ( '<STR_LIT>' , action = '<STR_LIT:store>' , dest = '<STR_LIT:port>' , <EOL> default = '<STR_LIT>' , <EOL> help = """<STR_LIT>""" ) <EOL> parser . add_option ( '<STR_LIT>' , action = "<STR_LIT:store_true>" , <EOL> dest = '<STR_LIT>' , <EOL> default = False , <EOL> help = """<STR_LIT>""" ) <EOL> parser . add_option ( '<STR_LIT>' , action = "<STR_LIT:store_true>" , <EOL> dest = '<STR_LIT>' , <EOL> default = False , <EOL> help = """<STR_LIT>""" ) <EOL> parser . add_option ( '<STR_LIT>' , action = '<STR_LIT:store>' , dest = '<STR_LIT>' , <EOL> default = None , <EOL> help = """<STR_LIT>""" ) <EOL> def configure ( self , options , conf ) : <EOL> super ( SeleniumBrowser , self ) . configure ( options , conf ) <EOL> if not self . enabled : <EOL> return <EOL> self . browser_settings = { <EOL> "<STR_LIT>" : options . browser , <EOL> '<STR_LIT:name>' : self . conf . testNames [ <NUM_LIT:0> ] , <EOL> '<STR_LIT>' : os . getenv ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : os . getenv ( '<STR_LIT>' ) <EOL> } <EOL> if options . browser == constants . Browser . INTERNET_EXPLORER : <EOL> self . browser_settings [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> self . browser_settings [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> if options . browser_version == '<STR_LIT>' : <EOL> version = constants . Browser . LATEST [ options . browser ] <EOL> if version is not None : <EOL> self . browser_settings [ "<STR_LIT:version>" ] = version <EOL> else : <EOL> version_options = constants . Browser . VERSION [ options . browser ] <EOL> if ( version_options is not None and <EOL> options . browser_version in version_options ) : <EOL> self . browser_settings [ "<STR_LIT:version>" ] = options . browser_version <EOL> self . options = options <EOL> self . headless_active = False <EOL> if ( self . options . servername == "<STR_LIT:localhost>" and <EOL> self . options . browser == constants . Browser . HTML_UNIT ) : <EOL> selenium_launcher . execute_selenium ( self . options . servername , <EOL> self . options . port , <EOL> self . options . log_path ) <EOL> def beforeTest ( self , test ) : <EOL> """<STR_LIT>""" <EOL> if self . options . headless : <EOL> self . display = Display ( visible = <NUM_LIT:0> , size = ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> self . display . start ( ) <EOL> self . headless_active = True <EOL> if self . options . servername == "<STR_LIT:localhost>" : <EOL> try : <EOL> self . driver = self . __select_browser ( self . options . browser ) <EOL> test . test . driver = self . driver <EOL> if "<STR_LIT:version>" in self . browser_settings . keys ( ) : <EOL> version = self . browser_settings [ "<STR_LIT:version>" ] <EOL> else : <EOL> version = "<STR_LIT>" <EOL> test . test . browser = "<STR_LIT>" % ( self . options . browser , version ) <EOL> test . test . demo_mode = self . options . demo_mode <EOL> test . test . demo_sleep = self . options . demo_sleep <EOL> except Exception as err : <EOL> print "<STR_LIT>" <EOL> print err <EOL> os . kill ( os . getpid ( ) , <NUM_LIT:9> ) <EOL> else : <EOL> connected = False <EOL> for i in range ( <NUM_LIT:1> , <NUM_LIT:4> ) : <EOL> try : <EOL> self . driver = self . __select_browser ( self . options . browser ) <EOL> test . test . driver = self . driver <EOL> if "<STR_LIT:version>" in self . browser_settings . keys ( ) : <EOL> version = self . browser_settings [ "<STR_LIT:version>" ] <EOL> else : <EOL> version = "<STR_LIT>" <EOL> test . test . browser = "<STR_LIT>" % ( <EOL> self . options . browser , version ) <EOL> connected = True <EOL> break <EOL> except Exception as err : <EOL> print "<STR_LIT>" % i <EOL> if i < <NUM_LIT:3> : <EOL> print "<STR_LIT>" <EOL> time . sleep ( <NUM_LIT:3> ) <EOL> if not connected : <EOL> print "<STR_LIT>" <EOL> print err <EOL> print "<STR_LIT>" <EOL> os . kill ( os . getpid ( ) , <NUM_LIT:9> ) <EOL> def afterTest ( self , test ) : <EOL> try : <EOL> self . driver . quit ( ) <EOL> except : <EOL> print "<STR_LIT>" <EOL> if self . options . headless : <EOL> if self . headless_active : <EOL> self . display . stop ( ) <EOL> def __select_browser ( self , browser_name ) : <EOL> if ( self . options . servername != "<STR_LIT:localhost>" or <EOL> self . options . browser == constants . Browser . HTML_UNIT ) : <EOL> return webdriver . Remote ( "<STR_LIT>" % ( <EOL> self . options . servername , <EOL> self . options . port ) , <EOL> self . browser_settings ) <EOL> else : <EOL> return browser_launcher . get_driver ( browser_name ) </s>
