How to use _is_url_absolute method in robotframework-pageobjects

Best Python code snippet using robotframework-pageobjects_python

page.py

Source:page.py Github

copy

Full Screen

...348 uri_type = 'template' if re.search('{.+}', self.uri) else 'plain'349 else:350 raise exceptions.UriResolutionError("Page object \"%s\" must have a \"uri\" attribute set." % pageobj_name)351 # Don't allow absolute uri attribute.352 if self._is_url_absolute(self.uri):353 raise exceptions.UriResolutionError(354 "Page object \"%s\" must not have an absolute \"uri\" attribute set. Use a relative URL "355 "instead." % pageobj_name)356 # We always need a baseurl set. This enforces parameterization of the357 # domain under test.358 if self.baseurl is None:359 raise exceptions.UriResolutionError("To open page object, \"%s\" you must set a baseurl." % pageobj_name)360 elif len(args) > 0 and hasattr(self, "uri") and self._is_url_absolute(self.uri):361 # URI template variables are being passed in, so the page object encapsulates362 # a page that follows some sort of URL pattern. Eg, /pubmed/SOME_ARTICLE_ID.363 raise exceptions.UriResolutionError("The URI Template \"%s\" in \"%s\" is an absolute URL. "364 "It should be relative and used with baseurl" %365 (self.uri, pageobj_name))366 if len(args) > 0:367 # the user wants to open a non-default uri368 uri_vars = {}369 first_arg = args[0]370 if not self._is_robot:371 if isinstance(first_arg, basestring):372 # In Python, if the first argument is a string and not a dict, it's a url or path.373 arg_type = "url"374 else:375 arg_type = "dict"376 elif self._is_robot:377 # We'll always get string args in Robot378 if self._is_url_absolute(first_arg) or first_arg.startswith("/"):379 arg_type = "url"380 else:381 arg_type = "robot"382 if arg_type != "url" and hasattr(self, "uri") and uri_type == 'plain':383 raise exceptions.UriResolutionError(384 "URI %s is set for page object %s. It is not a template, so no arguments are allowed." %385 (self.uri, pageobj_name))386 if arg_type == "url":387 if self._is_url_absolute(first_arg):388 # In Robot, the first argument is always a string, so we need to check if it starts with "/" or a scheme.389 # (We're not allowing relative paths right now._390 return first_arg391 elif first_arg.startswith("//"):392 raise exceptions.UriResolutionError("%s is neither a URL with a scheme nor a relative path"393 % first_arg)394 else: # starts with "/"395 # so it doesn't need resolution, except for appending to baseurl and stripping leading slash396 # if it needed: i.e., if the base url ends with "/" and the url starts with "/".397 return re.sub("\/$", "", self.baseurl) + first_arg398 elif arg_type == "robot":399 # Robot args need to be parsed as "arg1=123", "arg2=foo", etc.400 for arg in args:401 split_arg = arg.split("=")402 uri_vars[split_arg[0]] = "=".join(split_arg[1:])403 else:404 # dict just contains the args as keys and values405 uri_vars = args[0]406 # Check that variables are correct and match template.407 if not self._vars_match_template(self.uri, uri_vars):408 raise exceptions.UriResolutionError(409 "The variables %s do not match template %s for page object %s"410 % (uri_vars, self.uri, pageobj_name)411 )412 self.uri_vars = uri_vars413 return uritemplate.expand(self.baseurl + self.uri, uri_vars)414 else:415 if uri_type == 'template':416 raise exceptions.UriResolutionError('%s has uri template %s , but no arguments were given to resolve it' %417 (pageobj_name, self.uri))418 # the user wants to open the default uri419 return self.baseurl + self.uri420 @staticmethod421 def _is_url_absolute(url):422 """423 We're making the scheme mandatory, because webdriver can't handle just "//".424 """425 return re.match("^(\w+:(\d+)?)\/\/", url) is not None426 def go_to(self, *args):427 """428 Wrapper to make go_to method support uri templates.429 """430 resolved_url = self._resolve_url(*args)431 super(_BaseActions, self).go_to(resolved_url)432 return self433 def _generic_make_browser(self, webdriver_type, desired_cap_type, remote_url, desired_caps):434 """Override Selenium2Library's _generic_make_browser to allow for extra params435 to driver constructor."""...

Full Screen

Full Screen

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

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