How to use is_noney method in SeleniumLibrary

Best Python code snippet using SeleniumLibrary

element.py

Source:element.py Github

copy

Full Screen

...55 if is_truthy(ignore_case):56 actual = actual.lower()57 expected = expected.lower()58 if expected not in actual:59 if is_noney(message):60 message = "Element '%s' should have contained text '%s' but "\61 "its text was '%s'." % (locator, expected_before, actual_before)62 raise AssertionError(message)63 self.info("Element '%s' contains text '%s'." % (locator, expected_before))64 @keyword65 def element_should_not_contain(self, locator, expected, message=None, ignore_case=False ):66 """Verifies that element ``locator`` does not contains text ``expected``.67 See the `Locating elements` section for details about the locator68 syntax.69 The ``message`` argument can be used to override the default error70 message.71 The ``ignore_case`` argument can be set to True to compare case72 insensitive, default is False.73 ``ignore_case`` argument new in SeleniumLibrary 3.1.74 """75 actual = self.find_element(locator).text76 expected_before = expected77 if is_truthy(ignore_case):78 actual = actual.lower()79 expected = expected.lower()80 if expected in actual:81 if is_noney(message):82 message = "Element '%s' should not contain text '%s' but " \83 "it did." % (locator, expected_before)84 raise AssertionError(message)85 self.info("Element '%s' does not contain text '%s'."86 % (locator, expected_before))87 @keyword88 def page_should_contain(self, text, loglevel='INFO'):89 """Verifies that current page contains ``text``.90 If this keyword fails, it automatically logs the page source91 using the log level specified with the optional ``loglevel``92 argument. Valid log levels are ``DEBUG``, ``INFO`` (default),93 ``WARN``, and ``NONE``. If the log level is ``NONE`` or below94 the current active log level the source will not be logged.95 """96 if not self._page_contains(text):97 self.ctx.log_source(loglevel)98 raise AssertionError("Page should have contained text '%s' "99 "but did not." % text)100 self.info("Current page contains text '%s'." % text)101 @keyword102 def page_should_contain_element(self, locator, message=None,103 loglevel='INFO', limit=None):104 """Verifies that element ``locator`` is found on the current page.105 See the `Locating elements` section for details about the locator106 syntax.107 The ``message`` argument can be used to override the default error108 message.109 The ``limit`` argument can used to define how many elements the110 page should contain. When ``limit`` is ``None`` (default) page can111 contain one or more elements. When limit is a number, page must112 contain same number of elements.113 See `Page Should Contain` for explanation about the ``loglevel``114 argument.115 Examples assumes that locator matches to two elements.116 | `Page Should Contain Element` | div_name | limit=1 | # Keyword fails. |117 | `Page Should Contain Element` | div_name | limit=2 | # Keyword passes. |118 | `Page Should Contain Element` | div_name | limit=none | # None is considered one or more. |119 | `Page Should Contain Element` | div_name | | # Same as above. |120 The ``limit`` argument is new in SeleniumLibrary 3.0.121 """122 if is_noney(limit):123 return self.assert_page_contains(locator, message=message,124 loglevel=loglevel)125 limit = int(limit)126 count = len(self.find_elements(locator))127 if count == limit:128 self.info('Current page contains {} element(s).'.format(count))129 else:130 if is_noney(message):131 message = ('Page should have contained "{}" element(s), '132 'but it did contain "{}" element(s).'133 .format(limit, count))134 self.ctx.log_source(loglevel)135 raise AssertionError(message)136 @keyword137 def locator_should_match_x_times(self, locator, x, message=None, loglevel='INFO'):138 """Deprecated, use `Page Should Contain Element` with ``limit`` argument instead."""139 count = len(self.find_elements(locator))140 x = int(x)141 if count != x:142 if is_falsy(message):143 message = ("Locator '%s' should have matched %s time%s but "144 "matched %s time%s."145 % (locator, x, s(x), count, s(count)))146 self.ctx.log_source(loglevel)147 raise AssertionError(message)148 self.info("Current page contains %s elements matching '%s'."149 % (count, locator))150 @keyword151 def page_should_not_contain(self, text, loglevel='INFO'):152 """Verifies the current page does not contain ``text``.153 See `Page Should Contain` for explanation about the ``loglevel``154 argument.155 """156 if self._page_contains(text):157 self.ctx.log_source(loglevel)158 raise AssertionError("Page should not have contained text '%s'."159 % text)160 self.info("Current page does not contain text '%s'." % text)161 @keyword162 def page_should_not_contain_element(self, locator, message=None, loglevel='INFO'):163 """Verifies that element ``locator`` is found on the current page.164 See the `Locating elements` section for details about the locator165 syntax.166 See `Page Should Contain` for explanation about ``message`` and167 ``loglevel`` arguments.168 """169 self.assert_page_not_contains(locator, message=message,170 loglevel=loglevel)171 @keyword172 def assign_id_to_element(self, locator, id):173 """Assigns temporary ``id`` to element specified by ``locator``.174 This is mainly useful if the locator is complicated and/or slow XPath175 expression and it is needed multiple times. Identifier expires when176 the page is reloaded.177 See the `Locating elements` section for details about the locator178 syntax.179 Example:180 | `Assign ID to Element` | //ul[@class='example' and ./li[contains(., 'Stuff')]] | my id |181 | `Page Should Contain Element` | my id |182 """183 self.info("Assigning temporary id '%s' to element '%s'." % (id, locator))184 element = self.find_element(locator)185 self.driver.execute_script("arguments[0].id = '%s';" % id, element)186 @keyword187 def element_should_be_disabled(self, locator):188 """Verifies that element identified with ``locator`` is disabled.189 This keyword considers also elements that are read-only to be190 disabled.191 See the `Locating elements` section for details about the locator192 syntax.193 """194 if self.is_element_enabled(locator):195 raise AssertionError("Element '%s' is enabled." % locator)196 @keyword197 def element_should_be_enabled(self, locator):198 """Verifies that element identified with ``locator`` is enabled.199 This keyword considers also elements that are read-only to be200 disabled.201 See the `Locating elements` section for details about the locator202 syntax.203 """204 if not self.is_element_enabled(locator):205 raise AssertionError("Element '%s' is disabled." % locator)206 @keyword207 def element_should_be_focused(self, locator):208 """Verifies that element identified with ``locator`` is focused.209 See the `Locating elements` section for details about the locator210 syntax.211 New in SeleniumLibrary 3.0.212 """213 element = self.find_element(locator)214 focused = self.driver.switch_to.active_element215 # Selenium 3.6.0 with Firefox return dict wich contains the selenium WebElement216 if isinstance(focused, dict):217 focused = focused['value']218 if element != focused:219 raise AssertionError("Element '%s' does not have focus." % locator)220 @keyword221 def element_should_be_visible(self, locator, message=None):222 """Verifies that the element identified by ``locator`` is visible.223 Herein, visible means that the element is logically visible, not224 optically visible in the current browser viewport. For example,225 an element that carries ``display:none`` is not logically visible,226 so using this keyword on that element would fail.227 See the `Locating elements` section for details about the locator228 syntax.229 The ``message`` argument can be used to override the default error230 message.231 """232 if not self.find_element(locator).is_displayed():233 if is_noney(message):234 message = ("The element '%s' should be visible, but it "235 "is not." % locator)236 raise AssertionError(message)237 self.info("Element '%s' is displayed." % locator)238 @keyword239 def element_should_not_be_visible(self, locator, message=None):240 """Verifies that the element identified by ``locator`` is NOT visible.241 Passes if element does not exists. See `Element Should Be Visible`242 for more information about visibility and supported arguments.243 """244 element = self.find_element(locator, required=False)245 if element is None:246 self.info("Element '%s' did not exist." % locator)247 elif not element.is_displayed():248 self.info("Element '%s' exists but is not displayed." % locator)249 else:250 if is_noney(message):251 message = ("The element '%s' should not be visible, "252 "but it is." % locator)253 raise AssertionError(message)254 @keyword255 def element_text_should_be(self, locator, expected, message=None, ignore_case=False):256 """Verifies that element ``locator`` contains exact text ``expected``.257 See the `Locating elements` section for details about the locator258 syntax.259 The ``message`` argument can be used to override the default error260 message.261 The ``ignore_case`` argument can be set to True to compare case262 insensitive, default is False.263 ``ignore_case`` argument new in SeleniumLibrary 3.1.264 Use `Element Should Contain` if a substring match is desired.265 """266 self.info("Verifying element '%s' contains exact text '%s'."267 % (locator, expected))268 text = before_text = self.find_element(locator).text269 if is_truthy(ignore_case):270 text = text.lower()271 expected = expected.lower()272 if text != expected:273 if is_noney(message):274 message = ("The text of element '%s' should have been '%s' "275 "but it was '%s'."276 % (locator, expected, before_text))277 raise AssertionError(message)278 @keyword279 def element_text_should_not_be(self, locator, not_expected, message=None, ignore_case=False):280 """Verifies that element ``locator`` does not contain exact text ``not_expected``.281 See the `Locating elements` section for details about the locator282 syntax.283 The ``message`` argument can be used to override the default error284 message.285 The ``ignore_case`` argument can be set to True to compare case286 insensitive, default is False.287 New in SeleniumLibrary 3.1.1288 """289 self.info("Verifying element '%s' does not contains exact text '%s'."290 % (locator, not_expected))291 text = self.find_element(locator).text292 before_not_expected = not_expected293 if is_truthy(ignore_case):294 text = text.lower()295 not_expected = not_expected.lower()296 if text == not_expected:297 if is_noney(message):298 message = ("The text of element '%s' was not supposed to be '%s'."299 % (locator, before_not_expected))300 raise AssertionError(message)301 @keyword302 def get_element_attribute(self, locator, attribute=None):303 """Returns value of ``attribute`` from element ``locator``.304 See the `Locating elements` section for details about the locator305 syntax.306 Example:307 | ${id}= | `Get Element Attribute` | css:h1 | id |308 Passing attribute name as part of the ``locator`` is deprecated309 since SeleniumLibrary 3.0. The explicit ``attribute`` argument310 should be used instead.311 """312 if is_noney(attribute):313 self.warn("Using 'Get Element Attribute' without explicit "314 "attribute is deprecated.")315 locator, attribute = locator.rsplit('@', 1)316 return self.find_element(locator).get_attribute(attribute)317 @keyword318 def get_horizontal_position(self, locator):319 """Returns horizontal position of element identified by ``locator``.320 See the `Locating elements` section for details about the locator321 syntax.322 The position is returned in pixels off the left side of the page,323 as an integer.324 See also `Get Vertical Position`.325 """326 return self.find_element(locator).location['x']...

