package test_classes; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.concurrent.TimeUnit; import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang3.ArrayUtils; import org.openqa.selenium.By; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Optional; import org.testng.annotations.Parameters; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import abstract_classes.BaseTest; import qsf_page_object_pattern.BackEnd.BackEnd_CmsEditPage; import qsf_page_object_pattern.BackEnd.BackEnd_CmsPage; import qsf_page_object_pattern.BackEnd.BackEnd_SideBlocksAddPage; import qsf_page_object_pattern.BackEnd.BackEnd_SideBlocksEditPage; import qsf_page_object_pattern.BackEnd.BackEnd_SideBlocksPage; import qsf_page_object_pattern.BackEnd.BackEnd_SideBlocksReorderPage; import qsf_page_object_pattern.FrontEnd.FrontEnd_CmsPage; import tools.DynamicDataProvider; public class be_sideBlock_test extends BaseTest{ final String addedAlert = "Side Block has been added"; final String updatedAlert = "Side Block has been updated"; final String deletedAlert = "Side Block has been deleted"; final String reorderedAlert = "Side Blocks have been reordered"; final String modulePath = "site-content/side-block"; public String pageId = null; public String pageAlias = null; public String pageTitle = null; DynamicDataProvider dp = new DynamicDataProvider("BE_SideBlocks.json"); private String searchText; public be_sideBlock_test(){ } @DataProvider(name = "Valid_Page") public Object[][] createDataPage() { DynamicDataProvider pageDP = new DynamicDataProvider("BE_CmsPage.json"); return pageDP.GenerateTreeRecord("existingValue"); } @DataProvider(name = "Incorrect_Data") public Object[][] createData2() { //dp.GenerateRequiredCheck(); return dp.GenerateFullCheck(); } @DataProvider(name = "Valid_Data") public Object[][] createData1() { return dp.GenerateTreeRecord("existingValue"); } @DataProvider(name = "Edit_Data") public Object[][] createData3() { return dp.GenerateTreeRecord("editValue"); } @DataProvider(name = "CleanUp_Data") public Object[][] createData4() { //return dp.GenerateTreeRecord("editValue"); return ArrayUtils.addAll(dp.GenerateTreeRecord("editValue"), dp.GenerateTreeRecord("existingValue")); } @Parameters({"browser"}) @BeforeClass public void SetUp(@Optional("Firefox") String browser){ SetDriver(browser); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); loginToAdmin(); } @Test(dataProvider = "Valid_Page", description = "") public void TestNewCmsPage(Map> fields){ driver.get(settings.http + settings.adminUrl + "site-content/cms" + "?action=new"); BackEnd_CmsEditPage be_cmsEditPage = new BackEnd_CmsEditPage(driver); be_cmsEditPage.expandFckEditorFields(); BackEnd_CmsPage be_cmsPage = be_cmsEditPage.addNew(fields); assertTrue(be_cmsPage.getAlertInfo().contains(be_cms_test.addedAlert), "Expected '"+be_cms_test.addedAlert+"' to appear on page, but found: '"+be_cmsPage.getAlertInfo()+"'"); pageAlias = fields.get("meta[alias]").get("value"); pageTitle = fields.get("meta[menuTitle]").get("value"); String adminPageLink = be_cmsPage.getPageLinkByTitle(fields.get("meta[menuTitle]").get("value")); Map> params = getQueryParams(adminPageLink); pageId = params.get("id").get(0); } @Test(dataProvider = "Valid_Data", description = "", dependsOnMethods="TestNewCmsPage") public void TestValidSideBlock(Map> fields){ if(fields.containsKey("idPage[]")&&fields.get("idPage[]").get("value")!=""){ Map idPageData = fields.get("idPage[]"); idPageData.put("value", pageId); fields.put("idPage[]", new HashMap(idPageData)); } driver.get(settings.http + settings.adminUrl + modulePath); BackEnd_SideBlocksPage be_sideBlocksPage = new BackEnd_SideBlocksPage(driver); BackEnd_SideBlocksAddPage be_sideBlocksAddPage = be_sideBlocksPage.openAddNewForm(); be_sideBlocksPage = be_sideBlocksAddPage.addNew(fields); assertTrue(be_sideBlocksPage.getAlertInfo().contains(addedAlert), "Expected '"+addedAlert+"' to appear on page, but found: '"+be_sideBlocksPage.getAlertInfo()+"'"); searchText = fields.get("title").get("value"); be_sideBlocksPage.doSearch(searchText); Map FirstRecordData = be_sideBlocksPage.getFirstRecordDataFromTable(); assertTrue(fields.get("title").get("value").equals(FirstRecordData.get("title")), "Expected last title to be '"+fields.get("title").get("value")+"', but found '"+FirstRecordData.get("title")+"'"); assertTrue(FirstRecordData.get("content").contains(fields.get("content").get("value")), "Expected content to be '"+fields.get("content").get("value")+"', but found '"+FirstRecordData.get("content")+"'"); BackEnd_SideBlocksEditPage be_sideBlocksEditPage = be_sideBlocksPage.editFirstRecordFromTable(); for(Entry> field : fields.entrySet()){ switch (field.getValue().get("type")) { case "fck-editor": { assertTrue(be_sideBlocksEditPage.getFormFieldValue(field.getKey(), field.getValue().get("type")).contains(field.getValue().get("value")), "Values in Edit Mode for "+field.getKey()+"do not match with input values"); } break; case "file": { String fileNameWithOutExt = FilenameUtils.removeExtension(field.getValue().get("value")); assertTrue(be_sideBlocksEditPage.getFormFieldValue(field.getKey(), field.getValue().get("type")).contains(fileNameWithOutExt), "File for "+field.getKey()+" doesn't match"); } break; default: assertEquals(be_sideBlocksEditPage.getFormFieldValue(field.getKey(), field.getValue().get("type")), field.getValue().get("value"), "Values in Edit Mode for "+field.getKey()+"do not match with input values"); } } be_sideBlocksEditPage.clickCancel(); } @Test(dataProvider = "Valid_Data", dependsOnMethods="TestValidSideBlock", priority=2, description = "") public void TestFrontEnd(Map> fields){ driver.get(settings.http + settings.siteUrl + pageAlias); FrontEnd_CmsPage fe_cmsPage = new FrontEnd_CmsPage(driver); for(Entry> field : fields.entrySet()){ if(fe_cmsPage.getSideBlockData(field.getKey())!=null){ switch (field.getKey()) { case "content":{ assertTrue(fe_cmsPage.getSideBlockData(field.getKey()).contains(field.getValue().get("value")), "Value for '"+field.getKey()+"' did not match with Front End"); } break; default:{ assertEquals(fe_cmsPage.getSideBlockData(field.getKey()), field.getValue().get("value"), "Value for '"+field.getKey()+"' did not match with Front End"); } } } } } @Test(dataProvider = "Incorrect_Data", dependsOnMethods="TestValidSideBlock", priority=2, enabled=true, description = "") public void TestIncorrectSideBlock(Map> fieldsData, Map> expectedErrors) throws InterruptedException{ driver.get(settings.http + settings.adminUrl + modulePath); BackEnd_SideBlocksPage be_sideBlocksPage = new BackEnd_SideBlocksPage(driver); BackEnd_SideBlocksAddPage be_sideBlocksAddPage = be_sideBlocksPage.openAddNewForm(); be_sideBlocksAddPage = be_sideBlocksAddPage.submitIncorrectData(fieldsData); Map>realFormErrors = be_sideBlocksAddPage.getFieldsAlerts(); compareFormErrors(realFormErrors, expectedErrors); } @Test(dataProvider = "Edit_Data", dependsOnMethods="TestValidSideBlock", priority=3, enabled=true, description = "") public void TestEditSideBlock(Map> fields){ if(fields.containsKey("idPage[]")&&fields.get("idPage[]").get("value")!=""){ Map idPageData = fields.get("idPage[]"); idPageData.put("value", pageId); fields.put("idPage[]", new HashMap(idPageData)); } driver.get(settings.http + settings.adminUrl + modulePath); BackEnd_SideBlocksPage be_sideBlocksPage = new BackEnd_SideBlocksPage(driver); be_sideBlocksPage.doSearch(searchText); BackEnd_SideBlocksEditPage be_sideBlocksEditPage = be_sideBlocksPage.editFirstRecordFromTable(); be_sideBlocksPage = be_sideBlocksEditPage.editRecord(fields); assertTrue(be_sideBlocksPage.getAlertInfo().contains(updatedAlert), "Expected '"+updatedAlert+"' to appear on page, but found: '"+be_sideBlocksPage.getAlertInfo()+"'"); searchText = fields.get("title").get("value"); be_sideBlocksPage.doSearch(searchText); Map FirstRecordData = be_sideBlocksPage.getFirstRecordDataFromTable(); assertTrue(fields.get("title").get("value").equals(FirstRecordData.get("title")), "Expected last title to be '"+fields.get("title").get("value")+"', but found '"+FirstRecordData.get("title")+"'"); assertTrue(FirstRecordData.get("content").contains(fields.get("content").get("value")), "Expected content to be '"+fields.get("content").get("value")+"', but found '"+FirstRecordData.get("content")+"'"); be_sideBlocksEditPage = be_sideBlocksPage.editFirstRecordFromTable(); for(Entry> field : fields.entrySet()){ switch (field.getValue().get("type")) { case "fck-editor": { assertTrue(be_sideBlocksEditPage.getFormFieldValue(field.getKey(), field.getValue().get("type")).contains(field.getValue().get("value")), "Values in Edit Mode for "+field.getKey()+"do not match with input values"); } break; case "file": { String fileNameWithOutExt = FilenameUtils.removeExtension(field.getValue().get("value")); assertTrue(be_sideBlocksEditPage.getFormFieldValue(field.getKey(), field.getValue().get("type")).contains(fileNameWithOutExt), "File for "+field.getKey()+" doesn't match"); } break; default: assertEquals(be_sideBlocksEditPage.getFormFieldValue(field.getKey(), field.getValue().get("type")), field.getValue().get("value"), "Values in Edit Mode for "+field.getKey()+"do not match with input values"); } } } @Test(dataProvider = "Incorrect_Data", dependsOnMethods="TestEditSideBlock", priority=5, enabled=true, description = "") public void TestIncorrectEditSideBlock(Map> fieldsData, Map> expectedErrors) throws InterruptedException{ driver.get(settings.http + settings.adminUrl + modulePath); BackEnd_SideBlocksPage be_sideBlocksPage = new BackEnd_SideBlocksPage(driver); be_sideBlocksPage.doSearch(searchText); BackEnd_SideBlocksEditPage be_sideBlocksEditPage = be_sideBlocksPage.editFirstRecordFromTable(); Map> clearData = dp.GenerateClearForm(); be_sideBlocksEditPage.clearForm(clearData); be_sideBlocksEditPage = be_sideBlocksEditPage.submitIncorrectData(fieldsData); Map>realFormErrors = be_sideBlocksEditPage.getFieldsAlerts(); compareFormErrors(realFormErrors, expectedErrors); } @Test(dataProvider = "Valid_Data", dependsOnMethods = "TestEditSideBlock", priority=4, description = "") public void TestAnotherValidSideBlock(Map> fields){ if(fields.containsKey("idPage[]")&&fields.get("idPage[]").get("value")!=""){ Map idPageData = fields.get("idPage[]"); idPageData.put("value", pageId); fields.put("idPage[]", new HashMap(idPageData)); } driver.get(settings.http + settings.adminUrl + modulePath); BackEnd_SideBlocksPage be_sideBlocksPage = new BackEnd_SideBlocksPage(driver); BackEnd_SideBlocksAddPage be_sideBlocksAddPage = be_sideBlocksPage.openAddNewForm(); be_sideBlocksPage = be_sideBlocksAddPage.addNew(fields); assertTrue(be_sideBlocksPage.getAlertInfo().contains(addedAlert), "Expected '"+addedAlert+"' to appear on page, but found: '"+be_sideBlocksPage.getAlertInfo()+"'"); searchText = fields.get("title").get("value"); be_sideBlocksPage.doSearch(searchText); Map FirstRecordData = be_sideBlocksPage.getFirstRecordDataFromTable(); assertTrue(fields.get("title").get("value").equals(FirstRecordData.get("title")), "Expected last title to be '"+fields.get("title").get("value")+"', but found '"+FirstRecordData.get("title")+"'"); assertTrue(FirstRecordData.get("content").contains(fields.get("content").get("value")), "Expected content to be '"+fields.get("content").get("value")+"', but found '"+FirstRecordData.get("content")+"'"); BackEnd_SideBlocksEditPage be_sideBlocksEditPage = be_sideBlocksPage.editFirstRecordFromTable(); for(Entry> field : fields.entrySet()){ switch (field.getValue().get("type")) { case "fck-editor": { assertTrue(be_sideBlocksEditPage.getFormFieldValue(field.getKey(), field.getValue().get("type")).contains(field.getValue().get("value")), "Values in Edit Mode for "+field.getKey()+"do not match with input values"); } break; case "file": { String fileNameWithOutExt = FilenameUtils.removeExtension(field.getValue().get("value")); assertTrue(be_sideBlocksEditPage.getFormFieldValue(field.getKey(), field.getValue().get("type")).contains(fileNameWithOutExt), "File for "+field.getKey()+" doesn't match"); } break; default: assertEquals(be_sideBlocksEditPage.getFormFieldValue(field.getKey(), field.getValue().get("type")), field.getValue().get("value"), "Values in Edit Mode for "+field.getKey()+"do not match with input values"); } } be_sideBlocksEditPage.clickCancel(); } @Test(dependsOnMethods="TestAnotherValidSideBlock", priority=5) public void TestReorderSideBlocks(){ driver.get(settings.http + settings.adminUrl + modulePath); BackEnd_SideBlocksPage be_sideBlocksPage = new BackEnd_SideBlocksPage(driver); be_sideBlocksPage.doSearchByPage(pageId); ListtitleOrder = be_sideBlocksPage.getTableTitlesByOrder(); BackEnd_SideBlocksReorderPage be_sideBlocksReorderPage = be_sideBlocksPage.openReorderPage(); String firstTitle = titleOrder.get(0); be_sideBlocksPage = be_sideBlocksReorderPage.moveElementToBottom(firstTitle); assertTrue(be_sideBlocksPage.getAlertInfo().contains(reorderedAlert), "Expected '"+reorderedAlert+"' to appear on page, but found: '"+be_sideBlocksPage.getAlertInfo()+"'"); titleOrder = be_sideBlocksPage.getTableTitlesByOrder(); assertEquals(titleOrder.get(titleOrder.size() - 1), firstTitle); driver.get(settings.http + settings.siteUrl + pageAlias); FrontEnd_CmsPage fe_cmsPage = new FrontEnd_CmsPage(driver); ListfeTitleOrder = fe_cmsPage.getSideBlocksTitleByOrder(); assertTrue(feTitleOrder.get(feTitleOrder.size()-1).equals(firstTitle)); driver.get(settings.http + settings.adminUrl + modulePath); be_sideBlocksPage = new BackEnd_SideBlocksPage(driver); be_sideBlocksPage.doSearchByPage(pageId); titleOrder = be_sideBlocksPage.getTableTitlesByOrder(); be_sideBlocksReorderPage = be_sideBlocksPage.openReorderPage(); String lastTitle = titleOrder.get(titleOrder.size() - 1); be_sideBlocksPage = be_sideBlocksReorderPage.moveElementToTop(lastTitle); assertTrue(be_sideBlocksPage.getAlertInfo().contains(reorderedAlert), "Expected '"+reorderedAlert+"' to appear on page, but found: '"+be_sideBlocksPage.getAlertInfo()+"'"); titleOrder = be_sideBlocksPage.getTableTitlesByOrder(); assertEquals(titleOrder.get(0), lastTitle); driver.get(settings.http + settings.siteUrl + pageAlias); fe_cmsPage = new FrontEnd_CmsPage(driver); feTitleOrder = fe_cmsPage.getSideBlocksTitleByOrder(); assertTrue(feTitleOrder.get(0).equals(lastTitle)); } @Test(dataProvider = "Valid_Data", dependsOnMethods = "TestAnotherValidSideBlock", priority=6, description = "") public void TestDisablingVisibility(Map> fields){ driver.get(settings.http + settings.adminUrl + modulePath); BackEnd_SideBlocksPage be_sideBlocksPage = new BackEnd_SideBlocksPage(driver); be_sideBlocksPage.doSearch(fields.get("title").get("value")); BackEnd_SideBlocksEditPage be_sideBlocksEditPage = be_sideBlocksPage.editFirstRecordFromTable(); be_sideBlocksEditPage.inputFormFieldValue("show", "false", "checkbox"); driver.findElement(be_sideBlocksEditPage.submitBtn).click(); be_sideBlocksPage = new BackEnd_SideBlocksPage(driver); assertTrue(be_sideBlocksPage.getAlertInfo().contains(updatedAlert), "Expected '"+updatedAlert+"' to appear on page, but found: '"+be_sideBlocksPage.getAlertInfo()+"'"); driver.get(settings.http + settings.siteUrl + pageAlias); FrontEnd_CmsPage fe_cmsPage = new FrontEnd_CmsPage(driver); ListtitleOrder = fe_cmsPage.getSideBlocksTitleByOrder(); assertFalse(titleOrder.contains(fields.get("title").get("value")), "Disabled Item is still present on the page "+settings.http + settings.siteUrl + pageAlias); } @Test(dataProvider = "CleanUp_Data", dependsOnMethods="TestAnotherValidSideBlock", priority=7, description = "") public void cleanUpSideBlocks(Map> fields){ driver.get(settings.http + settings.adminUrl + modulePath); BackEnd_SideBlocksPage be_sideBlocksPage = new BackEnd_SideBlocksPage(driver); searchText = fields.get("title").get("value"); be_sideBlocksPage.doSearch(searchText); try { be_sideBlocksPage.deleteFirstRecordFromTable(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } assertTrue(be_sideBlocksPage.getAlertInfo().contains(deletedAlert), "Expected '"+deletedAlert+"' to appear on page, but found: '"+be_sideBlocksPage.getAlertInfo()+"'"); } @Test(dependsOnMethods = "cleanUpSideBlocks") public void cleanUpCmsPage(){ driver.get(settings.http + settings.adminUrl + "site-content/cms"); BackEnd_CmsPage be_cmsPage = new BackEnd_CmsPage(driver); be_cmsPage = be_cmsPage.deletePage(pageTitle); assertTrue(be_cmsPage.getAlertInfo().contains(be_cms_test.deletedAlert), "Expected '"+be_cms_test.deletedAlert+"' to appear on page, but found: '"+be_cmsPage.getAlertInfo()+"'"); } @Test(priority=8, description = "") public void testCancelButton(){ driver.get(settings.http + settings.adminUrl + modulePath); BackEnd_SideBlocksPage be_sideBlocksPage = new BackEnd_SideBlocksPage(driver); BackEnd_SideBlocksAddPage be_sideBlockAddPage = be_sideBlocksPage.openAddNewForm(); be_sideBlocksPage = be_sideBlockAddPage.clickCancel(); be_sideBlocksPage.doSearch(searchText); driver.findElement(By.id("btnCancel")).click(); be_sideBlocksPage = new BackEnd_SideBlocksPage(driver); } @AfterClass public void tearDown(){ driver.quit(); //driver.close(); } }