Best Python code snippet using robotframework-appiumlibrary_python
test_extendedelementfinder.py
Source:test_extendedelementfinder.py
1#!/usr/bin/env python2# -*- coding: utf-8 -*-3# Extended Selenium2 Library - a web testing library with AngularJS support.4# Copyright (c) 2015, 2016 Richard Huang <rickypc@users.noreply.github.com>5#6# This program is free software: you can redistribute it and/or modify7# it under the terms of the GNU Affero General Public License as8# published by the Free Software Foundation, either version 3 of the9# License, or (at your option) any later version.10#11# This program is distributed in the hope that it will be useful,12# but WITHOUT ANY WARRANTY; without even the implied warranty of13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the14# GNU Affero General Public License for more details.15#16# You should have received a copy of the GNU Affero General Public License17# along with this program. If not, see <http://www.gnu.org/licenses/>.18"""19Extended Selenium2 Library - a web testing library with AngularJS support.20"""21from sys import path22path.append('src')23import unittest24import mock25from ExtendedSelenium2Library.locators import ExtendedElementFinder26from selenium.webdriver.remote.webelement import WebElement27from Selenium2Library.locators import ElementFinder28class ExtendedElementFinderTests(unittest.TestCase):29 """Extended element finder keyword test class."""30 def setUp(self):31 """Instantiate the extended element finder class."""32 self.default_strategies = ['binding', 'button', 'css', 'default', 'dom',33 'id', 'identifier', 'jquery', 'link', 'model',34 'name', 'options', 'partial binding',35 'partial button', 'partial link', 'scLocator',36 'sizzle', 'tag', 'xpath']37 self.driver = mock.Mock()38 self.driver.session_id = 'session'39 self.finder = ExtendedElementFinder()40 self.finder._filter_elements = mock.Mock()41 self.finder._find_by_css_selector = mock.Mock()42 self.finder.BUTTON_TEXT_WRAPPER = 'return buttons;%(handler)s'43 self.finder.NG_BINDING_WRAPPER = 'return bindings;%(handler)s'44 self.ng_prefixes = ['ng-', 'data-ng-', 'ng_', 'x-ng-', 'ng\\:']45 self.web_element = WebElement(self.driver, 'element', False)46 self.finder._filter_elements.return_value = self.web_element47 self.finder._find_by_css_selector.return_value = self.web_element48 def test_should_inherit_finder(self):49 """Extended element finder instance should inherit Selenium2 element finder instances."""50 self.assertIsInstance(self.finder, ElementFinder)51 def test_should_inherit_attributes(self):52 """Extended element finder instance should inherit its parent attributes."""53 self.assertEqual(self.finder._default_strategies, self.default_strategies)54 self.assertEqual(self.finder._ng_prefixes, self.ng_prefixes)55 def test_should_find_by_button_text(self):56 """Should find by button text."""57 button_text = 'a-button'58 constrains = 'constrains'59 script = "return buttons;return text.replace(/^\s+|\s+$/g,'')==='%s'" % \60 button_text61 tag = 'tag'62 self.finder._find_by_button_text(self.driver, button_text, tag, constrains)63 self.driver.execute_script.assert_called_with(script)64 self.finder._filter_elements.assert_called_with(self.driver.execute_script.return_value,65 tag, constrains)66 def test_should_find_by_button_text_partial(self):67 """Should find by button partial text."""68 button_text = 'a-button'69 constrains = 'constrains'70 script = "return buttons;return text.indexOf('%s')>-1" % \71 button_text72 tag = 'tag'73 self.finder._find_by_button_text_partial(self.driver, button_text, tag, constrains)74 self.driver.execute_script.assert_called_with(script)75 self.finder._filter_elements.assert_called_with(self.driver.execute_script.return_value,76 tag, constrains)77 def test_should_find_by_ng_binding(self):78 """Should find by exact binding name."""79 binding_name = 'a-binding'80 constrains = 'constrains'81 script = ("return bindings;var matcher=new RegExp('({|\\s|^|\\|)'+'%s'."82 "replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,'\\$&')"83 "+'(}|\\s|$|\\|)');return matcher.test(name)") % \84 binding_name85 tag = 'tag'86 self.finder._find_by_ng_binding(self.driver, binding_name, tag, constrains)87 self.driver.execute_script.assert_called_with(script)88 self.finder._filter_elements.assert_called_with(self.driver.execute_script.return_value,89 tag, constrains)90 def test_should_find_by_ng_binding_partial(self):91 """Should find by partial binding name."""92 binding_name = 'a-binding'93 constrains = 'constrains'94 script = "return bindings;return name.indexOf('%s')>-1" % \95 binding_name96 tag = 'tag'97 self.finder._find_by_ng_binding_partial(self.driver, binding_name, tag, constrains)98 self.driver.execute_script.assert_called_with(script)99 self.finder._filter_elements.assert_called_with(self.driver.execute_script.return_value,100 tag, constrains)101 def test_should_find_by_ng_model(self):102 """Should find by exact model name."""103 constrains = 'constrains'104 model_name = 'a-model'105 stem = 'model="%s"' % model_name106 joiner = '%s],[' % stem107 criteria = '[' + joiner.join(self.ng_prefixes) + stem + ']'108 tag = 'tag'109 self.finder._find_by_ng_model(self.driver, model_name, tag, constrains)110 self.finder._find_by_css_selector.assert_called_with(self.driver,111 criteria, tag,112 constrains)113 def test_should_find_by_ng_options(self):114 """Should find by exact descriptor."""115 constrains = 'constrains'116 descriptor = 'an-options'117 stem = 'options="%s"' % descriptor118 joiner = '%s] option,[' % stem119 criteria = '[' + joiner.join(self.ng_prefixes) + stem + '] option'120 tag = 'tag'121 self.finder._find_by_ng_options(self.driver, descriptor, tag, constrains)122 self.finder._find_by_css_selector.assert_called_with(self.driver,123 criteria, tag,...
element_methods.py
Source:element_methods.py
...39 return prefix40 def _find_by_xpath(self, criteria):41 return WebDriverWait(self._driver, constant.SEL_TIMEOUT).until(42 EC.presence_of_element_located((By.XPATH, criteria)))43 def _find_by_css_selector(self, criteria):44 return WebDriverWait(self._driver, constants.SEL_TIMEOUT).until(45 EC.presence_of_element_located((By.CSS_SELECTOR, criteria)))46 def click(self):47 self.wait_for_clickable()48 self._element.click()49 logging.info("Clicked element successfully " + str(self.__locator))50 def send_keys(self, *value):51 self._element.send_keys(value)52 logging.info("Send keys successfully " + str(self.__locator) + ". Key = " + str(value))53 def switch_to_iframe(self):54 self._driver.switch_to.frame(self.find_element())55 def switch_to_default_iframe(self):56 self._driver.switch_to.default_content()57 def send_keys_action(self, key_value):...
_elementfinder.py
Source:_elementfinder.py
...50 def _find_by_ios(self, driver, criteria): # new UiSelector()51 return driver.find_element_by_ios_uiautomation(criteria)52 def _find_element_by_accessibility_id(self, driver, criteria):53 return driver.find_element_by_accessibility_id(criteria)54 def _find_by_css_selector(self, driver, criteria):55 return driver.find_elements_by_css_selector(criteria)56 def _find_by_sizzle_selector(self, driver, criteria):57 js = "return jQuery('%s').get();" % criteria.replace("'", "\\'")...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!