How to use _is_text_present method in robotframework-appiumlibrary

Best Python code snippet using robotframework-appiumlibrary_python

AssertElement.py

Source:AssertElement.py Github

copy

Full Screen

...158 log.mjLog.LogReporter("AssertElement","debug","Element contains exact text: %s => %s" % (locator,actual))159 def current_frame_contains_text(self, text):160 """Verifies that current frame contains `text`.161 """162 if not self._is_text_present(text):163 log.mjLog.LogReporter("AssertElement","error","Frame should have contained text '%s' "164 "but did not" % text)165 raise AssertionError("Frame should have contained text '%s' "166 "but did not" % text)167 log.mjLog.LogReporter("AssertElement","debug","Current Frame contains text '%s'." % text)168 169 def current_frame_should_not_contain_text(self, text):170 """Verifies that current frame contains `text`.171 """172 if self._is_text_present(text):173 log.mjLog.LogReporter("AssertElement","error","Frame should not have contained text '%s' "174 "but did contain" % text)175 raise AssertionError("Frame should not have contained text '%s' "176 "but it did" % text)177 log.mjLog.LogReporter("AssertElement","debug","Current Frame does not contains text '%s'." % text)178 def verify_element_color(self, locator, expectedColor):179 """180 Verifies element color181 """182 pass183 184 def verify_text_in_dropdown(self, textList, valueToVerify):185 ''' Verifies the value identified by valueToVerify is present in list identified by textList186 187 '''188 try:189 count = 0190 for text in textList:191 if text == valueToVerify:192 count = count +1193 log.mjLog.LogReporter("AssertElement", "info", "verify_text_in_dropdown"194 " - "+valueToVerify+" is present in list")195 break196 if count == 0:197 log.mjLog.LogReporter("AssertElement", "error", "%s is not present in list" % valueToVerify)198 199 except:200 raise AssertionError("Error in verify_text_in_dropdown "+str(sys.exc_info()))201 def values_should_not_be_equal(self, actualValue, expectedValue):202 """Verifies that actualValue is not equal to expectedValue203 """204 if actualValue == expectedValue:205 raise AssertionError("Actual value and Expected Values are equal")206 log.mjLog.LogReporter("AssertElement","debug"," Actual value is not equal to Expected Value")207 def page_should_not_contain_javascript_errors(self):208 """209 `Description;` Verifies the current page does not contain JavaScript errors.210 `Param:` None211 `Returns:` status - True/False212 `Created by:` Jim Wendt213 """214 error_recap = []215 keep_phrases = [216 '"description": "EvalError',217 '"description": "InternalError',218 '"description": "RangeError',219 '"description": "ReferenceError',220 '"description": "SyntaxError',221 '"description": "TypeError',222 '"description": "URIError',223 '"description": "ReferenceError',224 '"description": "DOMException'225 ]226 status = False227 if self._browser.console_log:228 for line in self._browser.console_log:229 for phrase in keep_phrases:230 if phrase in line:231 line = line.replace("\"description\": ", "")232 line = line.replace("\\n", "").strip()233 line = re.sub("\s+", " ", line)234 line = line[1:-2]235 if not line in error_recap:236 error_recap.append(line)237 if len(error_recap):238 for line in error_recap:239 log.mjLog.LogReporter("AssertElement", "error", line)240 log.mjLog.LogReporter("AssertElement", "error", "Page Contains JavaScript Errors")241 self._browser.console_log.truncate()242 raise AssertionError()243 return status244 else:245 status = True246 return status247 else:248 raise AssertionError("Unable to Validate Javascript Errors")249 log.mjLog.LogReporter("AssertElement", "debug", "Unable to Validate Javascript Errors")250 return status251 #private methods252 def _element_finder(self, locator):253 '''254 _element_finder() - Method to invoke element_finder from browser class255 '''256 return self._browser.element_finder(locator)257 258 def _get_browser_driver(self):259 return self._browser.get_current_browser()260 261 def _frame_contains(self, locator, text):262 self._driver = self._get_browser_driver()263 element = self._element_finder(locator)264 265 self._driver.switch_to_frame(element)266 found = self._is_text_present(text)267 self._driver.switch_to_default_content()268 return found269 def _get_text(self, locator):270 element = self._element_finder(locator)271 if element is not None:272 return element.text273 return None274 def _is_text_present(self, text):275 locator = "//*[contains(., '%s')]" % (text);276 return self._is_element_contains(locator)277 def _is_element_present(self, locator):278 return self._element_finder(locator)279 280 def _is_element_contains(self, locator):281 self._driver = self._browser.get_current_browser()282 return self._driver.find_elements_by_xpath(locator) 283 def _page_contains(self, text):284 self._driver = self._get_browser_driver()285 self._driver.switch_to_default_content()286 if self._is_text_present(text):287 return True288 subframes = self._element_finder("xpath=//frame|//iframe")289 if subframes:290 for frame in subframes:291 self._driver.switch_to_frame(frame)292 found_text = self._is_text_present(text)293 self._driver.switch_to_default_content()294 if found_text:295 return True296 return False297 def _page_should_contain_element(self, locator):298 return self._is_element_present(locator)299 300 def _get_value(self, locator, tag=None):301 element = self._element_finder(locator, True, False, tag=tag)302 return element.get_attribute('value') if element is not None else None303 def _is_enabled(self, locator):304 element = self._element_finder(locator)305 if not element.is_enabled():306 return False...

Full Screen

Full Screen

test_functional.py

Source:test_functional.py Github

copy

Full Screen

...16 self.selenium.quit()17 # Auxiliary function to add view subdir to URL18 def _get_full_url(self, namespace):19 return self.live_server_url + namespace20 def _is_text_present(self, text):21 try:22 body = self.selenium.find_element_by_tag_name("body")23 except NoSuchElementException, e:24 return False25 return text in body.text # check if the text is in body's text26 def test_home_title(self):27 """28 Tests that Home is loading properly29 """30 self.selenium.get(self._get_full_url("/"))31 self.assertIn(u'Metadata Explorer Tool', self.selenium.title)32 def test_home_sections(self):33 """34 Tests that Home is showing the right sections35 """36 self.selenium.get(self._get_full_url("/"))...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run robotframework-appiumlibrary automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful