From 24182fadb8cb6914b5538fd32b0ad9d8a34c710c Mon Sep 17 00:00:00 2001 From: serhatbolsu Date: Sun, 16 Oct 2016 14:03:26 +0300 Subject: [PATCH 1/4] `Click Text` with unicode and better handling for ios --- src/AppiumLibrary/keywords/_element.py | 32 ++++++++++++++++---------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/AppiumLibrary/keywords/_element.py b/src/AppiumLibrary/keywords/_element.py index d2d95fd3..0584fb2d 100644 --- a/src/AppiumLibrary/keywords/_element.py +++ b/src/AppiumLibrary/keywords/_element.py @@ -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: @@ -55,20 +55,28 @@ 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': + try: + self._element_find(text, True, True).click() + except ValueError: + if exact_match: + _text = normalize('NFD', text) + _xpath = u'//*[@value="{}" or @label="{}"]'.format(_text, _text) + else: + _text = normalize('NFD', text) + _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`. From bc392a95304da388ce4b8092a3f7ed5aedf13644 Mon Sep 17 00:00:00 2001 From: serhatbolsu Date: Sun, 16 Oct 2016 14:11:30 +0300 Subject: [PATCH 2/4] Unicode support as normalization for all element methods, as suggested by Appium --- src/AppiumLibrary/keywords/_element.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/AppiumLibrary/keywords/_element.py b/src/AppiumLibrary/keywords/_element.py index 0584fb2d..58f186c1 100644 --- a/src/AppiumLibrary/keywords/_element.py +++ b/src/AppiumLibrary/keywords/_element.py @@ -61,9 +61,10 @@ def click_text(self, text, exact_match=False): New in AppiumLibrary 1.4. """ if self._get_platform() == 'ios': - try: - self._element_find(text, True, True).click() - except ValueError: + element = self._element_find(text, True, False) + if element: + element.click() + else: if exact_match: _text = normalize('NFD', text) _xpath = u'//*[@value="{}" or @label="{}"]'.format(_text, _text) @@ -556,7 +557,9 @@ 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 + _locator = normalize('NFD', 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: @@ -575,10 +578,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): From 65e9a4114e05a4a59642ab56fdd7dbcba060d576 Mon Sep 17 00:00:00 2001 From: serhatbolsu Date: Wed, 26 Oct 2016 16:30:40 +0300 Subject: [PATCH 3/4] Android does not need normalization --- src/AppiumLibrary/keywords/_element.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/AppiumLibrary/keywords/_element.py b/src/AppiumLibrary/keywords/_element.py index 58f186c1..e9f210a0 100644 --- a/src/AppiumLibrary/keywords/_element.py +++ b/src/AppiumLibrary/keywords/_element.py @@ -66,11 +66,9 @@ def click_text(self, text, exact_match=False): element.click() else: if exact_match: - _text = normalize('NFD', text) - _xpath = u'//*[@value="{}" or @label="{}"]'.format(_text, _text) + _xpath = u'//*[@value="{}" or @label="{}"]'.format(text, text) else: - _text = normalize('NFD', text) - _xpath = u'//*[contains(@label,"{}") or contains(@value, "{}")]'.format(_text, _text) + _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: @@ -558,7 +556,10 @@ def _element_find(self, locator, first_only, required, tag=None): application = self._current_application() if isstr(locator): # Normalize any unicode as explained here, http://appium.io/slate/en/master/?javascript#multi-lingual-support - _locator = normalize('NFD', locator) + 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.") From 0e37a03711fb38b8df8c1e52f160fa6c28fc77e8 Mon Sep 17 00:00:00 2001 From: serhatbolsu Date: Wed, 26 Oct 2016 16:37:41 +0300 Subject: [PATCH 4/4] Version bump --- CHANGES.rst | 14 ++++++++++++++ src/AppiumLibrary/version.py | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index b3735dd6..9e73caa8 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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 diff --git a/src/AppiumLibrary/version.py b/src/AppiumLibrary/version.py index 16557e39..453ea502 100644 --- a/src/AppiumLibrary/version.py +++ b/src/AppiumLibrary/version.py @@ -1,3 +1,3 @@ # -*- coding: utf-8 -*- -VERSION = '1.4.0.1' +VERSION = '1.4.1'