Full Screen

Full Screen

librarycomponent.py

Source:librarycomponent.py Github

copy

Full Screen

...14 logger.info(msg, html)15 def debug(self, msg, html=False):16 logger.debug(msg, html)17 def log(self, msg, level='INFO', html=False):18 if not is_noney(level):19 logger.write(msg, level.upper(), html)20 def warn(self, msg, html=False):21 logger.warn(msg, html)22 def log_source(self, loglevel='INFO'):23 self.ctx.log_source(loglevel)24 def get_timeout(self, timeout=None):25 if is_noney(timeout):26 return self.ctx.timeout27 return timestr_to_secs(timeout)28 @property29 def log_dir(self):30 try:31 logfile = BuiltIn().get_variable_value('${LOG FILE}')32 if logfile == 'NONE':33 return BuiltIn().get_variable_value('${OUTPUTDIR}')34 return os.path.dirname(logfile)35 except RobotNotRunningError:...

Full Screen

Full Screen

test_types.py

Source:test_types.py Github

copy

Full Screen

...21 for item in self.truthy:22 self.assertTrue(is_falsy(item) is False)23 for item in self.falsy:24 self.assertTrue(is_falsy(item) is True)25 def test_is_noney(self):26 for item in [None, 'None', 'NONE', 'none']:27 self.assertTrue(is_noney(item) is True)28 for item in self.truthy + [False, 0, 'False', '', [], {}, ()]:...

Full Screen

Full Screen

logger.py

Source:logger.py Github

copy

Full Screen

...4 logger.info(msg, html)5def debug(msg, html=False):6 logger.debug(msg, html)7def log(msg, level='INFO', html=False):8 if not is_noney(level):9 logger.write(msg, level.upper(), html)10def warn(msg, html=False):...

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 SeleniumLibrary 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