Added test for searching on a QMO post tag #28

Merged
merged 4 commits into from Oct 30, 2012

Conversation

Projects
None yet
5 participants
Collaborator

rbillings commented Sep 18, 2012

I created a new test for click searching on QMO tags from the Community page. It is almost identical to test_tag_search.py. However, the test fails as it thinks it is still on the community_page after the click on line 21. I checked by adding a community_page get page title check which I removed after seeing that it did think it was on that page- in spite of the test failing on the correct /tag/a11y page. I just don't know what is going wrong, so comments would be appreciated.

Rebecca Bill... added some commits Sep 17, 2012

@bobsilverberg bobsilverberg commented on an outdated diff Sep 18, 2012

tests/test_tag_search.py
+
+import pytest
+from unittestzero import Assert
+
+from pages.community import CommunityPage
+from pages.tag_results import TagResultsPage
+
+
+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.find_tag_link.click()
@bobsilverberg

bobsilverberg Sep 18, 2012

Collaborator

The problem you are having is because the call to community_page.find_tag_link.click() does not return an instance of the TagResultsPage object. What you likely want to do is define a method in community.py which can be used to click on a tag and which returns an instance of the TagResultsPage object. I will add another comment to the code for community.py with an example.

@bobsilverberg bobsilverberg commented on an outdated diff Sep 18, 2012

pages/community.py
def go_to_community_page(self):
self.selenium.get(self.testsetup.base_url + '/community')
self.is_the_current_page
+
+ @property
+ def find_tag_link(self):
+ return self.selenium.find_element(*self._tag_locator)
@bobsilverberg

bobsilverberg Sep 18, 2012

Collaborator

I suggest replacing this @property with a method like so:

def click_first_tag_link(self):
    self.selenium.find_element(*self._tag_locator).click()
    from pages.tag_results import TagResultsPage
    return TagResultsPage(self.testsetup)

When you then call this method from test_search_tag it will return the page object you expect at which point you can work with it.

Collaborator

bobsilverberg commented Sep 18, 2012

I hope the above suggestions/explanations help. If not please feel free to ping me the next time you see me on irc and I will try to do a better job of explaining.

Collaborator

rbillings commented Sep 18, 2012

This pull request addresses issue #26, for bug: https://bugzilla.mozilla.org/show_bug.cgi?id=781553

@bobsilverberg bobsilverberg and 1 other commented on an outdated diff Sep 18, 2012

pages/tag_results.py
+# 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):
+
+ _page_title = u'Posts tagged'
+
+ def tag_results_page(self):
+ self.selenium.get(self.testsetup.base_url + '/tag/a11y/')
+ self.is_the_current_page
+
@bobsilverberg

bobsilverberg Sep 18, 2012

Collaborator

I would remove the entire tag_results_page method. One would not normally access this page directly via a url, but would always get here by clicking a link (I believe).

@bebef1987

bebef1987 Sep 25, 2012

Contributor

Also this is not used in the test

@bobsilverberg bobsilverberg commented on an outdated diff Sep 18, 2012

pages/tag_results.py
+
+from base import BasePage
+
+
+class TagResultsPage(BasePage):
+
+ _page_title = u'Posts tagged'
+
+ def tag_results_page(self):
+ self.selenium.get(self.testsetup.base_url + '/tag/a11y/')
+ self.is_the_current_page
+
+ @property
+ def is_page_title_correct(self):
+ return self.selenium.get_title() == self._page_title
+
@bobsilverberg

bobsilverberg Sep 18, 2012

Collaborator

I would remove is_page_title_correct as well because the page title will include the tag name and therefore will never be a straight expected == actual scenario.

@bobsilverberg bobsilverberg commented on the diff Sep 18, 2012

pages/community.py
def go_to_community_page(self):
self.selenium.get(self.testsetup.base_url + '/community')
self.is_the_current_page
+
+ @property
@bobsilverberg

bobsilverberg Sep 18, 2012

Collaborator

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.

@rbillings

rbillings Sep 18, 2012

