gt: 		switch (itemName) {
context: /*
   * Copyright (C) 2007-2019 Crafter Software Corporation. All Rights Reserved.
   *
   * This program is free software: you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation, either version 3 of the License, or
   * (at your option) any later version.
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   *
   * You should have received a copy of the GNU General Public License
   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
   */
  package org.craftercms.studio.test.cases.contenttestcases;
  
  import java.util.List;
  
  import org.apache.logging.log4j.LogManager;
  import org.apache.logging.log4j.Logger;
  import org.craftercms.studio.test.cases.StudioBaseTest;
  import org.openqa.selenium.By;
  import org.openqa.selenium.TimeoutException;
  import org.openqa.selenium.WebElement;
  import org.openqa.selenium.support.ui.Select;
  import org.testng.Assert;
  import org.testng.annotations.BeforeMethod;
  import org.testng.annotations.Parameters;
  import org.testng.annotations.Test;
  
  /**
   * 
   * @author luishernandez
   *
   */
  // Test Case Studio- Site Content ID:40, 44
  public class FileRenameThenPublishTest extends StudioBaseTest {
  
  	private String createFormFrameElementCss;
  	private String createFormSaveAndCloseElement;
  	private String configurationSetUp;
  	private String dashboardLink;
  	private String editRecentlyContentCreated;
  	private String recentActivityContentURL;
  	private String recentActivityContentName;
  	private String fooContentXpath;
  	private String editURLButton;
  	private String warningTitle;
  	private String warningOkButton;
  	private String filenameInput;
  	private String selectAllSegmentsCheckBox;
  	private String selectEntertaimentCategoryCheckBox;
  	private String articlesFolder;
  	private String folder2016Locator;
  	private String publishOptionXpath;
  	private String topNavStatusIcon;
  	private String recentlyActivitySelectAll;
  	private String recentlyActivityTable;
  	private String recentlyActivityItemName;
  	private String recentlyActivityItemIcon;
  	private String recentlyActivityItemURL;
  	private String recentlyActivityItemConfigurationEditedIcon;
  	private int numberOfAttemptsForElementsDisplayed;
  	private static Logger logger = LogManager.getLogger(FileRenameThenPublishTest.class);
  
  	@Parameters({"testId", "blueprint"})
  	@BeforeMethod
  	public void beforeTest(String testId, String blueprint) {
  		apiTestHelper.createSite(testId, "", blueprint);
  		int exitCode = this.getWebDriverManager().goToDeliveryFolderAndExecuteSiteScriptThroughCommandLine(testId, "init");
  		Assert.assertEquals(exitCode, 0, "Init site process failed");
  		createFormFrameElementCss = uiElementsPropertiesManager.getSharedUIElementsLocators()
  				.getProperty("complexscenarios.general.createformframe");
  		createFormSaveAndCloseElement = uiElementsPropertiesManager.getSharedUIElementsLocators()
  				.getProperty("complexscenarios.general.saveandclosebutton");
  		dashboardLink = uiElementsPropertiesManager.getSharedUIElementsLocators()
  				.getProperty("general.dashboard.dashboardlink");
  		editRecentlyContentCreated = uiElementsPropertiesManager.getSharedUIElementsLocators()
  				.getProperty("rightclick.edit.option");
  		recentActivityContentURL = uiElementsPropertiesManager.getSharedUIElementsLocators()
  				.getProperty("dashboard.myrecentactivity.contenturl");
  		recentActivityContentName = uiElementsPropertiesManager.getSharedUIElementsLocators()
  				.getProperty("dashboard.myrecentactivity.contentname");
  		fooContentXpath = uiElementsPropertiesManager.getSharedUIElementsLocators().getProperty("general.foocontent");
  		editURLButton = uiElementsPropertiesManager.getSharedUIElementsLocators().getProperty("frame1.editurlbutton");
  		warningTitle = uiElementsPropertiesManager.getSharedUIElementsLocators()
  				.getProperty("frame1.warning.warningtitle");
  		warningOkButton = uiElementsPropertiesManager.getSharedUIElementsLocators()
  				.getProperty("frame1.warning.okbutton");
  		filenameInput = uiElementsPropertiesManager.getSharedUIElementsLocators().getProperty("frame1.filenameinput");
  		selectAllSegmentsCheckBox = uiElementsPropertiesManager.getSharedUIElementsLocators()
  				.getProperty("frame2.article_select_all_segments_checkbox");
  		selectEntertaimentCategoryCheckBox = uiElementsPropertiesManager.getSharedUIElementsLocators()
  				.getProperty("frame2.select_entertaiment_Category_CheckBox");
  		articlesFolder = uiElementsPropertiesManager.getSharedUIElementsLocators()
  				.getProperty("dashboard.articlesfolder");
  		folder2016Locator = uiElementsPropertiesManager.getSharedUIElementsLocators()
  				.getProperty("general.articles.2016folder");
  		fooContentXpath = uiElementsPropertiesManager.getSharedUIElementsLocators().getProperty("general.foocontent");
  		publishOptionXpath = uiElementsPropertiesManager.getSharedUIElementsLocators()
  				.getProperty("rightclick.approveandpublish.option");
  		topNavStatusIcon = uiElementsPropertiesManager.getSharedUIElementsLocators()
  				.getProperty("general.statustopbaricon");
  		recentlyActivitySelectAll = uiElementsPropertiesManager.getSharedUIElementsLocators()
  				.getProperty("dashboard.myrecentactivity.selectall");
  		recentlyActivityTable = uiElementsPropertiesManager.getSharedUIElementsLocators()
  				.getProperty("dashboard.myrecentactivity.tablebody");
  		recentlyActivityItemName = uiElementsPropertiesManager.getSharedUIElementsLocators()
  				.getProperty("dashboard.myrecentactivity.itemname");
  		recentlyActivityItemIcon = uiElementsPropertiesManager.getSharedUIElementsLocators()
  				.getProperty("dashboard.myrecentactivity.itemicon");
  		recentlyActivityItemURL = uiElementsPropertiesManager.getSharedUIElementsLocators()
  				.getProperty("dashboard.myrecentactivity.itemurl");
  		recentlyActivityItemConfigurationEditedIcon = uiElementsPropertiesManager.getSharedUIElementsLocators()
  				.getProperty("dashboard.myrecentactivity.itemconfigurationeditedicon");
  		this.numberOfAttemptsForElementsDisplayed = Integer.parseInt(constantsPropertiesManager
  				.getSharedExecutionConstants().getProperty("crafter.numberofattemptsforelementdisplayed"));
  		configurationSetUp = "<content-type name=\"/page/article\" is-wcm-type=\"true\">"
  				+ "<label>Page - Article</label>" + "<form>/page/article</form>"
  				+ "<form-path>simple</form-path>"
  				+ "<model-instance-path>NOT-USED-BY-SIMPLE-FORM-ENGINE</model-instance-path>"
  				+ "<file-extension>xml</file-extension>" + "<content-as-folder>false</content-as-folder>"
  				+ "<previewable>true</previewable>" + "<noThumbnail>false</noThumbnail>"
  				+ "<image-thumbnail>page-article.png</image-thumbnail>" + "<paths>"
  				+ "<includes><pattern>^/site/website/articles/.*</pattern></includes>" + "</paths>"
  				+ "</content-type>";
  	}
  
  	public void modifyPageXMLDefinition() {
  		previewPage.modifyPageXMLDefinitionContentAsFolderForPageArticle(configurationSetUp);
  	}
  
  	public void createNewPageArticle(String folderLocation) {
  		logger.info("Create Article Content");
  		this.getWebDriverManager().waitForAnimation();
  		previewPage.createPageArticleContentUsingUploadedImage("foo", "foo", "foo", folderLocation,
  				selectEntertaimentCategoryCheckBox, selectAllSegmentsCheckBox, "foo", "foo", "foo", "foo");
  
  		this.getWebDriverManager().waitUntilSidebarOpens();
  	}
  
  	public void setup(String siteId) {
  		loginPage.loginToCrafter();
  		homePage.goToPreviewPage(siteId);
  		previewPage.clickSidebar();
  		this.modifyPageXMLDefinition();
  		this.getWebDriverManager().waitUntilSidebarOpens();
  		this.getWebDriverManager().waitForAnimation();
  		dashboardPage.expandHomeTree();
  
  		// expand Articles folder
  		this.getWebDriverManager().driverWaitUntilElementIsPresentAndDisplayedAndClickable("xpath", articlesFolder);
  		dashboardPage.expandParentFolder(articlesFolder);
  
  		this.getWebDriverManager().waitForAnimation();
  		dashboardPage.expandParentFolder(folder2016Locator);
  
  		this.getWebDriverManager().waitForAnimation();
  		dashboardPage.expandParentFolder(
  				folder2016Locator + "/../../../../../div[@class='ygtvchildren']//span[text()='12']");
  		this.createNewPageArticle(folder2016Locator + "/../../../../../div[@class='ygtvchildren']//span[text()='12']");
  
  		// reload page
  		getWebDriverManager().getDriver().navigate().refresh();
  		getWebDriverManager().waitUntilHomeIsOpened();
  		Assert.assertTrue(this.getWebDriverManager()
  				.driverWaitUntilElementIsPresentAndDisplayedAndClickable("xpath", fooContentXpath).isDisplayed());
  
  		this.getWebDriverManager().contextClick("xpath", fooContentXpath, false);
  		getWebDriverManager().usingContextMenu(() -> {
  			WebElement publishOption = this.getWebDriverManager().driverWaitUntilElementIsPresentAndDisplayed("xpath",
  					publishOptionXpath);
  			publishOption.click();
  		}, "Pages");
  
  		// submit
  		previewPage.clickOnSubmitButtonOfApprovePublish();
  		this.getWebDriverManager().waitForAnimation();
  
  		for (int i = 0; i < numberOfAttemptsForElementsDisplayed; i++) {
  			try {
  				this.getWebDriverManager().driverWaitUntilElementIsPresentAndDisplayedAndClickable("xpath", fooContentXpath)
  						.click();
  				this.getWebDriverManager().waitUntilAttributeContains("xpath", topNavStatusIcon, "class", "undefined live");
  				break;
  			} catch (TimeoutException e) {
  				this.getWebDriverManager().takeScreenshot("PageNotPublishedOnTopNavBar");
  				logger.warn("Content page is not published yet, checking again if it has published icon on top bar");
  				getWebDriverManager().getDriver().navigate().refresh();
  			}
  		}
  
  		String elementClassValue = this.getWebDriverManager().getDriver().findElement(By.xpath(topNavStatusIcon))
  				.getAttribute("class");
  		Assert.assertTrue(elementClassValue.contains("undefined live"));
  
  		this.goToDashboardAndCheck();
  	}
  
  	public void goToDashboardAndCheck() {
  		// click on dashboard
  		this.getWebDriverManager().driverWaitUntilElementIsPresentAndDisplayedAndClickable("xpath", dashboardLink);
  		this.getWebDriverManager().driverWaitUntilElementIsPresentAndDisplayedAndClickable("xpath", dashboardLink).click();
  
  		this.getWebDriverManager().waitUntilDashboardWidgetsAreLoaded();
  		this.getWebDriverManager().driverWaitUntilElementIsPresentAndDisplayedAndClickable("xpath", recentlyActivitySelectAll);
  		Select categoriesDropDown = new Select(
  				this.getWebDriverManager().driverWaitUntilElementIsPresentAndDisplayed("xpath", recentlyActivitySelectAll));
  
  		categoriesDropDown.selectByValue("all");
  
  		// check items on My Recent Activity widget
  		this.getWebDriverManager().waitUntilDashboardLoadingAnimationIsNotDisplayedOnRecentActivity();
  		this.getWebDriverManager().driverWaitUntilElementIsPresentAndDisplayed("xpath", recentActivityContentName);
  		this.getWebDriverManager().driverWaitUntilElementIsPresentAndDisplayed("xpath", recentActivityContentURL);
  
  		this.getWebDriverManager().waitForFullExpansionOfTree();
  		List<WebElement> recentActivityItems = this.getWebDriverManager()
  				.driverWaitUntilElementIsPresentAndDisplayed("xpath", recentlyActivityTable)
  				.findElements(By.tagName("tr"));
  
  		for (WebElement webElement : recentActivityItems) {
  			this.checkRecentActivityItems(webElement);
  		}
  
  	}
  
  	public void checkRecentActivityItems(WebElement element) {
  		this.getWebDriverManager().waitForAnimation();
  		String itemName = element.findElement(By.xpath(recentlyActivityItemName)).getText();
  		String itemIconClass = element.findElement(By.xpath(recentlyActivityItemIcon)).getAttribute("class");
  		String itemURL = element.findElement(By.xpath(recentlyActivityItemURL)).getText();
  
  