001/* 002 * (C) Copyright 2016 Nuxeo SA (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 * Anahide Tchertchian 018 * Gabriel Barata 019 * Yannis JULIENNE 020 */ 021package org.nuxeo.functionaltests.pages.tabs; 022 023import org.nuxeo.functionaltests.AbstractTest; 024import org.nuxeo.functionaltests.AjaxRequestManager; 025import org.nuxeo.functionaltests.Required; 026import org.nuxeo.functionaltests.contentView.ContentViewElement; 027import org.nuxeo.functionaltests.pages.AbstractPage; 028import org.nuxeo.functionaltests.pages.DocumentBasePage; 029import org.nuxeo.functionaltests.pages.forms.DublinCoreCreationDocumentFormPage; 030import org.openqa.selenium.Alert; 031import org.openqa.selenium.By; 032import org.openqa.selenium.NoSuchElementException; 033import org.openqa.selenium.WebDriver; 034import org.openqa.selenium.WebElement; 035import org.openqa.selenium.support.FindBy; 036 037import static org.nuxeo.functionaltests.Constants.SECTION_TYPE; 038 039import static org.junit.Assert.assertEquals; 040import static org.junit.Assert.assertNotNull; 041 042/** 043 * Section content tab. 044 * 045 * @since 8.3 046 */ 047public class SectionContentTabSubPage extends DocumentBasePage { 048 049 @Required 050 @FindBy(id = "section_content") 051 WebElement contentForm; 052 053 @FindBy(linkText = "New") 054 WebElement newButton; 055 056 @FindBy(id = "nxw_contentViewActions_refreshContentView_form:nxw_contentViewActions_refreshContentView") 057 WebElement refreshContentLink; 058 059 public SectionContentTabSubPage(WebDriver driver) { 060 super(driver); 061 } 062 063 public ContentViewElement getContentView() { 064 return AbstractTest.getWebFragment(By.id("cv_section_content_0_panel"), ContentViewElement.class); 065 } 066 067 public DublinCoreCreationDocumentFormPage getSectionCreatePage() { 068 newButton.click(); 069 WebElement fancyBox = AbstractPage.getFancyBoxContent(); 070 // find the link to doc type that needs to be created 071 WebElement link = fancyBox.findElement(By.linkText(SECTION_TYPE)); 072 assertNotNull(link); 073 link.click(); 074 return asPage(DublinCoreCreationDocumentFormPage.class); 075 } 076 077 public DocumentBasePage removeDocument(String documentTitle) { 078 getContentView().checkByTitle(documentTitle).getSelectionActionByTitle(ContentTabSubPage.DELETE).click(); 079 Alert alert = driver.switchTo().alert(); 080 assertEquals("Delete selected document(s)?", alert.getText()); 081 alert.accept(); 082 return asPage(DocumentBasePage.class); 083 } 084 085 public SectionContentTabSubPage unpublishDocument(String documentTitle) { 086 getContentView().checkByTitle(documentTitle).getSelectionActionByTitle("Unpublish").click(); 087 return asPage(SectionContentTabSubPage.class); 088 } 089 090 protected ContentViewElement getElement() { 091 return AbstractTest.getWebFragment(By.id("cv_section_content_0_panel"), ContentViewElement.class); 092 } 093 094 public DocumentBasePage goToDocument(String documentTitle) { 095 getElement().clickOnItemTitle(documentTitle); 096 return asPage(DocumentBasePage.class); 097 } 098 099 public boolean hasDocumentLink(String title) { 100 try { 101 WebElement element = getElement().findElement(By.linkText(title)); 102 return element != null; 103 } catch (NoSuchElementException e) { 104 return false; 105 } 106 } 107 108 /** 109 * @since 8.3 110 */ 111 public boolean hasNewButton() { 112 try { 113 return newButton.isDisplayed(); 114 } catch (NoSuchElementException e) { 115 return false; 116 } 117 } 118 119 /** 120 * @since 8.3 121 */ 122 public SectionContentTabSubPage refreshContent() { 123 AjaxRequestManager arm = new AjaxRequestManager(driver); 124 arm.begin(); 125 refreshContentLink.click(); 126 arm.end(); 127 return asPage(SectionContentTabSubPage.class); 128 } 129 130}