<s> import sys <EOL> sys . path . append ( "<STR_LIT>" ) <EOL> if sys . version < '<STR_LIT>' : <EOL> import unittest2 as unittest <EOL> else : <EOL> import unittest <EOL> try : <EOL> import StringIO <EOL> except ImportError : <EOL> from io import StringIO <EOL> import mock <EOL> import seleniumwrapper <EOL> from selenium . webdriver . common . desired_capabilities import DesiredCapabilities <EOL> from selenium . webdriver . remote . webdriver import WebDriver <EOL> from selenium . webdriver . remote . webelement import WebElement <EOL> from seleniumwrapper . wrapper import SeleniumWrapper <EOL> from seleniumwrapper . wrapper import SeleniumContainerWrapper <EOL> from selenium . common . exceptions import ( <EOL> NoSuchElementException , WebDriverException , ElementNotVisibleException , TimeoutException <EOL> ) <EOL> class TestSeleniumWrapperFactory ( unittest . TestCase ) : <EOL> def test_factory_functions_raise_typeerror_if_argument_is_not_a_string ( self ) : <EOL> self . assertRaises ( TypeError , seleniumwrapper . create , <NUM_LIT:1> ) <EOL> self . assertRaises ( TypeError , seleniumwrapper . connect , <NUM_LIT:1> , "<STR_LIT>" ) <EOL> self . assertRaises ( TypeError , seleniumwrapper . connect , "<STR_LIT>" , <NUM_LIT:1> ) <EOL> def test_factory_functions_raise_valueerror_if_invalid_drivername_is_given ( self ) : <EOL> self . assertRaises ( ValueError , seleniumwrapper . create , '<STR_LIT>' ) <EOL> self . assertRaises ( ValueError , seleniumwrapper . create , '<STR_LIT>' ) <EOL> self . assertRaises ( ValueError , seleniumwrapper . connect , '<STR_LIT>' , "<STR_LIT>" ) <EOL> self . assertRaises ( ValueError , seleniumwrapper . connect , '<STR_LIT>' , "<STR_LIT>" ) <EOL> def test_connect_merge_3rd_arguments_with_desired_capabilities ( self ) : <EOL> p = mock . patch ( "<STR_LIT>" ) <EOL> m = p . start ( ) <EOL> p2 = mock . patch ( "<STR_LIT>" ) <EOL> m2 = p2 . start ( ) <EOL> seleniumwrapper . connect ( "<STR_LIT>" , "<STR_LIT>" , { "<STR_LIT>" : "<STR_LIT>" } ) <EOL> dic = DesiredCapabilities . ANDROID <EOL> dic [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> m . assert_called_once_with ( '<STR_LIT>' , dic ) <EOL> p2 . stop ( ) <EOL> p . stop ( ) <EOL> class TestSeleniumWrapper ( unittest . TestCase ) : <EOL> def test_init_raise_if_driver_is_not_a_webdriver_object ( self ) : <EOL> self . assertRaises ( TypeError , SeleniumWrapper , '<STR_LIT>' ) <EOL> def test_init_not_raise_if_driver_is_a_webdriver_object ( self ) : <EOL> mocked_driver = mock . Mock ( WebDriver ) <EOL> SeleniumWrapper ( mocked_driver ) <EOL> def test_wrapper_should_delegate_unknown_attribute_access_to_wrapped_driver ( self ) : <EOL> mocked_driver = mock . Mock ( WebDriver ) <EOL> mocked_driver . hoge = lambda d : d <EOL> wrapper = SeleniumWrapper ( mocked_driver ) <EOL> self . assertEqual ( wrapper . hoge ( <NUM_LIT:1> ) , <NUM_LIT:1> ) <EOL> def test_wrapper_should_raise_AttributeError_if_wrapped_driver_also_dont_have_attribute_with_given_name ( self ) : <EOL> mocked_driver = mock . Mock ( WebDriver ) <EOL> wrapper = SeleniumWrapper ( mocked_driver ) <EOL> self . assertRaises ( AttributeError , getattr , * [ wrapper , '<STR_LIT>' ] ) <EOL> def test_wrapper_should_chain_wrapping_if_possible ( self ) : <EOL> mocked_driver = mock . Mock ( WebDriver ) <EOL> mocked_element = mock . Mock ( WebElement ) <EOL> mocked_driver . find_element_by_id = lambda given : given <EOL> wrapper = SeleniumWrapper ( mocked_driver ) <EOL> wrapped_element = wrapper . find_element_by_id ( mocked_element ) <EOL> unwrapped_element = wrapper . find_element_by_id ( "<STR_LIT>" ) <EOL> self . assertTrue ( isinstance ( wrapped_element , SeleniumWrapper ) ) <EOL> self . assertFalse ( isinstance ( unwrapped_element , SeleniumWrapper ) ) <EOL> def test_wrapper_should_respond_to_waitfor ( self ) : <EOL> mocked_driver = mock . Mock ( WebDriver ) <EOL> mocked_driver . find_element_by_id = lambda target : target <EOL> wrapper = SeleniumWrapper ( mocked_driver ) <EOL> self . assertEqual ( wrapper . waitfor ( '<STR_LIT:id>' , '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> def test_wrapper_should_handle_attr_access_even_if_attr_is_descriptor ( self ) : <EOL> mocked_element = mock . Mock ( WebElement ) <EOL> class Hoge ( WebDriver ) : <EOL> def __init__ ( self ) : <EOL> pass <EOL> @ property <EOL> def hoge ( self ) : <EOL> return mocked_element <EOL> @ property <EOL> def num ( self ) : <EOL> return <NUM_LIT:100> <EOL> mocked_driver = Hoge ( ) <EOL> wrapper = SeleniumWrapper ( mocked_driver ) <EOL> self . assertEqual ( wrapper . num , <NUM_LIT:100> ) <EOL> self . assertTrue ( isinstance ( wrapper . hoge , SeleniumWrapper ) , wrapper . hoge ) <EOL> def test_click_should_raise_if_element_is_not_stopping_for_time_seconds ( self ) : <EOL> class Hoge ( object ) : <EOL> def __init__ ( self ) : <EOL> self . num = <NUM_LIT:0> <EOL> def __getitem__ ( self , num ) : <EOL> self . num += <NUM_LIT:1> <EOL> return self . num <EOL> mocked_element = mock . Mock ( WebElement ) <EOL> mocked_element . location = Hoge ( ) <EOL> wrapper = SeleniumWrapper ( mocked_element ) <EOL> self . assertRaises ( WebDriverException , wrapper . click , ** { '<STR_LIT>' : <NUM_LIT:0.5> } ) <EOL> def test_click_should_raise_if_element_is_not_clickable_for_timeout_seconds ( self ) : <EOL> def dummy ( ) : <EOL> raise WebDriverException ( "<STR_LIT>" ) <EOL> mocked_element = mock . Mock ( WebElement ) <EOL> mocked_element . click = dummy <EOL> mocked_element . value_of_css_property . return_value = <NUM_LIT:0> <EOL> mocked_element . location = { "<STR_LIT:x>" : <NUM_LIT:0> , "<STR_LIT:y>" : <NUM_LIT:0> } <EOL> wrapper = SeleniumWrapper ( mocked_element ) <EOL> self . assertRaises ( WebDriverException , wrapper . click , ** { '<STR_LIT>' : <NUM_LIT:0.5> } ) <EOL> def test_click_should_raise_if_element_is_not_displayed_for_timeout_seconds ( self ) : <EOL> mocked_element = mock . Mock ( WebElement ) <EOL> mocked_element . is_displayed = lambda : False <EOL> mocked_element . value_of_css_property . return_value = <NUM_LIT:0> <EOL> mocked_element . location = { "<STR_LIT:x>" : <NUM_LIT:0> , "<STR_LIT:y>" : <NUM_LIT:0> } <EOL> wrapper = SeleniumWrapper ( mocked_element ) <EOL> self . assertRaises ( ElementNotVisibleException , wrapper . click , ** { '<STR_LIT>' : <NUM_LIT:0.5> } ) <EOL> def test_click_should_raise_if_other_exception_is_thrown ( self ) : <EOL> def dummy ( ) : <EOL> raise TypeError ( ) <EOL> mocked_element = mock . Mock ( WebElement ) <EOL> mocked_element . click = dummy <EOL> wrapper = SeleniumWrapper ( mocked_element ) <EOL> self . assertRaises ( TypeError , wrapper . click , ** { '<STR_LIT>' : <NUM_LIT:0.5> } ) <EOL> def test_unwrap_return_its_wrapped_object ( self ) : <EOL> mocked_element = mock . Mock ( WebElement ) <EOL> wrapper = SeleniumWrapper ( mocked_element ) <EOL> self . assertIsInstance ( wrapper . unwrap , WebElement ) <EOL> def test_execute_script_should_return_None_if_null_was_returned ( self ) : <EOL> mocked_driver = mock . Mock ( WebDriver ) <EOL> mocked_driver . execute_script . return_value = None <EOL> driver = SeleniumWrapper ( mocked_driver ) <EOL> obj = driver . execute_script ( '<STR_LIT>' ) <EOL> self . assertIsNone ( obj ) <EOL> def test_wrapper_returns_None_in_silent_mode ( self ) : <EOL> mocked_driver = mock . Mock ( WebDriver ) <EOL> mocked_driver . find_element_by_id . side_effect = TimeoutException <EOL> driver = SeleniumWrapper ( mocked_driver ) <EOL> self . assertRaises ( NoSuchElementException , driver . by_id , '<STR_LIT>' ) <EOL> driver . silent = True <EOL> self . assertIsNone ( driver . by_id ( '<STR_LIT>' ) ) <EOL> class TestSeleniumWrapperAliases ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> mocky = mock . Mock ( WebDriver ) <EOL> self . mock = mocky <EOL> def test_waitfor_raise_if_find_element_return_falsy_value ( self ) : <EOL> self . mock . find_element_by_xpath . return_value = None <EOL> wrapper = SeleniumWrapper ( self . mock ) <EOL> self . assertRaises ( NoSuchElementException , wrapper . waitfor , * [ '<STR_LIT>' , '<STR_LIT>' ] , ** { '<STR_LIT>' : <NUM_LIT:0.1> } ) <EOL> def test_waitfor_raise_if_find_elements_return_falsy_value ( self ) : <EOL> self . mock . find_elements_by_xpath . return_value = [ ] <EOL> wrapper = SeleniumWrapper ( self . mock ) <EOL> self . assertRaises ( NoSuchElementException , wrapper . waitfor , * [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> ** { '<STR_LIT>' : True , '<STR_LIT>' : <NUM_LIT:0.1> } ) <EOL> def test_waitfor_wraps_its_return_value_if_it_is_wrappable ( self ) : <EOL> mock_elem = mock . Mock ( WebElement ) <EOL> self . mock . find_element_by_xpath . return_value = mock_elem <EOL> wrapper = SeleniumWrapper ( self . mock ) <EOL> self . assertIsInstance ( wrapper . waitfor ( "<STR_LIT>" , "<STR_LIT>" ) , SeleniumWrapper ) <EOL> def test_waitfor_wraps_its_return_value_if_given_eager_arument_is_true ( self ) : <EOL> mock_elem = mock . Mock ( WebElement ) <EOL> self . mock . find_elements_by_xpath . return_value = [ mock_elem ] <EOL> wrapper = SeleniumWrapper ( self . mock ) <EOL> self . assertIsInstance ( wrapper . waitfor ( "<STR_LIT>" , "<STR_LIT>" , eager = True ) , SeleniumContainerWrapper ) <EOL> def test_attr_raise_if_invoked_from_webdriver_wrapped_object ( self ) : <EOL> wrapper = SeleniumWrapper ( self . mock ) <EOL> self . assertRaises ( AttributeError , wrapper . attr , '<STR_LIT>' ) <EOL> def test_attr_invoke_get_attribute_if_invoked_from_webelement_wrapped ( self ) : <EOL> mock_elem = mock . Mock ( WebElement ) <EOL> mock_elem . get_attribute . return_value = True <EOL> wrapped = SeleniumWrapper ( mock_elem ) <EOL> self . assertTrue ( wrapped . attr ( '<STR_LIT>' ) ) <EOL> def test_aliases_work_correctly ( self ) : <EOL> mock_elem = mock . Mock ( WebElement ) <EOL> self . mock . find_element_by_xpath . return_value = mock_elem <EOL> self . mock . find_element_by_css_selector . return_value = mock_elem <EOL> self . mock . find_element_by_tag_name . return_value = mock_elem <EOL> self . mock . find_element_by_class_name . return_value = mock_elem <EOL> self . mock . find_element_by_id . return_value = mock_elem <EOL> self . mock . find_element_by_name . return_value = mock_elem <EOL> self . mock . find_element_by_link_text . return_value = mock_elem <EOL> self . mock . find_element_by_partial_link_text . return_value = mock_elem <EOL> wrapper = SeleniumWrapper ( self . mock ) <EOL> self . assertIsInstance ( wrapper . xpath ( "<STR_LIT>" ) , SeleniumWrapper ) <EOL> self . assertIsInstance ( wrapper . css ( "<STR_LIT>" ) , SeleniumWrapper ) <EOL> self . assertIsInstance ( wrapper . by_tag ( "<STR_LIT>" ) , SeleniumWrapper ) <EOL> self . assertIsInstance ( wrapper . by_class ( "<STR_LIT>" ) , SeleniumWrapper ) <EOL> self . assertIsInstance ( wrapper . by_id ( "<STR_LIT>" ) , SeleniumWrapper ) <EOL> self . assertIsInstance ( wrapper . by_name ( "<STR_LIT>" ) , SeleniumWrapper ) <EOL> self . assertIsInstance ( wrapper . by_linktxt ( "<STR_LIT>" ) , SeleniumWrapper ) <EOL> self . assertIsInstance ( wrapper . by_linktxt ( "<STR_LIT>" , partial = True ) , SeleniumWrapper ) <EOL> self . assertIsInstance ( wrapper . href ( "<STR_LIT>" ) , SeleniumWrapper ) <EOL> self . assertIsInstance ( wrapper . img ( alt = "<STR_LIT>" ) , SeleniumWrapper ) <EOL> self . assertIsInstance ( wrapper . by_text ( "<STR_LIT>" , "<STR_LIT>" ) , SeleniumWrapper ) <EOL> self . assertIsInstance ( wrapper . button ( "<STR_LIT>" ) , SeleniumWrapper ) <EOL> wrapped_elem = mock . Mock ( WebElement ) <EOL> wrapped_elem . find_element_by_xpath . return_value = mock_elem <EOL> wrapper = SeleniumWrapper ( wrapped_elem ) <EOL> self . assertIsInstance ( wrapper . parent , SeleniumWrapper ) <EOL> class TestSeleniumWrapperJavascriptSupport ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> mocky = mock . Mock ( WebDriver ) <EOL> self . mock = mocky <EOL> def test_scroll_methods_raise_if_wrapped_is_not_webdriver ( self ) : <EOL> wrapper = SeleniumWrapper ( mock . Mock ( WebElement ) ) <EOL> self . assertRaises ( AttributeError , wrapper . scroll_to , * [ <NUM_LIT:10> , <NUM_LIT:10> ] ) <EOL> self . assertRaises ( AttributeError , wrapper . scroll_by , * [ <NUM_LIT:10> , <NUM_LIT:10> ] ) <EOL> self . assertRaises ( AttributeError , wrapper . scroll_into_view , '<STR_LIT>' ) <EOL> def test_scroll_into_view_raise_if_no_jquery_found ( self ) : <EOL> wrapper = SeleniumWrapper ( self . mock ) <EOL> self . mock . execute_script . return_value = None <EOL> self . assertRaises ( AttributeError , wrapper . scroll_into_view , '<STR_LIT>' ) <EOL> def test_scroll_into_view_execute_script_if_jquery_was_found ( self ) : <EOL> wrapper = SeleniumWrapper ( self . mock ) <EOL> wrapper . scroll_into_view ( '<STR_LIT>' ) <EOL> calls = [ mock . call . execute_script ( "<STR_LIT>" ) , <EOL> mock . call . execute_script ( "<STR_LIT>" ) ] <EOL> self . mock . assert_has_calls ( calls ) <EOL> class TestSeleniumWrapperOptions ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> mocky = mock . Mock ( WebDriver ) <EOL> self . mock = mocky <EOL> def test_timeout_property_allows_int_and_float ( self ) : <EOL> wrapper = SeleniumWrapper ( self . mock ) <EOL> wrapper . timeout = <NUM_LIT:0.1> <EOL> self . assertEqual ( wrapper . timeout , <NUM_LIT:0.1> ) <EOL> wrapper . timeout = <NUM_LIT:1> <EOL> self . assertEqual ( wrapper . timeout , <NUM_LIT:1> ) <EOL> def test_silent_property_raise_AttributeError_if_none_bool_given ( self ) : <EOL> wrapper = SeleniumWrapper ( self . mock ) <EOL> try : <EOL> wrapper . silent = <NUM_LIT:1> <EOL> except AttributeError : <EOL> pass <EOL> def suite ( ) : <EOL> suite = unittest . TestSuite ( ) <EOL> suite . addTests ( unittest . makeSuite ( TestSeleniumWrapperAliases ) ) <EOL> suite . addTests ( unittest . makeSuite ( TestSeleniumWrapper ) ) <EOL> suite . addTests ( unittest . makeSuite ( TestSeleniumWrapperJavascriptSupport ) ) <EOL> return suite <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> s = suite ( ) <EOL> unittest . TextTestRunner ( verbosity = <NUM_LIT:2> ) . run ( s ) </s>
