<s> from selenium import webdriver <EOL> class SeleniumUtilityBelt ( object ) : <EOL> def setUp ( self ) : <EOL> self . driver = webdriver . PhantomJS ( ) <EOL> super ( SeleniumUtilityBelt , self ) . setUp ( ) <EOL> def open ( self , url ) : <EOL> self . driver . get ( "<STR_LIT>" % ( self . live_server_url , url ) ) <EOL> def find ( self , selector ) : <EOL> return self . driver . find_elements_by_css_selector ( selector ) <EOL> def get_classes ( self , element ) : <EOL> return element . get_attribute ( '<STR_LIT:class>' ) . split ( '<STR_LIT:U+0020>' ) <EOL> def get_elements_or_raise ( self , selector ) : <EOL> elements = self . find ( selector ) <EOL> if not elements : <EOL> raise AssertionError ( '<STR_LIT>' . format ( selector ) ) <EOL> return elements <EOL> def assertHasClass ( self , selector , cls ) : <EOL> elements = self . get_elements_or_raise ( selector ) <EOL> for element in elements : <EOL> classes = self . get_classes ( ) <EOL> if not cls in classes : <EOL> raise AssertionError ( <EOL> "<STR_LIT>" . format ( selector , cls ) ) <EOL> def assertOnPage ( self , selector , visible = None ) : <EOL> elements = self . get_elements_or_raise ( selector ) <EOL> if visible is not None : <EOL> for element in elements : <EOL> displayed = element . is_displayed ( ) <EOL> if visible and not displayed : <EOL> raise AssertionError ( <EOL> '<STR_LIT>' . format ( selector ) ) <EOL> elif not visible and displayed : <EOL> raise AssertionError ( <EOL> '<STR_LIT>' . format ( selector ) ) </s>
