Skip to content
This repository has been archived by the owner on Aug 20, 2018. It is now read-only.

Added test for searching on a QMO post tag #28

Merged
merged 4 commits into from
Oct 30, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pages/base.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


class BasePage(Page): class BasePage(Page):


_page_title_locator = (By.CSS_SELECTOR, "h1.page-title") _page_title_locator = (By.CSS_SELECTOR, "h1.section-title")


@property @property
def is_logged_in(self): def is_logged_in(self):
Expand Down
9 changes: 9 additions & 0 deletions pages/community.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,13 +4,22 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this # License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.


from selenium.webdriver.common.by import By

from base import BasePage from base import BasePage




class CommunityPage(BasePage): class CommunityPage(BasePage):


_page_title = u'Community | QMO \u2013 quality.mozilla.org' _page_title = u'Community | QMO \u2013 quality.mozilla.org'
_tag_locator = (By.CSS_SELECTOR, '#tag_cloud-3 a')


def go_to_community_page(self): def go_to_community_page(self):
self.selenium.get(self.testsetup.base_url + '/community') self.selenium.get(self.testsetup.base_url + '/community')
self.is_the_current_page self.is_the_current_page

@property
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should be marked as a property, as it performs an action. I could be wrong about that so maybe someone else wants to comment on this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call- I saw that earlier and meant to remove it but forgot!

def click_first_tag_link(self):
self.selenium.find_element(*self._tag_locator).click()
from pages.tag_results import TagResultsPage
return TagResultsPage(self.testsetup)
16 changes: 16 additions & 0 deletions pages/tag_results.py
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env python

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

from selenium.webdriver.common.by import By

from base import BasePage


class TagResultsPage(BasePage):

@property
def results(self):
return self.selenium.find_elements(By.CSS_SELECTOR, "#content-main > article")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should assign a variable to the locator at the beginning of the class:
_results_locator = (By.CSS_SELECTOR, '#content-main > article')
and use the variable here:
return self.selenium.find_elements(*self._results_locator)

24 changes: 24 additions & 0 deletions tests/test_tag_search.py
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env python

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import pytest
from unittestzero import Assert

from pages.community import CommunityPage
from pages.tag_results import TagResultsPage
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use this import in the test, so we can remove it.



class TestTagSearchPage:

@pytest.mark.nondestructive
def test_search_tag(self, mozwebqa):
community_page = CommunityPage(mozwebqa)
community_page.go_to_community_page()

tag_results_page = community_page.click_first_tag_link

Assert.contains('Posts and pages tagged', tag_results_page.page_title)
Assert.greater(len(tag_results_page.results), 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may want to add an assert for the page title, using Assert.contains because the tag name may be different for different test runs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After removing the properties for tag_results.py what can I use for the Assert.contains outside of expected text? I have no page attributes to reference.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need a property in the page object which returns the page's actual title, and then you can compare that to an expected value in the test.

I notice that there is a page_title property in base.py, which tag_results.py inherits from, so that may work, or it may not based on how it's implemented. I suggest trying to use that first (which would mean you wouldn't have to add a property to tag_results.py), but if it doesn't give you what you want you may have to add a property to tag_results.py which might make use of self.selenium.title.