How to use get_normalized_logging_levels method in robotframework-pageobjects

Best Python code snippet using robotframework-pageobjects_python

test_unit.py

Source:test_unit.py Github

copy

Full Screen

1import inspect2import os3import sys4from nose.tools import raises5from mock import patch6from robot.libraries.BuiltIn import BuiltIn7from unittest import skipUnless8import selenium9from selenium import webdriver10from basetestcase import BaseTestCase11from robotpageobjects import exceptions12from robotpageobjects.page import Page, _Keywords, Override, not_keyword13from robotpageobjects.optionhandler import OptionHandler14test_dir = os.path.dirname(os.path.realpath(__file__))15scenario_dir = os.path.join(test_dir, "scenarios")16po_dir = os.path.join(scenario_dir, "po")17sys.path.append(po_dir)18from basepageobjects import BaseHomePage, BaseResultsPage19class InheritFromSe2LibTestCase(BaseTestCase):20 def setUp(self):21 super(InheritFromSe2LibTestCase, self).setUp()22 class PO(Page):23 pass24 self.po = PO()25 def test_no_robot_se2lib_exposed(self):26 # We can't test this as a unittest in27 # robot, so see functional test class.28 try:29 getattr(self.po, "title_should_be")30 except AttributeError:31 self.fail("SE2Lib methods are not exposed as direct page object attributes")32class MockPage(object):33 pass34class OptionHandlerTestCase(BaseTestCase):35 path_to_var_file = os.path.join(BaseTestCase.test_dir, "vars.py")36 def test_is_singleton(self):37 ids = []38 for i in range(3):39 ids.append(id(OptionHandler(MockPage())))40 self.assertTrue(all(x == ids[0] for x in ids), "All OptionHandler instances should refer to the same instance")41 def test_no_robot_get_env_var(self):42 os.environ["PO_FOO"] = "bar"43 handler = OptionHandler(MockPage())44 self.assertEquals(handler.get("foo"), "bar")45 def test_no_robot_env_not_set_is_none(self):46 handler = OptionHandler(MockPage())47 self.assertIsNone(handler.get("fasdfasdfasdfsadf"))48 @skipUnless(os.name == "posix", "Skipping Windows, since environment variables are not case sensitive")49 def test_no_robot_ignore_lowercase_env_vars(self):50 os.environ["PO_BROWSEr"] = "firefox"51 handler = OptionHandler(MockPage())52 self.assertIsNone(handler.get("browser"), "Mixed case environment variables should not be set")53 @raises(exceptions.VarFileImportErrorError)54 def test_var_file_import_exception(self):55 os.environ["PO_VAR_FILE"] = "foo/bar/asdfsadf/asdf"56 handler = OptionHandler(MockPage())57 handler.get("PO_VAR_FILE")58 def test_no_robot_var_file(self):59 os.environ["PO_VAR_FILE"] = self.path_to_var_file60 handler = OptionHandler(MockPage())61 self.assertEquals(handler.get("author"), "Dickens")62 self.assertEquals(handler.get("dynamic"), "Python")63 @patch.object(BuiltIn, "get_variables")64 def test_robot(self, mock_get_variables):65 mock_get_variables.return_value = {"${browser}": "foobar"}66 handler = OptionHandler(MockPage())67 self.assertEquals(handler.get("browser"), "foobar")68 @patch.object(BuiltIn, "get_variables")69 def test_robot_can_get_vars_from_env(self, mock_get_variables):70 os.environ["PO_BROWSER"] = "opera"71 try:72 handler = OptionHandler(MockPage())73 self.assertEquals(handler.get("browser"), "opera")74 except Exception, e:75 raise e76 finally:77 del os.environ["PO_BROWSER"]78 @patch.object(BuiltIn, "get_variables")79 def test_robot_env_overrides_var_file(self, mock_get_variables):80 os.environ["PO_AUTHOR"] = "Twain"81 os.environ["PO_VAR_FILE"] = self.path_to_var_file82 try:83 handler = OptionHandler(MockPage())84 self.assertEquals(handler.get("author"), "Twain")85 except Exception, e:86 raise e87 finally:88 del os.environ["PO_AUTHOR"]89 del os.environ["PO_VAR_FILE"]90 @patch.object(BuiltIn, "get_variables")91 def test_robot_cmd_line_var_overrides_env_var(self, mock_get_variables):92 os.environ["PO_BROWSER"] = "firefox"93 mock_get_variables.return_value = {"${browser}": "chrome"}94 try:95 handler = OptionHandler(MockPage())96 self.assertEquals(handler.get("browser"), "chrome")97 except Exception, e:98 raise e99 finally:100 del os.environ["PO_BROWSER"]101 @patch.object(BuiltIn, "get_variables")102 def test_robot_cmd_line_var_overrides_var_file(self, mock_get_variables):103 mock_get_variables.return_value = {"${author}": "Twain"}104 os.environ["PO_VAR_FILE"] = self.path_to_var_file105 try:106 handler = OptionHandler(MockPage())107 self.assertEquals(handler.get("author"), "Twain")108 except Exception, e:109 raise e110 finally:111 del os.environ["PO_VAR_FILE"]112 113 def test_get_options_from_page_object(self):114 p = MockPage()115 p.options = {'author': 'Twain'}116 handler = OptionHandler(p)117 self.assertEquals(handler.get("author"), "Twain")118class SauceTestCase(BaseTestCase):119 def setUp(self):120 super(SauceTestCase, self).setUp()121 class PO(Page):122 pass123 self.PO = PO124 @raises(exceptions.MissingSauceOptionError)125 def test_missing_sauce_apikey_should_raise_missing_sauce_option_error(self):126 self.set_baseurl_env(base_file=False, arbitrary_base="http://www.ncbi.nlm.nih.gov")127 os.environ["PO_SAUCE_PLATFORM"] = "Windows 8.1"128 os.environ["PO_SAUCE_USERNAME"] = "abc"129 self.PO.uri = "/foo"130 self.PO()131 @raises(exceptions.MissingSauceOptionError)132 def test_missing_sauce_username_should_raise_missing_sauce_option_error(self):133 self.set_baseurl_env(base_file=False, arbitrary_base="http://www.ncbi.nlm.nih.gov")134 os.environ["PO_SAUCE_PLATFORM"] = "Windows 8.1"135 os.environ["PO_SAUCE_APIKEY"] = "abc"136 self.PO.uri = "/foo"137 self.PO()138 @raises(exceptions.MissingSauceOptionError)139 def test_missing_sauce_platform_should_raise_missing_sauce_option_error(self):140 self.set_baseurl_env(base_file=False, arbitrary_base="http://www.ncbi.nlm.nih.gov")141 os.environ["PO_BROWSER"] = "Firefox"142 os.environ["PO_SAUCE_BROWSERVERSION"] = "37"143 os.environ["PO_SAUCE_USERNAME"] = "abc"144 os.environ["PO_SAUCE_APIKEY"] = "abc"145 self.PO.uri = "/foo"146 self.PO()147 @raises(exceptions.SauceConnectionError)148 def test_sauce_connection_error(self):149 self.set_baseurl_env(base_file=False, arbitrary_base="http://www.ncbi.nlm.nih.gov")150 os.environ["PO_BROWSER"] = "Firefox"151 os.environ["PO_SAUCE_BROWSERVERSION"] = "27"152 os.environ["PO_SAUCE_USERNAME"] = "foo"153 os.environ["PO_SAUCE_APIKEY"] = "bar"154 os.environ["PO_SAUCE_PLATFORM"] = "Windows 8.1"155 self.PO.uri = "/foo"156 p = self.PO()157 p.open()158 @skipUnless(BaseTestCase.are_sauce_creds_set_for_testing(),159 "SAUCE_USERNAME and SAUCE_APIKEY env vars must be set to test")160 @raises(selenium.common.exceptions.WebDriverException)161 def test_sauce_invalid_browser(self):162 self.set_baseurl_env(base_file=False, arbitrary_base="http://www.ncbi.nlm.nih.gov")163 os.environ["PO_BROWSER"] = "Firefox"164 os.environ["PO_SAUCE_BROWSERVERSION"] = "27"165 username, apikey = self.get_sauce_creds()166 os.environ["PO_SAUCE_USERNAME"] = username167 os.environ["PO_SAUCE_APIKEY"] = apikey168 os.environ["PO_SAUCE_PLATFORM"] = "Winows 8.1"169 self.PO.uri = "/foo"170 p = self.PO()171 p.open()172class ResolveUrlTestCase(BaseTestCase):173 def setUp(self):174 super(ResolveUrlTestCase, self).setUp()175 class PO(Page):176 pass177 self.PO = PO178 ### Exceptions ###179 @raises(exceptions.UriResolutionError)180 def test_no_baseurl_set_and_no_uri_attr_set(self):181 """No baseurl is set, and there is no "uri" set in the PO."""182 self.PO()._resolve_url()183 @raises(exceptions.UriResolutionError)184 def test_no_baseurl_set_and_no_uri_attr_set_and_uri_vars_set(self):185 """No baseurl is set, and there is no "uri" set in the PO,186 and a variable was passed in."""187 self.PO()._resolve_url("bar")188 @raises(exceptions.UriResolutionError)189 def test_no_baseurl_set_and_uri_attr_set_and_uri_vars_set(self):190 """No baseurl is set. A uri is set, but a variable was passed in."""191 self.PO.uri = "/foo"192 self.PO()._resolve_url("bar")193 @raises(exceptions.UriResolutionError)194 def test_baseurl_set_abs_uri_attr(self):195 """An absolute url (with scheme) was set as the uri."""196 self.set_baseurl_env()197 self.PO.uri = "http://www.example.com"198 self.PO()._resolve_url()199 @raises(exceptions.UriResolutionError)200 def test_baseurl_set_and_abs_uri_template(self):201 """An absolute uri template was set."""202 self.set_baseurl_env()203 self.PO.uri_template = "http://www.ncbi.nlm.nih.gov/pubmed/{pid}"204 self.PO()._resolve_url({"pid": "123"})205 @raises(exceptions.UriResolutionError)206 def test_bad_vars_passed_to_uri_template(self):207 """The variable names passed in do not match the template."""208 self.set_baseurl_env(base_file=False, arbitrary_base="http://www.ncbi.nlm.nih.gov")209 self.PO.uri_template = "/pubmed/{pid}"210 self.PO()._resolve_url({"foo": "bar"})211 @raises(exceptions.UriResolutionError)212 def test_too_many_vars_passed_to_uri_template_in_robot(self):213 self.set_baseurl_env()214 self.PO.uri_template = "/pubmed/{pid}"215 po = self.PO()216 po._is_robot = True217 po._resolve_url("pid=foo", "bar=baz")218 @raises(exceptions.UriResolutionError)219 def test_no_vars_passed_to_uri_template(self):220 """There is a template but no variables are possed in."""221 self.set_baseurl_env(base_file=False, arbitrary_base="http://www.ncbi.nlm.nih.gov")222 self.PO.uri_template = "/pubmed/{pid}"223 self.PO()._resolve_url()224 @raises(exceptions.UriResolutionError)225 def test_wrong_var_name_in_robot(self):226 self.set_baseurl_env()227 self.PO.uri_template = "/pubmed/{pid}"228 po = self.PO()229 po._is_robot = True230 po._resolve_url("foo=bar")231 @raises(exceptions.UriResolutionError)232 def test_names_not_provided_in_robot(self):233 self.set_baseurl_env()234 self.PO.uri_template = "/pubmed/{pid}"235 po = self.PO()236 po._is_robot = True237 po._resolve_url("1234")238 @raises(exceptions.UriResolutionError)239 def test_absolute_url_without_scheme(self):240 self.set_baseurl_env()241 self.PO.uri_template = "/pubmed/{pid}"242 po = self.PO()243 po._resolve_url("//www.google.com")244 ### Normative Cases ###245 def test_url_string_bypasses_uri_template(self):246 """A path was passed in as a string (inside or outside Robot). It should just be appended to247 the baseurl, even if there is a template in the PO."""248 self.set_baseurl_env()249 self.PO.uri_template = "/pubmed/{pid}"250 po = self.PO()251 path = "/pmc/1234"252 url = po._resolve_url(path)253 self.assertEquals(url, po.baseurl + path)254 def test_url_string_bypasses_uri(self):255 """A path was passed in as a string (inside or outside Robot). It should just be appended to256 the baseurl, even if there is a uri set in the PO."""257 self.set_baseurl_env()258 self.PO.uri = "/pubmed"259 po = self.PO()260 path = "/pmc/1234"261 url = po._resolve_url(path)262 self.assertEquals(url, po.baseurl + path)263 def test_absolute_url_bypasses_uri_template(self):264 """An absolute url was passed in as a string (inside or outside Robot). It should just be used instead of265 the PO's uri_template."""266 self.set_baseurl_env()267 self.PO.uri_template = "/pubmed/{pid}"268 po = self.PO()269 abs_url = "http://www.google.com"270 resolved_url = po._resolve_url(abs_url)271 self.assertEquals(resolved_url, abs_url)272 def test_absolute_url_bypasses_uri(self):273 """An absolute url was passed in as a string (inside or outside Robot). It should just be used instead of274 the PO's uri."""275 self.set_baseurl_env()276 self.PO.uri = "/pubmed/{pid}"277 po = self.PO()278 abs_url = "http://www.google.com"279 resolved_url = po._resolve_url(abs_url)280 self.assertEquals(resolved_url, abs_url)281 def test_rel_uri_is_resolved(self):282 self.set_baseurl_env()283 self.PO.uri = "/foo"284 po_inst = self.PO()285 url = po_inst._resolve_url()286 self.assertEquals(url, po_inst.baseurl + po_inst.uri)287 self.assertRegexpMatches(url, "file:///.+/foo$")288 def test_uri_template_is_resolved(self):289 self.set_baseurl_env(base_file=False, arbitrary_base="http://www.ncbi.nlm.nih.gov")290 self.PO.uri_template = "/pubmed/{pid}"291 p = self.PO()292 url = p._resolve_url({"pid": "123"})293 pid = p.uri_vars["pid"]294 self.assertEquals("123", pid)295 self.assertEquals("http://www.ncbi.nlm.nih.gov/pubmed/123", url)296 def test_baseurl_set_no_uri_attr_set(self):297 """A baseurl is set, but no variables were passed in and no "uri" was set."""298 self.set_baseurl_env()299 self.PO()._resolve_url()300class SelectorsTestCase(BaseTestCase):301 @raises(exceptions.DuplicateKeyError)302 def test_selectors_dup(self):303 class BaseFoo(object):304 selectors = {"foo": "foo"}305 class BaseBar(object):306 selectors = {"foo": "bar"}307 class FooBarPage(Page, BaseFoo, BaseBar):308 selectors = {"foo": "baz"}309 page = FooBarPage()310 def test_selectors_merge_override(self):311 class BaseFoo(object):312 selectors = {"foo": "foo"}313 class BaseBar(object):314 selectors = {"bar": "bar",315 "baz": "cat"}316 class FooBarPage(Page, BaseFoo, BaseBar):317 selectors = {Override("baz"): "baz"}318 page = FooBarPage()319 selectors = page.selectors320 self.assertEqual(selectors.get("foo"), "foo", "Selectors should contain 'foo' from BaseFoo.")321 self.assertEqual(selectors.get("bar"), "bar", "Selectors should contain 'bar' from BaseBar.")322 self.assertEqual(selectors.get("baz"), "baz", "Selector 'baz' should be overridden in FooBarPage.")323class KeywordTestCase(BaseTestCase):324 def setUp(self):325 super(KeywordTestCase, self).setUp()326 # No need for testing in Robot too, since we will have a general test327 # that exceptions get raised properly, and this is just another exception.328 class P(Page):329 uri = ""330 def not_return_none(self):331 return True332 def return_none(self):333 pass334 @not_keyword335 def return_none_not_keyword(self):336 pass337 def _return_none(self):338 pass339 self.p = P()340 def test_method_not_return_none_should_not_raise_exception(self):341 self.assertTrue(self.p.not_return_none())342 @raises(exceptions.KeywordReturnsNoneError)343 def test_method_returning_none_should_raise_exception(self):344 self.p.return_none()345 def test_method_returning_none_with_not_keyword_should_not_raise_exception(self):346 self.assertIsNone(self.p.return_none_not_keyword())347 def test_private_method_returning_none_should_not_raise_exception(self):348 self.assertIsNone(self.p._return_none())349 def test_se2lib_keywords_fixed_to_mention_selectors(self):350 m = getattr(self.p, "click_element")351 docstring = inspect.getdoc(m)352 first_line_of_docstring = docstring.split("\n")[0]353 self.assertEquals(first_line_of_docstring, "click_element(self, selector_or_locator)")354 self.assertTrue("Click element identified by `selector` or `locator`" in docstring)355 def test_is_obj_keyword(self):356 is_obj_keyword = _Keywords.is_obj_keyword357 self.assertTrue(is_obj_keyword(Page.click_element))358 self.assertFalse(is_obj_keyword(Page.selectors))359 self.assertFalse(is_obj_keyword(Page._is_url_absolute))360 self.assertFalse(is_obj_keyword(Page.get_current_browser))361 self.assertFalse(is_obj_keyword(Page.driver))362 def test_is_obj_keyword_by_name(self):363 is_obj_keyword_by_name = _Keywords.is_obj_keyword_by_name364 self.assertTrue(is_obj_keyword_by_name("click_element", Page))365 self.assertFalse(is_obj_keyword_by_name("selectors", Page))366 self.assertFalse(is_obj_keyword_by_name("_is_url_absolute", Page))367 self.assertFalse(is_obj_keyword_by_name("get_current_browser", Page))368 self.assertFalse(is_obj_keyword_by_name("driver", Page))369 self.assertFalse(is_obj_keyword_by_name("foobarbatdaniel", Page))370 def test_page_property_raises_exception(self):371 class MyPage(Page):372 @property373 def some_property(self):374 raise Exception()375 exc_raised = False376 try:377 MyPage().get_keyword_names()378 except:379 exc_raised = True380 self.assertFalse(exc_raised, "An exception was raised when trying to access a page object property that "381 "raises an exception itself")382class LoggingLevelsTestCase(BaseTestCase):383 # Tests protected method Page._get_normalized_logging_levels, which given a384 # String logging level should return a tuple of the attempted string logging level385 # with the associated integer level from Python's logging module. This method386 # deals with the fact that Robot has different logging levels than python. It's called387 # by Page.log().388 def setUp(self):389 super(LoggingLevelsTestCase, self).setUp()390 self.normalize_fn = Page._abstracted_logger.get_normalized_logging_levels391 def test_log_CRITICAL_python(self):392 level_tup = self.normalize_fn("CRITICAL", False)393 self.assertEquals(level_tup, ("CRITICAL", 50))394 def test_log_CRITICAL_robot(self):395 level_tup = self.normalize_fn("CRITICAL", True)396 self.assertEquals(level_tup, ("WARN", 30))397 def test_log_WARN_python(self):398 level_tup = self.normalize_fn("WARN", False)399 self.assertEquals(level_tup, ("WARN", 30))400 def test_log_WARNING_python(self):401 level_tup = self.normalize_fn("WARNING", False)402 self.assertEquals(level_tup, ("WARNING", 30))403 def test_log_WARN_robot(self):404 level_tup = self.normalize_fn("WARN", True)405 self.assertEquals(level_tup, ("WARN", 30))406 def test_log_WARNING_robot(self):407 level_tup = self.normalize_fn("WARNING", True)408 self.assertEquals(level_tup, ("WARN", 30))409 def test_log_INFO_python(self):410 level_tup = self.normalize_fn("INFO", False)411 self.assertEquals(level_tup, ("INFO", 20))412 def test_log_INFO_robot(self):413 level_tup = self.normalize_fn("INFO", False)414 self.assertEquals(level_tup, ("INFO", 20))415 def test_log_DEBUG_python(self):416 level_tup = self.normalize_fn("DEBUG", False)417 self.assertEquals(level_tup, ("DEBUG", 10))418 def test_log_DEBUG_robot(self):419 level_tup = self.normalize_fn("DEBUG", True)420 self.assertEquals(level_tup, ("DEBUG", 10))421 def test_log_TRACE_python(self):422 level_tup = self.normalize_fn("TRACE", False)423 self.assertEquals(level_tup, ("NOTSET", 0))424 def test_log_TRACE_robot(self):425 level_tup = self.normalize_fn("TRACE", True)426 self.assertEquals(level_tup, ("TRACE", 0))427 def test_log_NOTSET_python(self):428 level_tup = self.normalize_fn("NOTSET", False)429 self.assertEquals(level_tup, ("NOTSET", 0))430 def test_log_NOTSET_robot(self):431 level_tup = self.normalize_fn("NOTSET", True)432 self.assertEquals(level_tup, ("TRACE", 0))433 @raises(ValueError)434 def test_log_invalid_log_level_should_raise_value_error_python(self):435 level_tup = self.normalize_fn("FOO", False)436 self.assertEquals(level_tup, ("FOO", 0))437 @raises(ValueError)438 def test_log_invalid_log_level_should_raise_value_error_robot(self):439 level_tup = self.normalize_fn("FOO", True)440 self.assertEquals(level_tup, ("FOO", 0))441 def test_log_valid_but_lowercase_level_python(self):442 level_tup = self.normalize_fn("inFo", False)443 self.assertEquals(level_tup, ("INFO", 20))444class SelectorTemplateTestCase(BaseTestCase):445 def setUp(self):446 super(SelectorTemplateTestCase, self).setUp()447 self.p = Page()448 self.p.selectors["foo"] = "xpath=//foo[{n}]/{el}"449 def test_basic(self):450 self.assertEquals("xpath=//foo[3]/p", self.p.resolve_selector("foo", n=3, el="p"))451 def test_too_many_args(self):452 self.assertEquals("xpath=//foo[3]/p", self.p.resolve_selector("foo", n=3, el="p", boo="bat"))453 @raises(exceptions.SelectorError)454 def test_not_enough_args(self):455 self.p.resolve_selector("foo", n=3)456 @raises457 def test_wrong_args(self):458 self.p.resolve_selector("foo", n=3, ep="p")459class GetSubclassFromPOModuleTestCase(BaseTestCase):460 def setUp(self):461 super(GetSubclassFromPOModuleTestCase, self).setUp()462 self.p = BaseHomePage()463 @raises(exceptions.PageSelectionError)464 def test_no_fallback_raises_exception_with_nonexistent_package(self):465 klass = self.p.get_subclass_from_po_module("nonexistentpageobjects", BaseResultsPage, fallback_to_super=False)466 def test_with_fallback_with_nonexistent_package(self):467 klass = self.p.get_subclass_from_po_module("nonexistentpageobjects", BaseResultsPage, fallback_to_super=True)468 self.assertEqual(klass, BaseResultsPage, "Fallback with nonexistent package should fall back to class"469 "BaseSearchResultPage.")470 def test_package_on_path_with_fallback_succeeds(self):471 klass = self.p.get_subclass_from_po_module("mydbpageobjects", BaseResultsPage, fallback_to_super=True)472 self.assertEqual(klass.__name__, "MyDBResultsPage", "MyDBResultsPage class should be selected.")473 def test_package_on_path_without_fallback_succeeds(self):474 klass = self.p.get_subclass_from_po_module("mydbpageobjects", BaseResultsPage, fallback_to_super=False)475 self.assertEqual(klass.__name__, "MyDBResultsPage", "MyDBResultsPage class should be selected.")476class ServiceArgsTestCase(BaseTestCase):477 def test_set_service_args(self):478 class P(Page):pass479 os.environ["PO_SERVICE_ARGS"] = "--cookies-file=foo.txt"480 service_args = P().service_args481 self.assertTrue(isinstance(service_args, list), "Service args is a list")482 self.assertEquals(len(service_args), 1, "Service args property has 1 member")483 self.assertEquals(484 service_args[0], 485 "--cookies-file=foo.txt", 486 "Service args is what we set it to be"...