Collaborator

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

@bobsilverberg bobsilverberg and 1 other commented on an outdated diff Sep 18, 2012

tests/test_tag_search.py
+from unittestzero import Assert
+
+from pages.community import CommunityPage
+from pages.tag_results import TagResultsPage
+
+
+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.greater(len(tag_results_page.results), 0)
@bobsilverberg

bobsilverberg Sep 18, 2012

Collaborator

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.

@rbillings

rbillings Sep 18, 2012

Collaborator

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.

@bobsilverberg

bobsilverberg Sep 19, 2012

Collaborator

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.

Collaborator

rbillings commented Oct 8, 2012

My test results all fail on this line:
expected_page_title = tag_results_page.page_title
With the error : "AttributeError: 'function' object has no attribute 'page_title'
This was even after I copied [from base.py] the definition of page_title into tag_results.py. Suggestions?

Contributor

teodosia commented Oct 10, 2012

@rbillings I've tried the same thing (expected_page_title = tag_results_page.page_title) and the tests indeed fails because the title in the tag page(h1.section-title) has a different locator that the one in base_page.py(h1.page-title)
I've noticed that all the page titles have this locator h1.section-title so you should change it in the base_page.py and than it should work.

Collaborator

rbillings commented Oct 10, 2012

@teodosia good idea. However I tried updating base.py to go to h1.section-title and also tried adding it directly into the tag_results.py and running the test still fails with the same AttributeError listed above. I'm stumped!

Collaborator

bobsilverberg commented Oct 11, 2012

@rbillings I just tried it with @teodosia's suggestion and it worked for me. It's a two step process:

  1. Change the locator in base.py (at line 14) to be:
    _page_title_locator = (By.CSS_SELECTOR, "h1.section-title")
  2. Add an assert into the test in test_tag_search.py to test against the page_title property (at line 23) like so:
    Assert.contains('Posts and pages tagged', tag_results_page.page_title)

I think that should work for you too.

Rebecca Billings Edited base.py and tag_search_results. Test still fails for me- but n…
…ot for others and afaict this is the correct code.
7d7b9d9

@teodosia teodosia commented on the diff Oct 16, 2012

tests/test_tag_search.py
@@ -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
@teodosia

teodosia Oct 16, 2012

Contributor

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

@teodosia teodosia commented on the diff Oct 16, 2012

pages/tag_results.py
+#!/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")
@teodosia

teodosia Oct 16, 2012

Contributor

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)

Contributor

teodosia commented Oct 16, 2012

Besides the comments the code looks good to me and the test passes. I ran the test on https://quality.mozilla.org.
@rbillings could you, please, copy-paste the stacktrace of your fail here to try and figure out why it's not working for you?

Collaborator

rbillings commented Oct 16, 2012

The test is failing as it doesn't click the tag, but I'm not sure why it doesn't:

    tag_results_page = community_page.click_first_tag_link
  Assert.contains('Posts and pages tagged', tag_results_page.page_title)

E AttributeError: 'function' object has no attribute 'page_title'

tests/test_tag_search.py:22: AttributeError
------------------------------- pytest-mozwebqa --------------------------------
Failing URL: https://quality.mozilla.org/community/

Collaborator

stephendonner commented Oct 20, 2012

Can we shore this up on Monday? Thanks!

Collaborator

rbillings commented Oct 20, 2012

I committed my last fix a few days ago- and I can see it on my branch but not here...
rbillings/qmo-tests@7d7b9d9
Unless someone has a quick idea I'll look into this on Monday.

Collaborator

stephendonner commented Oct 30, 2012

This passes for other folks, and passes in Jenkins:

Fetching upstream changes from git://github.com/rbillings/qmo-tests.git
Commencing build of Revision 7d7b9d9 (origin/tagsearch)
Checking out Revision 7d7b9d9 (origin/tagsearch)

tests/test_tag_search.py .

Finished: SUCCESS

Merging this in :-)

stephendonner merged commit b441c52 into mozilla:master Oct 30, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment