Skip to content

Commit

Permalink
Merge pull request #140 from serhatbolsu/feature/unicode-handling
Browse files Browse the repository at this point in the history
Feature/unicode handling
  • Loading branch information
serhatbolsu authored Oct 26, 2016
2 parents 1c2af11 + 0e37a03 commit c50feab
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 18 deletions.
14 changes: 14 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
History
=======
1.4.1
----------------
- Unicode better support
- Unicode supported now inside xpath text.
- Click Text iOS handling is much better now. Works regardless if text is name, value or label

1.4.0
----------------
- New finding elements strategy now supports directly using WebElement. Check keyword documentation for more information.
- Added default locator strategies. Default is: id and xpath check library introduction for more details.
- Click Text added as keyword in which you can directly click on found texts. Underlying it works on predefined xpath depending on platform.
- Unicode fixes also reflected on Page Should Contain Text and Page Should Not Contain Text
- Getting an element text is added and its helper keywords.

1.3.7
----------------
- ``swipe`` critical bug fix <https://github.com/jollychang/robotframework-appiumlibrary/pull/125>
Expand Down
44 changes: 27 additions & 17 deletions src/AppiumLibrary/keywords/_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from .keywordgroup import KeywordGroup
from robot.libraries.BuiltIn import BuiltIn
import ast
import unicodedata
from unicodedata import normalize
from selenium.webdriver.remote.webelement import WebElement

try:
Expand Down Expand Up @@ -55,20 +55,27 @@ def click_text(self, text, exact_match=False):
By default tries to click first text involves given ``text``, if you would
like to click exactly matching text, then set ``exact_match`` to `True`.
If there are multiple use of ``text`` use `locator` with `Get Web Elements` instead.
If there are multiple use of ``text`` and you do not want first one,
use `locator` with `Get Web Elements` instead.
New in AppiumLibrary 1.4.
"""
_platform_class_dict = {'ios': 'name', 'android': 'text'}
if exact_match:
_xpath = u'//*[@{}="{}"]'.format(
_platform_class_dict.get(self._get_platform()),
text)
else:
_xpath = u'//*[contains(@{},"{}")]'.format(
_platform_class_dict.get(self._get_platform()),
text)
self._element_find(_xpath, True, True).click()
if self._get_platform() == 'ios':
element = self._element_find(text, True, False)
if element:
element.click()
else:
if exact_match:
_xpath = u'//*[@value="{}" or @label="{}"]'.format(text, text)
else:
_xpath = u'//*[contains(@label,"{}") or contains(@value, "{}")]'.format(text, text)
self._element_find(_xpath, True, True).click()
elif self._get_platform() == 'android':
if exact_match:
_xpath = u'//*[@{}="{}"]'.format('text', text)
else:
_xpath = u'//*[contains(@{},"{}")]'.format('text', text)
self._element_find(_xpath, True, True).click()

def input_text(self, locator, text):
"""Types the given `text` into text field identified by `locator`.
Expand Down Expand Up @@ -548,7 +555,12 @@ def _element_input_value_by_locator(self, locator, text):
def _element_find(self, locator, first_only, required, tag=None):
application = self._current_application()
if isstr(locator):
elements = self._element_finder.find(application, locator, tag)
# Normalize any unicode as explained here, http://appium.io/slate/en/master/?javascript#multi-lingual-support
if self._get_platform() == 'ios':
_locator = normalize('NFD', locator)
else:
_locator = locator
elements = self._element_finder.find(application, _locator, tag)
if required and len(elements) == 0:
raise ValueError("Element locator '" + locator + "' did not match any elements.")
if first_only:
Expand All @@ -567,10 +579,8 @@ def _get_text(self, locator):
return None

def _is_text_present(self, text):
text_norm = unicodedata.normalize(
'NFD', text).encode('ascii', 'ignore')
source_norm = unicodedata.normalize(
'NFD', self.get_source()).encode('ascii', 'ignore')
text_norm = normalize('NFD', text).encode('ascii', 'ignore')
source_norm = normalize('NFD', self.get_source()).encode('ascii', 'ignore')
return text_norm in source_norm

def _is_element_present(self, locator):
Expand Down
2 changes: 1 addition & 1 deletion src/AppiumLibrary/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# -*- coding: utf-8 -*-

VERSION = '1.4.0.1'
VERSION = '1.4.1'

0 comments on commit c50feab

Please sign in to comment.