001/* 002 Licensed to the Apache Software Foundation (ASF) under one 003 or more contributor license agreements. See the NOTICE file 004 distributed with this work for additional information 005 regarding copyright ownership. The ASF licenses this file 006 to you under the Apache License, Version 2.0 (the 007 "License"); you may not use this file except in compliance 008 with the License. You may obtain a copy of the License at 009 010 http://www.apache.org/licenses/LICENSE-2.0 011 012 Unless required by applicable law or agreed to in writing, 013 software distributed under the License is distributed on an 014 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 KIND, either express or implied. See the License for the 016 specific language governing permissions and limitations 017 under the License. 018 */ 019package org.apache.wiki.pages.haddock; 020 021import com.codeborne.selenide.CollectionCondition; 022import com.codeborne.selenide.ElementsCollection; 023import com.codeborne.selenide.Selenide; 024import org.apache.wiki.pages.Page; 025import org.openqa.selenium.By; 026 027import java.util.List; 028 029/** 030 * Actions available on the Search Results page. 031 */ 032public class SearchResultsPage implements HaddockPage { 033 034 private static final String SEARCH_PAGE_NAME_RESULTS = ".wikitable.table-striped tr:not(:first-child) td:first-child"; 035 036 /** 037 * Open the search results page with a given query text to search for. 038 * 039 * @param pageName Wiki page name to View. 040 * @return {@link ViewWikiPage} instance, to allow chaining of actions. 041 */ 042 public static SearchResultsPage open( final String pageName ) { 043 return Page.withUrl( Page.baseUrl() + "/Search.jsp?query=" + pageName ).openAs( new SearchResultsPage() ); 044 } 045 046 /** 047 * Returns the search result page names. 048 * 049 * @return the list of page names returned by the search query. 050 */ 051 public List< String > pagesFound() { 052 return Selenide.$$( By.cssSelector( SEARCH_PAGE_NAME_RESULTS ) ).texts(); 053 } 054 055 /** 056 * Ensures that the given page names are present on the search results. 057 * 058 * @param pageNames page names to look for. 059 * @return {@link SearchResultsPage} instance, to allow chaining of actions. 060 */ 061 public SearchResultsPage shouldContain( final String... pageNames ) { 062 final ElementsCollection resultsTableRows = Selenide.$$( By.cssSelector( SEARCH_PAGE_NAME_RESULTS ) ); 063 for( final String pageName : pageNames ) { 064 resultsTableRows.shouldHave( CollectionCondition.itemWithText( pageName ) ); 065 } 066 067 return this; 068 } 069 070 /** 071 * Navigates to a view page from the search results. 072 * 073 * @param result wikipage name to navigate to. 074 * @return {@link ViewWikiPage} instance, to allow chaining of actions. 075 */ 076 public ViewWikiPage navigateTo(final String result ) { 077 Selenide.$( By.cssSelector( ".wikitable.table-striped" ) ).find( By.linkText( result ) ).click(); 078 return new ViewWikiPage(); 079 } 080 081}