Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added test for search with data into test_search_results #25

Merged
merged 3 commits into from

4 participants

@rbillings
Owner

No description provided.

pages/regions/header.py
@@ -15,6 +15,7 @@ class HeaderRegion(Page):
_media_link_locator = (By.CSS_SELECTOR, '#nav-main li:nth-child(5) a')
_docs_link_locator = (By.CSS_SELECTOR, '#nav-main li:nth-child(6) a')
_search_button_locator = (By.CSS_SELECTOR, '#search button')
+ _search_field_locator = (By.CSS_SELECTOR, '#search')
@AlinT
AlinT added a note

This is not the locator for the seach field input. This is one example of the search_field_locator:
(By.CSS_SELECTOR, '#search input#s')

Also because the locator isn't pointing correctly to what it should, the test is failing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
tests/test_search_results.py
@@ -20,3 +21,15 @@ def test_no_results_returned_from_blank_search(self, mozwebqa):
home_page.header_region.click_search_button()
Assert.true(home_page.is_the_current_page)
Assert.true(home_page.get_url_current_page().endswith('/?s='))
+
+ @pytest.mark.nondestructive
+ def test_search_results_returned(self,mozwebqa):
+ home_page = HomePage(mozwebqa)
+ home_page.go_to_home_page()
+
+ search_results_page = home_page.header_region.type_in_search_field('job board')
+ search_results_page = home_page.header_region.click_search_button()
+
+ expected_text= "Search results"
+ Assert.contains(expected_text, search_results_page._page_title)
+ Assert.true(search_results_page.get_url_current_page().endswith('/?s='))
@AlinT
AlinT added a note

Why is this assert here, because the url of the current page after the search does not end with /?s= , it ends with /?s=

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
tests/test_search_results.py
@@ -20,3 +21,15 @@ def test_no_results_returned_from_blank_search(self, mozwebqa):
home_page.header_region.click_search_button()
Assert.true(home_page.is_the_current_page)
Assert.true(home_page.get_url_current_page().endswith('/?s='))
+
+ @pytest.mark.nondestructive
+ def test_search_results_returned(self,mozwebqa):
+ home_page = HomePage(mozwebqa)
+ home_page.go_to_home_page()
+
+ search_results_page = home_page.header_region.type_in_search_field('job board')
@AlinT
AlinT added a note

You should simply make home_page.header_region.type_in_search('job board'), because this method does not return anything.

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

the test is too fragile...
ex:
If the title is "No Search results found" the test will pass

You could count if there is data returned...
ex:
Do a
Assert.greater_equal(1, len(self.selenium.find_elements(By.CSS_SELECTOR, "#content-main > article")))

@rbillings
Owner

Thanks AlinT & bebef1987 for your suggestions!

@stephendonner

Merged!

@stephendonner stephendonner merged commit 9f73c63 into mozilla:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 7, 2012
  1. Added test for search with data into test_search_results

    Rebecca Billings authored
Commits on Sep 12, 2012
  1. Updated search selector, removed unneeded assert and fixed the type i…

    Rebecca Billings authored
    …n search field method.
Commits on Sep 14, 2012
  1. Added assertion to check for search results

    Rebecca Billings authored
This page is out of date. Refresh to see the latest.
View
9 pages/regions/header.py
@@ -15,6 +15,7 @@ class HeaderRegion(Page):
_media_link_locator = (By.CSS_SELECTOR, '#nav-main li:nth-child(5) a')
_docs_link_locator = (By.CSS_SELECTOR, '#nav-main li:nth-child(6) a')
_search_button_locator = (By.CSS_SELECTOR, '#search button')
+ _search_field_locator = (By.CSS_SELECTOR, '#search input#s')
def click_community_link(self):
self.selenium.find_element(*self._community_link_locator).click()
@@ -40,3 +41,11 @@ def click_search_button(self):
self.selenium.find_element(*self._search_button_locator).click()
from pages.search_results import SearchResultsPage
return SearchResultsPage(self.testsetup)
+
+ def click_search_field(self):
+ self.selenium.find_element(*self._search_field_locator).click()
+ from pages.search_results import SearchResultsPage
+ return SearchResultsPage(self.testsetup)
+
+ def type_in_search_field(self, text):
+ self.selenium.find_element(*self._search_field_locator).send_keys(text)
View
11 pages/search_results.py
@@ -12,11 +12,20 @@
class SearchResultsPage(BasePage):
_page_title = u'Search results'
+ _search_text_locator = (By.ID, 'content-main')
- def go_to_docs_page(self):
+ def search_results_page(self):
self.selenium.get(self.testsetup.base_url + '/?s')
self.is_the_current_page
@property
def is_page_title_correct(self):
return self.selenium.get_title() == self._page_title
+
+ @property
+ def search_text(self):
+ return self.selenium.find_element(*self._search_text_locator).text
+
+ @property
+ def results(self):
+ return self.selenium.find_elements(By.CSS_SELECTOR, "#content-main > article")
View
13 tests/test_search_results.py
@@ -8,6 +8,7 @@
from unittestzero import Assert
from pages.home import HomePage
+from pages.search_results import SearchResultsPage
class TestSearchPage:
@@ -20,3 +21,15 @@ def test_no_results_returned_from_blank_search(self, mozwebqa):
home_page.header_region.click_search_button()
Assert.true(home_page.is_the_current_page)
Assert.true(home_page.get_url_current_page().endswith('/?s='))
+
+ @pytest.mark.nondestructive
+ def test_search_results_returned(self,mozwebqa):
+ home_page = HomePage(mozwebqa)
+ home_page.go_to_home_page()
+
+ home_page.header_region.type_in_search_field('job board')
+ search_results_page = home_page.header_region.click_search_button()
+
+ expected_text= "Search results"
+ Assert.contains(expected_text, search_results_page._page_title)
+ Assert.greater(len(search_results_page.results), 0)
Something went wrong with that request. Please try again.