Full Screen

Full Screen

abstractedlogger.py

Source:abstractedlogger.py Github

copy

Full Screen

...44 return getattr(logging, str_upper)45 except AttributeError:46 return getattr(logging, "INFO")47 @staticmethod48 def get_normalized_logging_levels(level_as_str, in_robot):49 """ Given a log string, returns the translated log level string and the translated50 python logging level integer. This is needed because there are logging level51 constants defined in Robot that are not in Python, and Python logging level52 constants that are not defined in Robot.53 """54 translation_map = {55 "CRITICAL": "WARN",56 "WARNING": "WARN",57 "NOTSET": "TRACE"58 }59 level_as_str_upper = level_as_str.upper()60 if in_robot:61 robot_levels = robot_logging_conf.LEVELS62 # The level passed in is a Robot level, so look up corresponding63 # python integer logging level64 if level_as_str_upper is "WARNING":65 # There is no "WARNING" in Robot66 level_as_str_upper = "WARN"67 if level_as_str_upper in robot_levels:68 return level_as_str_upper, robot_levels[level_as_str_upper]69 else:70 # The level passed-in doesn't correspond to a71 # Robot level, so translate it to one, then look it up.72 translated_level_str = None73 try:74 translated_level_str = translation_map[level_as_str_upper]75 except KeyError:76 raise ValueError("The log level '%s' is invalid" % level_as_str_upper)77 return translated_level_str, robot_levels[translated_level_str]78 else:79 try:80 # Try to get levels from python81 return level_as_str_upper, getattr(logging, level_as_str_upper)82 except AttributeError:83 # Could be user is passing in a Robot log string that84 # doesn't exist for Python. So look up the Python level given the robot level85 inv_translation_map = {v: k for k, v in translation_map.items()}86 try:87 translated_level_str = inv_translation_map[level_as_str_upper]88 except KeyError:89 translated_level_str = level_as_str_upper90 try:91 return translated_level_str, getattr(logging, translated_level_str)92 except AttributeError:93 raise ValueError("The log level '%s' is invalid" % level_as_str_upper)94 def log(self, msg, calling_page_name, level="INFO", is_console=True):95 level_as_str, level_as_int = self.get_normalized_logging_levels(level, self.in_robot)96 msg = "%s - %s" % (calling_page_name, msg)97 if self.in_robot:98 self.logger.write(msg, level_as_str)99 if is_console:100 # Robot's logging only outputs to stdout if it's a warning, so allow101 # always logging to console, unless caller specifies not to.102 robot.api.logger.console("%s - %s" % (level, msg))103 else:104 if is_console:105 self.logger.addHandler(self.stream_handler)...

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