def setup_browser(context): if 'browser' in context.config.userdata.keys(): browser = context.config.userdata.get('browser') if browser is None: context.browser = SeElements(webdriver.Chrome()) elif browser == "chrome": context.browser = SeElements(webdriver.Chrome()) elif browser == "chrome_h": chrome_options = webdriver.ChromeOptions() chrome_options.add_argument("headless") chrome_options.add_argument('--no-sandbox') chrome_options.add_argument('--allow-running-insecure-content') chrome_options.add_argument('--ignore-certificate-errors') chrome_options.add_argument("--window-size=1920,1200") capabilities = DesiredCapabilities.CHROME.copy() capabilities['acceptSslCerts'] = True capabilities['acceptInsecureCerts'] = True context.browser = SeElements( webdriver.Chrome(chrome_options=chrome_options, desired_capabilities=capabilities)) else: print( "browser var does not exist", "Please configure a browser var within: userconfig.json - " + "behave.ini or using -D flag") return context.browser
class Login(BasePage): se = None def __init__(self, driver): super().__init__(driver) self.se = SeElements(driver) self.se.navigate(get_correct_url(os.environ["ENV"], 'teacher/login')) def load(self): self.se.find_with_wait(NEXT_BUTTON) def isLoaded(self): try: assert self.se.find_with_wait(NEXT_BUTTON).is_displayed() except wrapping_exceptions(): raise Error("Page is not loaded properly") def get_next_button(self): return self.se.find_with_wait(NEXT_BUTTON) def get_email_field(self): return self.se.find_with_wait(EMAIL_FIELD) def type_email(self): self.get_email_field().write(EMAIL) def get_password_field(self): return self.se.find_with_wait(PASSWORD_FIELD) def get_welcome_text(self): return self.se.find_with_wait(WELCOME_TEXT) def type_password(self): self.get_password_field().write(PASSWORD) def get_login_button(self): return self.se.find_with_wait(LOGIN_BUTTON) def click_next_button(self): self.get_next_button().click() def click_login_button(self): self.get_login_button().click() def make_login(self): self.type_email() self.click_next_button() self.type_password() self.click_login_button() self.get_welcome_text()
def getInstance(cls, *args, **kwargs): if cls.__instance is None: cls.__instance = object.__new__(cls) browser_options = {} if kwargs["browser_type"] == "Chrome": if kwargs["device"]: chrome_options = Options() chrome_parameters = dict() chrome_parameters["deviceName"] = kwargs["device"] chrome_options.add_experimental_option( "mobileEmulation", chrome_parameters) browser_options["chrome_options"] = chrome_options if "proxy" in kwargs and type(kwargs["proxy"]) is str: desired_capabilities = Webdriver.DesiredCapabilities.CHROME.copy( ) desired_capabilities[ 'proxy'] = WebDriverInstance.chrome_proxy( kwargs["proxy"]) browser_options[ "desired_capabilities"] = desired_capabilities cls.webdriver = Webdriver.Chrome(**browser_options) elif kwargs["browser_type"] == "Firefox": proxy = None if "proxy" in kwargs and type(kwargs["proxy"]) is str: proxy = WebDriverInstance.firefox_proxy(kwargs["proxy"]) cls.webdriver = Webdriver.Firefox(proxy=proxy) else: cls.webdriver = getattr(Webdriver, kwargs["browser_type"])() cls.driver = SeElements(cls.webdriver) cls.driver.set_window_size(kwargs["width"], kwargs["height"]) return cls.__instance.driver
def test_update_is_called_on_first_access(self): with patch.object(SeElements, 'update', return_value=True) as mock_update: e = SeElements(None, context=None, fn='.foo', lazy=True) self.assertFalse(mock_update.called) # Get the items e.items # Should be called self.assertTrue(mock_update.called)
def driver_get(request): from selenium import webdriver driver = SeElements(webdriver.Chrome()) session = request.node def exit(): driver.browser.close() driver.browser.quit() request.addfinalizer(exit) for item in session.items: cls = item.getparent(pytest.Class) setattr(cls.obj, 'driver', driver)
def before_all(context): print("> Starting the browser") global chrome_options if USE_WEBDRIVER_WRAPPER == WebdriverWrapperType.RAW: context.driver = webdriver.Chrome(chrome_options=chrome_options) elif USE_WEBDRIVER_WRAPPER == WebdriverWrapperType.ELEMENTIUM: context.driver = SeElements( webdriver.Chrome(chrome_options=chrome_options)) elif USE_WEBDRIVER_WRAPPER == WebdriverWrapperType.CAPYBARA: capybara.current_driver = "selenium_chrome" # headless #capybara.current_driver = "selenium_remote_chrome" # gui capybara.default_max_wait_time = 10 capybara.current_session().current_window.resize_to(1920, 1080)
def before_all(context): print("> Starting the browser") global chrome_options global webdriver_wrapper if webdriver_wrapper == WebdriverWrapperType.RAW: context.driver = webdriver.Chrome( #executable_path=CHROME_EXE_PATH, chrome_options=chrome_options) elif webdriver_wrapper == WebdriverWrapperType.ELEMENTIUM: context.driver = SeElements( webdriver.Chrome( #executable_path=CHROME_EXE_PATH, chrome_options=chrome_options)) elif webdriver_wrapper == WebdriverWrapperType.CAPYBARA: if webdriver_headless_mode: capybara.current_driver = "selenium_chrome" # headless else: capybara.current_driver = "selenium_remote_chrome" # gui capybara.default_max_wait_time = 10 capybara.current_session().current_window.resize_to(1920, 1080)
class GoogleDriveUi: def __init__(self, driver): self.driver = driver self.se = SeElements(browser=self.driver) def open_home_page(self): self.driver.get('https://www.google.com/drive/') def click_go_to_google_drive_button(self): self.se.xpath('//a[@data-g-action="Intro"]', wait=True, ttl=5).click() def login(self, email, password): self.open_home_page() self.click_go_to_google_drive_button() self.se.find('#identifierId', wait=True, ttl=5).clear().write(email) self.se.find('#identifierNext', wait=True, ttl=5).click() self.se.find('[type="password"]', wait=True, ttl=5).clear().write(password) self.se.find('#passwordNext', wait=True, ttl=5).click() def double_click_on_file_or_folder(self, data_id): actionChains = ActionChains(self.driver) actionChains.double_click( self.driver.find_element_by_xpath( '//div[@data-id="{}"]'.format(data_id))).perform() def find_file_or_folder(self, data_id): return self.se.xpath('//div[@data-id="{}"]'.format(data_id), wait=True, ttl=5)
def __init__(self, user, pwd): self.webdriver = webdriver.Chrome() self.se = SeElements(self.webdriver)
def __init__(self, driver): self.driver = driver self.se = SeElements(browser=self.driver)
class Facebook: def __init__(self, driver): self.driver = driver self.se = SeElements(browser=self.driver) def open_home_page(self): self.driver.get("https://www.facebook.com") def login(self, email, password): self.se.find('#email', wait=True, ttl=5).clear().write(email) self.se.find('#pass', wait=True, ttl=5).clear().write(password) self.se.find('#loginbutton', wait=True, ttl=5).click() def open_profile(self): self.se.xpath('//a[@title="Profile" or @title="Профиль"]', wait=True, ttl=5).click() def open_friends_page(self): self.se.xpath('//a[text()="Friends" or text()="Друзья"]', wait=True, ttl=5).click() def get_number_of_friends_badge(self): return self.se.xpath( '//a[@name="All friends" or @name="Все друзья"]/span[2]', wait=True, ttl=5).text() def scroll_down(self): movies_block = self.se.find('#pagelet_timeline_medley_movies') count = 50 while not len(movies_block): if count == 0: break else: self.driver.execute_script( 'window.scrollTo(0, document.body.scrollHeight);') count -= 1 def count_friends(self): friends = self.se.xpath('//div[@data-testid="friend_list_item"]', wait=True, ttl=10) return len(friends)
def __init__(self, driver): super().__init__(driver) self.se = SeElements(driver) self.se.navigate(get_correct_url(os.environ["ENV"], 'teacher/classes'))
class ClassMenu(BasePage): def __init__(self, driver): super().__init__(driver) self.se = SeElements(driver) self.se.navigate(get_correct_url(os.environ["ENV"], 'teacher/classes')) def load(self): self.se.find_with_wait(CLASS_PAGE_TITLE) def isLoaded(self): try: assert self.se.find_with_wait(CLASS_PAGE_TITLE).is_displayed() except wrapping_exceptions(): raise Error("Page is not loaded properly") def get_create_class_button(self): return self.se.find_with_wait(CREATE_A_NEW_CLASS) def get_add_class_window(self): return self.se.find_with_wait(ADD_CLASS_WINDOW) def get_class_name(self): return self.se.find_with_wait(CLASS_NAME_FIELD) def get_grade(self): return self.se.find_with_wait(GRADE) def get_period(self): return self.se.find_with_wait(PERIOD) def get_curriculum(self): return self.se.find_with_wait(CURRICULUM) def get_language(self): return self.se.find_with_wait(LANGUAGE) def get_status(self): return self.se.find_with_wait(STATUS) def get_create_class_on_modal(self): return self.se.find_with_wait(CREATE_CLASS_ON_MODAL) def get_nice_work_text(self): return self.se.find_with_wait(NICE_WORK) def get_no_thanks(self): return self.se.find_with_wait(NO_THANKS) def get_class_table(self): return self.se.find_with_wait(CLASS_TABLE) def get_class_name_inside_table(self): return self.se.find_with_wait(CLASS_NAME_INSIDE_TABLE) def get_student_count(self): return self.se.find_with_wait(STUDENT_COUNT) def get_confirm_field(self): return self.se.find_with_wait(CONFIRM_FIELD) def get_checkmark(self): return self.se.find_with_wait(CLASS_CHECKBOX) def get_bulk_action(self): return self.se.find_with_wait(BULK_ACTION) def get_delete(self): return self.se.find_with_wait(CLASS_DELETE) def get_ok(self): return self.se.find_with_wait(OK) def click_create_class_button(self): self.get_create_class_button().click() def type_class_name(self): self.get_class_name().write(CLASS_NAME) def type_confirm(self): self.get_confirm_field().write(CONFIRM) def type_grade(self): self.get_grade().write(GRADE_VALUE) def type_period(self): self.get_period().write(PERIOD_VALUE) def select_curriculum(self): self.get_curriculum().select(value=ENGLISH_VALUE) def select_language(self): self.get_language().select(value=LANGUAGE_VALUE) def select_status(self): self.get_status().select(value=STATUS_VALUE) def click_create_class_on_modal(self): self.get_create_class_on_modal().click() def click_no_thanks(self): self.get_no_thanks().click() def click_checkmark(self): self.get_checkmark().click() def click_bulk_action(self): self.get_bulk_action().click() def click_delete(self): self.get_delete().click() def click_ok(self): self.get_ok().click() # Below functions are for Create Class -> with Add student flow def get_add_student(self): return self.se.find_with_wait(ADD_STUDENT) def click_add_student(self): self.get_add_student().click() def get_add_student_title(self): return self.se.find_with_wait(ADD_STUDENT_TITLE) def get_add_single_student(self): return self.se.find_with_wait(ADD_A_SINGLE_STUDENT) def click_add_single_student(self): self.get_add_single_student().click() def get_student_details(self): return self.se.find_with_wait(STUDENT_DETAILS) def get_username(self): return self.se.find_with_wait(USERNAME) def get_student_password(self): return self.se.find_with_wait(STUDENT_PASSWORD) def get_first_name(self): return self.se.find_with_wait(FIRST_NAME) def get_last_name(self): return self.se.find_with_wait(LAST_NAME) def get_create_student(self): return self.se.find_with_wait(CREATE_STUDENT_ON_MODAL) def type_username(self, username): self.get_username().write(username) def send_tab(self): self.get_username().write(Keys.TAB) def type_student_password(self): self.get_student_password().write(ST_PASSWORD) def type_first_name(self): self.get_first_name().write(STUDENT_FNAME) def type_last_name(self): self.get_last_name().write(STUDENT_LNAME) def click_create_student(self): self.get_create_student().click() # Below is Error modal buttons functions def get_error_modal(self): return self.se.find_with_wait(ERROR_WINDOW) def get_error_text(self): return self.se.find_with_wait(ERROR_TEXT).text() def get_ok_on_error(self): return self.se.find_with_wait(OK_ON_ERROR) def click_ok_on_modal(self): self.get_ok_on_error().click()
def before_feature(context, feature): context.feature_id = context.behave_integration_service.before_feature(feature) if 'ui' in feature.tags: context.driver = get_driver(context.requested_browser) context.timeout = 10 context.browser = SeElements(context.driver)
def test_init_items_are_loaded_by_default(self): with patch.object(SeElements, 'update', return_value=True) as mock_update: SeElements(None, context=None, fn='.foo') self.assertTrue(mock_update.called)
def before_all(context): # Create an Elements object that wraps the Selenium Firefox driver # Note: You could also setup this elements outside of the behave context # and just import it in your modules instead of explicitly associating it # with the Behave context. context.elements = SeElements(webdriver.Firefox())
# Dir For Reports workDir = 'reports' # Value Sets Files # Template for test results: sideA; sideB; sideC; er; # er = expected result at_testResult = 'at-testResult.csv' # Template for test input: CaseID; Priority; sideA; sideB; sideC; expRes; TestThing; at_testInput = 'at-testInput.csv' try: if not os.path.exists(workDir): os.mkdir(workDir) finally: print('Create dir: ' + workDir) b = webdriver.Chrome(driverPath) browser = SeElements(b) browser.set_window_size(500, 600) browser.navigate(formURL) ''' 1. МЕТОДЫ ДЛЯ ТЕСТИРОВАНИЯ ОЖИДАЕМОГО РЕЗУЛЬТАТА 2. МЕТОДЫ ДЛЯ ТЕСТИРОВАНИЯ ИНПУТОВ ''' ''' ##################### ''' ''' ######### 1 ######### ''' ''' ##################### ''' resultFileForTR = f'/{at_testResult}-RUN-{datetime.today().strftime("%Y-%m-%d_%H.%M.%S")}.csv' # Метод чтения кейсов для проверки получаемого результата.
def test_delete_addressbook_in_mh(): browser = SeElements(webdriver.Firefox()) #with se as browser: # open url browser.navigate('https://bulk.boomware.com/login') # login browser.find('email').write('*****@*****.**') browser.find('password').write('123456Test') browser.find('button').click() # enter token browser.find('code').write('978896') browser.find('button').click() pass
def test_init_items_can_be_lazy_loaded(self): with patch.object(SeElements, 'update', return_value=True) as mock_update: SeElements(None, context=None, fn='.foo', lazy=True) self.assertFalse(mock_update.called)
def browser(request): driver = Firefox() se = SeElements(driver) request.addfinalizer(driver.quit) return se
def setUpClass(cls): cls.driver = SeElements( webdriver.Chrome(executable_path=r"C:\chromedriver.exe")) cls.driver.navigate(cls.url) cls.page_object = cls.page_object_class(cls.driver)
NOTE: 1) If Google ever changes their main page, this example will break. 2) This assumes that you have Firefox installed on your machine 3) This was tested on an OS X 10.10 machine running Firefox. YMMV. To run: pip install -U selenium python simple.py """ from selenium import webdriver from selenium.webdriver.common.keys import Keys from elementium.drivers.se import SeElements # Create an Elements object that wraps the Selenium Firefox driver elements = SeElements(webdriver.Firefox()) # Navigate to the Google search page elements.navigate("http://www.google.com") # Find the search box search_box = elements.find('#lst-ib')[0] # Enter something into the field to so that we can search for it search_box.write("github elementium").write(Keys.RETURN) # Quite the browser elements.browser.quit()