001/* 002 * (C) Copyright 2017 Nuxeo (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Kevin Leturc 018 */ 019package org.nuxeo.functionaltests.contentView; 020 021import org.nuxeo.functionaltests.AbstractTest; 022import org.nuxeo.functionaltests.AjaxRequestManager; 023import org.nuxeo.functionaltests.Locator; 024import org.nuxeo.functionaltests.Required; 025import org.nuxeo.functionaltests.fragment.WebFragmentImpl; 026import org.nuxeo.functionaltests.pages.DocumentBasePage; 027import org.openqa.selenium.WebDriver; 028import org.openqa.selenium.WebElement; 029import org.openqa.selenium.support.FindBy; 030 031/** 032 * @since 9.1 033 */ 034public class PageNavigationControls extends WebFragmentImpl { 035 036 @Required 037 @FindBy(xpath = "//input[@alt='Rewind']") 038 WebElement firstButton; 039 040 @Required 041 @FindBy(xpath = "//input[@alt='Previous']") 042 WebElement previousButton; 043 044 @Required 045 @FindBy(className = "currentPageStatus") 046 WebElement status; 047 048 @Required 049 @FindBy(xpath = "//input[@alt='Next']") 050 WebElement nextButton; 051 052 @Required 053 @FindBy(xpath = "//input[@alt='Fast Forward']") 054 WebElement lastButton; 055 056 public PageNavigationControls(WebDriver driver, WebElement element) { 057 super(driver, element); 058 } 059 060 public DocumentBasePage first() { 061 return first(DocumentBasePage.class); 062 } 063 064 public <T extends DocumentBasePage> T first(Class<T> pageClassToProxy) { 065 return clickWithAjax(firstButton, pageClassToProxy); 066 } 067 068 public DocumentBasePage previous() { 069 return previous(DocumentBasePage.class); 070 } 071 072 public <T extends DocumentBasePage> T previous(Class<T> pageClassToProxy) { 073 return clickWithAjax(previousButton, pageClassToProxy); 074 } 075 076 public int getCurrentPage() { 077 return Integer.parseInt(status.getText().split("/")[0]); 078 } 079 080 public int getLastPage() { 081 return Integer.parseInt(status.getText().split("/")[1]); 082 } 083 084 public DocumentBasePage next() { 085 return next(DocumentBasePage.class); 086 } 087 088 public <T extends DocumentBasePage> T next(Class<T> pageClassToProxy) { 089 return clickWithAjax(nextButton, pageClassToProxy); 090 } 091 092 public DocumentBasePage last() { 093 return last(DocumentBasePage.class); 094 } 095 096 public <T extends DocumentBasePage> T last(Class<T> pageClassToProxy) { 097 return clickWithAjax(lastButton, pageClassToProxy); 098 } 099 100 protected <T extends DocumentBasePage> T clickWithAjax(WebElement button, Class<T> pageClassToProxy) { 101 AjaxRequestManager arm = new AjaxRequestManager(driver); 102 arm.begin(); 103 Locator.waitUntilEnabledAndClick(button); 104 arm.end(); 105 return AbstractTest.asPage(pageClassToProxy); 106 } 107 108}