diff --git a/README.md b/README.md index 666bd39..2a7d107 100755 --- a/README.md +++ b/README.md @@ -332,7 +332,7 @@ There are two types of page objects: singular and templated. ### Singular Page Objects -A singular page object models a page with only one URL. For example, `GoogleHomePage` is singular, because there's only one URI: “/“. Singular page objects should have a `uri` attribute in their class definitions: +A singular page object models a page with only one URL. For example, `GoogleHomePage` is singular, because there's only one URI: “/“. Singular page objects should have a `uri` attribute (defaults to '/') in their class definitions: ... class MyAppHomePage(EntrezPage): diff --git a/robotpageobjects/page.py b/robotpageobjects/page.py index 553ed9b..8e804d4 100755 --- a/robotpageobjects/page.py +++ b/robotpageobjects/page.py @@ -144,6 +144,9 @@ def __init__(self): # Allow setting of uri_template or uri, but make them the same internally if hasattr(self, 'uri_template'): self.uri = self.uri_template + # Set a default uri in case one is not set in the Page + elif not hasattr(self, 'uri'): + self.uri = '/' @staticmethod @not_keyword diff --git a/tests/scenarios/test_go_to.py b/tests/scenarios/test_go_to.py index cebe044..1e02a99 100755 --- a/tests/scenarios/test_go_to.py +++ b/tests/scenarios/test_go_to.py @@ -1,5 +1,6 @@ import unittest from po import widget_template +from robotpageobjects import Page class TestWidgetItem(unittest.TestCase): @@ -10,6 +11,12 @@ def test_widget_item(self): self.widget_item_page.go_to({"category": "home-and-garden", "id": "123"}) self.widget_item_page.title_should_be("Cool Widget") + def test_no_uri_template(self): + self.p = Page() + self.p.baseurl = 'https://www.google.com/' + self.p.open() + self.p.title_should_be('Google') + def tearDown(self): try: self.widget_item_page.close() diff --git a/tests/test_functional.py b/tests/test_functional.py index 511feff..d431e43 100755 --- a/tests/test_functional.py +++ b/tests/test_functional.py @@ -69,10 +69,6 @@ def test_no_baseurl_gives_readable_error_in_robot(self): run = self.run_scenario("test_template_passed.robot") self.assert_run(run, expected_returncode=1, search_output="must set a baseurl") - def test_no_uri_attr_gives_readable_error_in_robot(self): - run = self.run_scenario("test_no_uri.robot", variable="baseurl:%s" % self.base_file_url) - self.assert_run(run, expected_returncode=1, search_output='must have a "uri" attribute set') - def test_enlarge_browser_on_open(self): self.set_baseurl_env() run = self.run_scenario("test_enlarge_browser_on_open.py") diff --git a/tests/test_unit.py b/tests/test_unit.py index 51e6983..09d4667 100755 --- a/tests/test_unit.py +++ b/tests/test_unit.py @@ -212,13 +212,6 @@ def test_no_baseurl_set_and_uri_attr_set_and_uri_vars_set(self): self.PO.uri = "/foo" self.PO()._resolve_url("bar") - @raises(exceptions.UriResolutionError) - def test_baseurl_set_no_uri_attr_set(self): - """A baseurl is set, but no variables were passed in and no "uri" was set.""" - - self.set_baseurl_env() - self.PO()._resolve_url() - @raises(exceptions.UriResolutionError) def test_baseurl_set_abs_uri_attr(self): """An absolute url (with scheme) was set as the uri.""" @@ -340,6 +333,12 @@ def test_uri_template_is_resolved(self): self.assertEquals("123", pid) self.assertEquals("http://www.ncbi.nlm.nih.gov/pubmed/123", url) + def test_baseurl_set_no_uri_attr_set(self): + """A baseurl is set, but no variables were passed in and no "uri" was set.""" + + self.set_baseurl_env() + self.PO()._resolve_url() + class SelectorsTestCase(BaseTestCase): @raises(exceptions.DuplicateKeyError)