Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.zaizi.automation.alfresco; import com.relevantcodes.extentreports.ExtentReports; import com.relevantcodes.extentreports.ExtentTest; import com.relevantcodes.extentreports.LogStatus; import com.zaizi.automation.alfresco.core.elements.Button; import com.zaizi.automation.alfresco.core.elements.Element; import com.zaizi.automation.alfresco.core.elements.Link; import com.zaizi.automation.alfresco.core.elements.TextField; import com.zaizi.automation.alfresco.core.info.TestCaseProperties; import com.zaizi.automation.alfresco.core.info.TestCaseValues; import com.zaizi.automation.alfresco.core.pages.CreateObjects; import com.zaizi.automation.alfresco.core.pages.LoginPage; import com.zaizi.automation.alfresco.core.pages.NavigateToPage; import com.zaizi.automation.alfresco.core.pages.RemoveObjects; import com.zaizi.automation.alfresco.core.pages.SearchObjects; import com.zaizi.automation.alfresco.core.pages.SiteDashboardPage; import com.zaizi.automation.alfresco.reportsetup.ExtentManager; import com.zaizi.automation.exceptions.IterableException; import java.io.File; import java.io.IOException; import org.apache.commons.io.FileUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.junit.BeforeClass; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.MethodSorters; import org.junit.runners.Parameterized; import org.openqa.selenium.By; import org.openqa.selenium.Dimension; import org.openqa.selenium.OutputType; import org.openqa.selenium.Point; import org.openqa.selenium.TakesScreenshot; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.remote.Augmenter; /** * * @author mketheeswaran */ @RunWith(value = Parameterized.class) @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class E_Vanila_FolderCreation_Chrome { /** * * Defining log4j */ public static final Logger LOGGER = LogManager.getLogger(E_Vanila_FolderCreation_Chrome.class.getName()); /** * * Defining Report */ static ExtentReports extent; //ExtentReports extent = new ExtentReports(TestCaseProperties.REPORT_TEST_PATH_CHROME+className+".html",true); /** * * Define WebDriver */ private static WebDriver driver; /** * Define siteName */ private String siteName; /** * Define siteId */ private String siteId; /** * Define Private site creator Name */ private String siteCreatorName; /** * Define isPrivate */ private Boolean isPrivate; /** * Define folderName */ private String folderName; /** * Define folderTitle */ private String folderTitle; /** * Define expectResult For Site */ private String expectedResult; /** * * Define ScreenShotName */ private String screenShotName; /** * * Define className */ public static String className = E_Vanila_FolderCreation_Chrome.class.getSimpleName(); /** * parameters pass via this constructor * */ public E_Vanila_FolderCreation_Chrome(String siteName, String siteId, String siteCreatorName, Boolean isPrivate, String expectedResult, String folderName, String folderTitle, String screenShotName) { this.siteName = siteName; this.siteId = siteId; this.siteCreatorName = siteCreatorName; this.isPrivate = isPrivate; this.expectedResult = expectedResult; this.folderName = folderName; this.folderTitle = folderTitle; this.screenShotName = screenShotName; } /** * * Declares parameters here * @return * * @throws Exception */ @Parameterized.Parameters() public static Iterable<Object[]> data() throws IterableException { LOGGER.info(TestCaseProperties.TEXT_TEST_PREPARING, "E_Vanila_FolderCreation_Chrome"); return TestCaseValues.documentLibraryTestValues("E_Vanila_FolderCreation_Chrome"); } /** * * Declares ExtentReports Configurations here * SeleniumWebdriver Specification (Set capabilities of Platform,BrowserName,Version) * RemoteWebdriver Specification(new RemoteWebDriver(new URL(NODEURL),capability)) * Grid Specification * * @return * * @throws Exception */ @BeforeClass public static void beforeClass() throws IOException { //Add CustomStyles to testReport //String css = "div.content{ width: 1422px;}"+ "div.filters{ width:1422px;}"; extent = ExtentManager.getReporter(TestCaseProperties.REPORT_TEST_PATH_CHROME + className + ".html"); //Initialize ExtentReport(driver,NameofReport) //Element.reportInitialChrome(driver, className); //test.config().addCustomStyles(css); //Define DocumentTitle of ExtentReport //test.config().documentTitle("Automation Report"); //Define ReportTitle of ExtentReport //test.config().reportTitle("Regression"); //Define ReportHeadLine of ExtentReport //test.config().reportHeadline("Login Testing"); } /** * * Setup Requirements for Below TestCase * user "privateuser" EXIST * */ @Test public void a_preRequest() throws InterruptedException, IOException { LOGGER.info(TestCaseProperties.TEXT_TEST_EXECUTING, "Setup Requirements"); ExtentTest test = extent.startTest("Setup Requirements"); LOGGER.info("1 ) user \"privateuser\" / \"privateuser\" exists,"); LOGGER.info("2 ) password of \"privateuser\" is \"1qaz@WSX\" "); test.log(LogStatus.INFO, "1 ) user \"privateuser\" / \"privateuser\" exists"); test.log(LogStatus.INFO, "2 ) password of \"privateuser\" is \"1qaz@WSX\" "); extent.endTest(test); extent.flush(); } /** * * @Test createSite * @return * * @throws Exception InterruptedException, IOException */ @Test public void b_createSite() throws InterruptedException, IOException { LOGGER.info(TestCaseProperties.TEXT_TEST_EXECUTING, "Create Site " + siteName); //Extent Report Start Configuration(testCaseName,Definition of testCase) ExtentTest test = extent.startTest("b_createSite", "Create site called \" " + siteName + " \",Is it private Site " + isPrivate); //Set the DriverType(BrowserName,Platform) driver = TestCaseProperties.driverType("Chrome", "WINDOWS"); // Set the upper left corner of the screen starting point driver.manage().window().setPosition(new Point(0, 0)); // define screen size java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); // define desired size Dimension maxWindowSize = new Dimension((int) screenSize.getWidth(), (int) screenSize.getHeight()); // Maximize the browser window according to your system's current // resolution(set desired size) driver.manage().window().setSize(maxWindowSize); //Get LoginScreen_URl from TestcaseProperties Values driver.get(TestCaseProperties.LOGIN_SCREEN_URL); LOGGER.info("Test case b_createSite started executing"); test.log(LogStatus.INFO, "Test case b_createSite started executing"); LOGGER.info("Accessing the Login Page"); test.log(LogStatus.INFO, "Accessing the Login Page"); LOGGER.info("Login as admin"); test.log(LogStatus.INFO, "Login as admin"); LoginPage loginPage = new LoginPage(driver); loginPage.loginAsAdmin(className, screenShotName); CreateObjects createObjects = new CreateObjects(driver); if (isPrivate) { LOGGER.info("CREATE PRIVATE SITE"); test.log(LogStatus.INFO, "CREATE PRIVATE SITE"); test.log(LogStatus.INFO, "Click \"Create Site\" "); test.log(LogStatus.INFO, "Enter " + siteName + " in \"site Name Field\" "); test.log(LogStatus.INFO, "Enter " + siteId + " in \"site URL Field\" "); test.log(LogStatus.INFO, "Check \"private\" Option"); test.log(LogStatus.INFO, "Click \"OK\" Button "); createObjects.createPrivateSite(siteName, siteId, expectedResult, className, screenShotName + "private2"); WebDriver augmentedDriver1 = new Augmenter().augment(driver); File screenshot1 = ((TakesScreenshot) augmentedDriver1).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(screenshot1, new File( TestCaseProperties.REPORT_TEST_PATH_CHROME + className + "/" + screenShotName + "58" + ".jpg")); test.log(LogStatus.INFO, "Snapshot below: " + test.addScreenCapture("./" + className + "/" + screenShotName + "58" + ".jpg")); System.out.println("Screenshot Taken Successfully!!!!"); //If Site Created if (Element.isElementPresent(driver, By.xpath("//div[@class='bd']/span[@class='wait']"))) { LOGGER.info(TestCaseProperties.TEXT_TEST_PASS, "Site " + siteName + " CREATED "); test.log(LogStatus.INFO, "<font color=blue>Site " + siteName + " CREATED <font> "); } //If Site IS NOT CREATED //Expected Result1=[COULD NOT CREATE SITE SINCE THE URL IS ALREADY USED] //ExpectedResult1==CurrentResult else { SiteDashboardPage siteDash1 = new SiteDashboardPage(driver); String siteErrorNotification = siteDash1.errorNotification(siteName, className, screenShotName); if (siteErrorNotification.toUpperCase().equals(expectedResult)) { LOGGER.info("Expected Results : " + expectedResult); test.log(LogStatus.INFO, "Expected Results : " + expectedResult); LOGGER.info("Current Test Results : " + siteErrorNotification); test.log(LogStatus.PASS, "Current Test Results : " + "<font color=green>" + siteErrorNotification + "<font>"); Button okaybtn = new Button(driver, By.xpath("//button[text()='OK']")); okaybtn.click(); } //ExpectedResult1!=CurrentResult[PROBLEM] else { LOGGER.error(TestCaseProperties.TEXT_TEST_FAIL, "Private Site " + siteName + "IS NOT CREATED "); test.log(LogStatus.FAIL, "Private Site " + siteName + "IS NOT CREATED "); LOGGER.info("Expected Results : " + expectedResult); test.log(LogStatus.INFO, "Expected Results : " + expectedResult); LOGGER.info("Current Test Results : " + siteErrorNotification); test.log(LogStatus.FAIL, "Current Test Results : " + "<font color=red>" + siteErrorNotification + "<font>"); } } Element.waitForLoad(driver); LOGGER.info("CHECK WHETHER PRIVATE SITE CREATED OR NOT"); test.log(LogStatus.INFO, "CHECK WHETHER PRIVATE SITE CREATED OR NOT"); LOGGER.info("Check whether \" " + siteName + "\" SITE IS VISIBLE TO " + siteCreatorName); test.log(LogStatus.INFO, "Check whether \" " + siteName + "\" SITE IS VISIBLE TO " + siteCreatorName); Thread.sleep(5000); LOGGER.info("Search the sitename in Site finder"); test.log(LogStatus.INFO, "Search the sitename in Site finder"); SearchObjects searchSite = new SearchObjects(driver); searchSite.searchSite(siteName, className, screenShotName + "joinadmin"); if (Element.isElementPresent(driver, By.xpath("//Span[text()='No sites found']"))) { LOGGER.info("Message display as \"No sites found\""); test.log(LogStatus.INFO, "Message display as \"No sites found\""); LOGGER.info(siteName + " SITE IS NOT VISIBLE TO " + siteCreatorName); test.log(LogStatus.FAIL, "<font color=blue>" + siteName + " SITE IS NOT VISIBLE TO " + siteCreatorName + "<font>"); WebDriver augmentedDriver2 = new Augmenter().augment(driver); File screenshot2 = ((TakesScreenshot) augmentedDriver2).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(screenshot2, new File(TestCaseProperties.REPORT_TEST_PATH_CHROME + className + "/" + screenShotName + "59" + ".jpg")); test.log(LogStatus.INFO, "Snapshot below: " + test.addScreenCapture("./" + className + "/" + screenShotName + "59" + ".jpg")); System.out.println("Screenshot Taken Successfully!!!!"); } else if (Element.isTextPresentInListForSite( driver.findElements(By.xpath("//tbody//tr//td//div//h3//a[contains(., '" + siteName + "')]")), siteName)) { LOGGER.info(siteName + " SITE IS VISIBLE TO " + siteCreatorName); test.log(LogStatus.INFO, "<font color=blue>" + siteName + " SITE IS VISIBLE TO " + siteCreatorName + "<font>"); WebDriver augmentedDriver3 = new Augmenter().augment(driver); File screenshot3 = ((TakesScreenshot) augmentedDriver3).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(screenshot3, new File(TestCaseProperties.REPORT_TEST_PATH_CHROME + className + "/" + screenShotName + "60" + ".jpg")); test.log(LogStatus.INFO, "Snapshot below: " + test.addScreenCapture("./" + className + "/" + screenShotName + "60" + ".jpg")); System.out.println("Screenshot Taken Successfully!!!!"); } Thread.sleep(5000); Element.waitForLoad(driver); LoginPage loginPage1 = new LoginPage(driver); loginPage1.logout(); Element.waitForLoad(driver); LOGGER.info("Login as \"privateuser\" "); test.log(LogStatus.INFO, "Login as \"privateuser\" "); loginPage1.loginAsUser1("privateuser", "1qaz@WSX"); Element.waitForLoad(driver); Thread.sleep(5000); LOGGER.info("Check whether \"" + siteName + "\" SITE IS VISIBLE TO UNJOIN USER \"privateuser\""); test.log(LogStatus.INFO, "Check whether \" " + siteName + "\" SITE IS VISIBLE TO UNJOIN USER \"privateuser\""); SearchObjects searchSite2 = new SearchObjects(driver); searchSite2.searchSite(siteName, className, screenShotName + "non join"); Element.waitForLoad(driver); if (Element.isElementPresent(driver, By.xpath("//Span[text()='No sites found']"))) { Thread.sleep(5000); LOGGER.info("Message display as \"No sites found\""); test.log(LogStatus.INFO, "Message display as \"No sites found\""); LOGGER.info(siteName + " SITE IS NOT VISIBLE TO UNJOIN USER"); test.log(LogStatus.PASS, siteName + " SITE IS NOT VISIBLE TO UNJOIN USER \"privateuser\""); WebDriver augmentedDriver3 = new Augmenter().augment(driver); File screenshot3 = ((TakesScreenshot) augmentedDriver3).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(screenshot3, new File(TestCaseProperties.REPORT_TEST_PATH_CHROME + className + "/" + screenShotName + "61" + ".jpg")); test.log(LogStatus.INFO, "Snapshot below: " + test.addScreenCapture("./" + className + "/" + screenShotName + "61" + ".jpg")); System.out.println("Screenshot Taken Successfully!!!!"); } else { Thread.sleep(5000); if (Element.isTextPresentInList( driver.findElements( By.xpath("//tbody//tr//td//div//h3//a[contains(., '" + siteName + "')]")), siteName)) { LOGGER.info(siteName + " SITE IS VISIBLE TO UNJOIN USER \"privateuser\""); test.log(LogStatus.FAIL, siteName + " SITE IS VISIBLE TO UNJOIN USER \"privateuser\""); WebDriver augmentedDriver3 = new Augmenter().augment(driver); File screenshot3 = ((TakesScreenshot) augmentedDriver3).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(screenshot3, new File(TestCaseProperties.REPORT_TEST_PATH_CHROME + className + "/" + screenShotName + "62" + ".jpg")); test.log(LogStatus.INFO, "Snapshot below: " + test.addScreenCapture("./" + className + "/" + screenShotName + "62" + ".jpg")); System.out.println("Screenshot Taken Successfully!!!!"); } else { LOGGER.info(siteName + " SITE IS NOT VISIBLE TO UNJOIN USER"); test.log(LogStatus.PASS, siteName + " SITE IS NOT VISIBLE TO UNJOIN USER \"privateuser\""); WebDriver augmentedDriver3 = new Augmenter().augment(driver); File screenshot3 = ((TakesScreenshot) augmentedDriver3).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(screenshot3, new File(TestCaseProperties.REPORT_TEST_PATH_CHROME + className + "/" + screenShotName + "63" + ".jpg")); test.log(LogStatus.INFO, "Snapshot below: " + test.addScreenCapture("./" + className + "/" + screenShotName + "63" + ".jpg")); System.out.println("Screenshot Taken Successfully!!!!"); } } } else { LOGGER.info("CREATE PUBLIC SITE"); test.log(LogStatus.INFO, "CREATE PUBLIC SITE"); test.log(LogStatus.INFO, "Click \"Create Site\" "); test.log(LogStatus.INFO, "Enter " + siteName + " in \"site Name Field\" "); test.log(LogStatus.INFO, "Enter " + siteId + " in \"site URL Field\" "); test.log(LogStatus.INFO, "Check \"private\" Option"); test.log(LogStatus.INFO, "Click \"OK\" Button "); createObjects.createPublicSite(siteName, siteId, expectedResult, className, screenShotName); //If Site Created if (Element.isElementPresent(driver, By.xpath("//div[@class='bd']/span[@class='wait']"))) { LOGGER.info(TestCaseProperties.TEXT_TEST_PASS, "Site " + siteName + " CREATED "); test.log(LogStatus.INFO, "<font color=blue>Site " + siteName + " CREATED <font> "); WebDriver augmentedDriver1 = new Augmenter().augment(driver); File screenshot1 = ((TakesScreenshot) augmentedDriver1).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(screenshot1, new File(TestCaseProperties.REPORT_TEST_PATH_CHROME + className + "/" + screenShotName + "64" + ".jpg")); test.log(LogStatus.INFO, "Snapshot below: " + test.addScreenCapture("./" + className + "/" + screenShotName + "64" + ".jpg")); System.out.println("Screenshot Taken Successfully!!!!"); } //If Site IS NOT CREATED //Expected Result1=[COULD NOT CREATE SITE SINCE THE URL IS ALREADY USED] //ExpectedResult1==CurrentResult else { SiteDashboardPage siteDash1 = new SiteDashboardPage(driver); String siteErrorNotification = siteDash1.errorNotification(siteName, className, screenShotName); if (siteErrorNotification.toUpperCase().equals(expectedResult)) { LOGGER.info("Expected Results : " + expectedResult); test.log(LogStatus.INFO, "Expected Results : " + expectedResult); LOGGER.info("Current Test Results : " + siteErrorNotification); test.log(LogStatus.PASS, "Current Test Results : " + "<font color=green>" + siteErrorNotification + "<font>"); WebDriver augmentedDriver1 = new Augmenter().augment(driver); File screenshot1 = ((TakesScreenshot) augmentedDriver1).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(screenshot1, new File(TestCaseProperties.REPORT_TEST_PATH_CHROME + className + "/" + screenShotName + "65" + ".jpg")); test.log(LogStatus.INFO, "Snapshot below: " + test.addScreenCapture("./" + className + "/" + screenShotName + "65" + ".jpg")); System.out.println("Screenshot Taken Successfully!!!!"); Button okaybtn = new Button(driver, By.xpath("//button[text()='OK']")); okaybtn.click(); } //ExpectedResult1!=CurrentResult[PROBLEM] else { LOGGER.error(TestCaseProperties.TEXT_TEST_FAIL, "Private Site " + siteName + "IS NOT CREATED "); test.log(LogStatus.FAIL, "Private Site " + siteName + "IS NOT CREATED "); LOGGER.info("Expected Results : " + expectedResult); test.log(LogStatus.INFO, "Expected Results : " + expectedResult); LOGGER.info("Current Test Results : " + siteErrorNotification); test.log(LogStatus.FAIL, "Current Test Results : " + "<font color=red>" + siteErrorNotification + "<font>"); WebDriver augmentedDriver1 = new Augmenter().augment(driver); File screenshot1 = ((TakesScreenshot) augmentedDriver1).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(screenshot1, new File(TestCaseProperties.REPORT_TEST_PATH_CHROME + className + "/" + screenShotName + "66" + ".jpg")); test.log(LogStatus.INFO, "Snapshot below: " + test.addScreenCapture("./" + className + "/" + screenShotName + "66" + ".jpg")); System.out.println("Screenshot Taken Successfully!!!!"); } } LOGGER.info("CHECK WHETHER " + siteName + " IS CREATED OR NOT"); test.log(LogStatus.INFO, "CHECK WHETHER " + siteName + " IS CREATED OR NOT"); LOGGER.info("CHECK WHETHER " + siteName + " IS DISPLAY IN SITES LIST"); test.log(LogStatus.INFO, "CHECK WHETHER " + siteName + " IS DISPLAY IN SITES LIST"); LOGGER.info("Click \"Sites\""); test.log(LogStatus.INFO, "Click \"Sites\""); LOGGER.info("Click \"Site Finder\""); test.log(LogStatus.INFO, "Click \"Site Finder\""); LOGGER.info("Search sitename"); test.log(LogStatus.INFO, "Search sitename"); SearchObjects searchSite = new SearchObjects(driver); searchSite.searchSite(siteName, className, screenShotName); if (Element.isElementPresent(driver, By.xpath("//Span[text()='No sites found']"))) { LOGGER.info("Message display as \"No sites found\""); test.log(LogStatus.INFO, "Message display as \"No sites found\""); WebDriver augmentedDriver1 = new Augmenter().augment(driver); File screenshot1 = ((TakesScreenshot) augmentedDriver1).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(screenshot1, new File(TestCaseProperties.REPORT_TEST_PATH_CHROME + className + "/" + screenShotName + "67" + ".jpg")); test.log(LogStatus.INFO, "Snapshot below: " + test.addScreenCapture("./" + className + "/" + screenShotName + "67" + ".jpg")); System.out.println("Screenshot Taken Successfully!!!!"); } else { if (Element.isTextPresentInListForSite( driver.findElements( By.xpath("//tbody//tr//td//div//h3//a[contains(., '" + siteName + "')]")), siteName)) { LOGGER.info("Site is Display in \"Site Search\""); test.log(LogStatus.PASS, "<font color=green>Site is Display in \"Site Search\"<font>"); WebDriver augmentedDriver1 = new Augmenter().augment(driver); File screenshot1 = ((TakesScreenshot) augmentedDriver1).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(screenshot1, new File(TestCaseProperties.REPORT_TEST_PATH_CHROME + className + "/" + screenShotName + "68" + ".jpg")); test.log(LogStatus.INFO, "Snapshot below: " + test.addScreenCapture("./" + className + "/" + screenShotName + "68" + ".jpg")); System.out.println("Screenshot Taken Successfully!!!!"); } else { LOGGER.info("Site IS NOT Display in \"Site Search\""); test.log(LogStatus.FAIL, "<font color=red>Site is NOT Display in \"Site Search\"<font>"); WebDriver augmentedDriver1 = new Augmenter().augment(driver); File screenshot1 = ((TakesScreenshot) augmentedDriver1).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(screenshot1, new File(TestCaseProperties.REPORT_TEST_PATH_CHROME + className + "/" + screenShotName + "69" + ".jpg")); test.log(LogStatus.INFO, "Snapshot below: " + test.addScreenCapture("./" + className + "/" + screenShotName + "69" + ".jpg")); System.out.println("Screenshot Taken Successfully!!!!"); } } } loginPage.logout(); LOGGER.info("Test case b_createSite executed"); test.log(LogStatus.INFO, "Test case b_createSite executed"); extent.endTest(test); extent.flush(); } /** * * @Test FolderCreation * @return * * @throws Exception InterruptedException, IOException */ @Test public void c_FolderCreation() throws InterruptedException, IOException { ExtentTest test = extent.startTest("c_FolderCreation", "Folder Creation and Validation as Admin in the Private Site"); driver = TestCaseProperties.driverType("Chrome", "WINDOWS"); //Set the upper left corner of the screen starting point driver.manage().window().setPosition(new Point(0, 0)); //define screen size java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); // define desired size Dimension maxWindowSize = new Dimension((int) screenSize.getWidth(), (int) screenSize.getHeight()); // Maximize the browser window according to your system's current resolution(set desired size) driver.manage().window().setSize(maxWindowSize); LOGGER.info("Test case c_FolderCreation started execution"); test.log(LogStatus.INFO, "Test case c_FolderCreation started execution"); driver.get(TestCaseProperties.LOGIN_SCREEN_URL); LoginPage loginPage = new LoginPage(driver); LOGGER.info("Accessing the Login Page"); test.log(LogStatus.INFO, "Accessing the Login Page"); //Login as the Admin LOGGER.info("Login As Admin"); test.log(LogStatus.INFO, "Login As Admin"); loginPage.loginAsAdmin(className, screenShotName); Thread.sleep(3000); SearchObjects search = new SearchObjects(driver); //Search for the Site LOGGER.info("Click \"Search Finder\""); test.log(LogStatus.INFO, "Click \"Search Finder\""); LOGGER.info("Search Site \"" + siteName + "\""); test.log(LogStatus.INFO, "Search Site \"" + siteName + "\""); search.searchSite(siteName, className, screenShotName); //Clicks on the Site Link LOGGER.info("Navigate to the " + siteName); test.log(LogStatus.INFO, "Navigate to the " + siteName); Link siteLink = new Link(driver, By.xpath("//h3[@class='sitename']/a[text()='" + siteName + "']")); siteLink.click(); // Element.takescreenshot(driver, className, screenShotName+"site1name"); Thread.sleep(3000); //Create Folder LOGGER.info("Created the Folder : " + folderName); test.log(LogStatus.INFO, "Created the Folder : " + folderName); test.log(LogStatus.INFO, "Navigate To DocumentLibrary"); test.log(LogStatus.INFO, "Click \"Create\" Button"); test.log(LogStatus.INFO, "Click \"Folder\""); test.log(LogStatus.INFO, "Enter the Name of the Folder"); test.log(LogStatus.INFO, "Enter the title of the Folder"); test.log(LogStatus.INFO, "Click \"Save\" Button"); CreateObjects create = new CreateObjects(driver); create.createFolder(folderName, folderTitle, className, screenShotName + "createFolder1"); Thread.sleep(3000); WebDriver augmentedDriver1 = new Augmenter().augment(driver); File screenshot1 = ((TakesScreenshot) augmentedDriver1).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(screenshot1, new File( TestCaseProperties.REPORT_TEST_PATH_CHROME + className + "/" + screenShotName + "70" + ".jpg")); test.log(LogStatus.INFO, "Snapshot below: " + test.addScreenCapture("./" + className + "/" + screenShotName + "70" + ".jpg")); System.out.println("Screenshot Taken Successfully!!!!"); loginPage.logout(); //--- Folder Validation LOGGER.info("CHECK WHETHER FOLDER IS CREATED SUCESSFULLY"); test.log(LogStatus.INFO, "CHECK WHETHER FOLDER IS CREATED SUCESSFULLY"); LOGGER.info("Accessing the LoginPage"); test.log(LogStatus.INFO, "Accessing the LoginPage"); LOGGER.info("Login as Admin"); test.log(LogStatus.INFO, "Login as Admin"); LoginPage loginPage1 = new LoginPage(driver); loginPage1.loginAsAdmin(className, screenShotName); //Search for the Site LOGGER.info("Click \"Search Finder\""); test.log(LogStatus.INFO, "Click \"Search Finder\""); LOGGER.info("Search Site \"" + siteName + "\""); test.log(LogStatus.INFO, "Search Site \"" + siteName + "\""); search.searchSite(siteName, className, screenShotName); //Clicks on the Site Link LOGGER.info("Navigate to the " + siteName); test.log(LogStatus.INFO, "Navigate to the " + siteName); Link siteLink1 = new Link(driver, By.xpath("//h3[@class='sitename']/a[text()='" + siteName + "']")); siteLink1.click(); Thread.sleep(3000); //Navigate to the Document Library LOGGER.info("Navigate To DocumentLibrary"); test.log(LogStatus.INFO, "Navigate To DocumentLibrary"); NavigateToPage navigate = new NavigateToPage(driver); navigate.goToDocLib(); Element currentResult = new Element(driver, By.xpath("//h3//span//a[@rel='|path|/" + folderName + "|']")); //Verify whether the folder is created if (Element.isElementPresent(driver, By.xpath("//h3//span//a[@rel='|path|/" + folderName + "|']"))) { //Expected Result LOGGER.info("Expected Results :Folder " + folderName + "should visible"); test.log(LogStatus.INFO, "Expected Results :Folder " + folderName + "should visible"); //Current Result LOGGER.info("Current Test Results : Folder " + currentResult.getWebElement().getText() + " is visible"); test.log(LogStatus.INFO, "Current Test Results :Folder " + currentResult.getWebElement().getText() + " is visible"); LOGGER.info("The Admin has created the " + folderName + " successfully."); test.log(LogStatus.PASS, "The Admin has created the " + folderName + " successfully."); WebDriver augmentedDriver2 = new Augmenter().augment(driver); File screenshot2 = ((TakesScreenshot) augmentedDriver2).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(screenshot2, new File( TestCaseProperties.REPORT_TEST_PATH_CHROME + className + "/" + screenShotName + "71" + ".jpg")); test.log(LogStatus.INFO, "Snapshot below: " + test.addScreenCapture("./" + className + "/" + screenShotName + "71" + ".jpg")); System.out.println("Screenshot Taken Successfully!!!!"); } else { //Expected Result LOGGER.info("Expected Results :Folder " + folderName + "should visible"); test.log(LogStatus.INFO, "Expected Results :Folder " + folderName + "should visible"); //Current Result LOGGER.info("Current Test Results : Folder " + currentResult.getWebElement().getText() + " is visible"); test.log(LogStatus.INFO, "Current Test Results :Folder " + currentResult.getWebElement().getText() + " is visible"); LOGGER.info("The Admin has NOT created the " + folderName + " successfully."); test.log(LogStatus.FAIL, "The Admin has NOT created the " + folderName + " successfully."); WebDriver augmentedDriver2 = new Augmenter().augment(driver); File screenshot2 = ((TakesScreenshot) augmentedDriver2).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(screenshot2, new File( TestCaseProperties.REPORT_TEST_PATH_CHROME + className + "/" + screenShotName + "72" + ".jpg")); test.log(LogStatus.INFO, "Snapshot below: " + test.addScreenCapture("./" + className + "/" + screenShotName + "72" + ".jpg")); System.out.println("Screenshot Taken Successfully!!!!"); } LOGGER.info("Test case c_FolderCreation executed"); test.log(LogStatus.INFO, "Test case c_FolderCreation executed"); extent.endTest(test); extent.flush(); } /** * * @Test DeleteFolder * @return * * @throws Exception InterruptedException, IOException */ @Test public void d_deleteFolder() throws InterruptedException, IOException { ExtentTest test = extent.startTest("d_deleteFolder", "Folder Creation and Validation as Admin in the Private Site"); driver = TestCaseProperties.driverType("Chrome", "WINDOWS"); //Set the upper left corner of the screen starting point driver.manage().window().setPosition(new Point(0, 0)); //define screen size java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); // define desired size Dimension maxWindowSize = new Dimension((int) screenSize.getWidth(), (int) screenSize.getHeight()); // Maximize the browser window according to your system's current resolution(set desired size) driver.manage().window().setSize(maxWindowSize); LOGGER.info("Test case d_deleteFolder started execution"); test.log(LogStatus.INFO, "Test case d_deleteFolder started execution"); driver.get(TestCaseProperties.LOGIN_SCREEN_URL); LoginPage loginPage = new LoginPage(driver); LOGGER.info("Accessing the Login Page"); test.log(LogStatus.INFO, "Accessing the Login Page"); //Login as the Admin LOGGER.info("Login As Admin"); test.log(LogStatus.INFO, "Login As Admin"); loginPage.loginAsAdmin(className, screenShotName); Thread.sleep(3000); SearchObjects search = new SearchObjects(driver); //Search for the Site LOGGER.info("Click \"Search Finder\""); test.log(LogStatus.INFO, "Click \"Search Finder\""); LOGGER.info("Search Site \"" + siteName + "\""); test.log(LogStatus.INFO, "Search Site \"" + siteName + "\""); search.searchSite(siteName, className, screenShotName); //Clicks on the Site Link LOGGER.info("Navigate to the " + siteName); test.log(LogStatus.INFO, "Navigate to the " + siteName); Link siteLink = new Link(driver, By.xpath("//h3[@class='sitename']/a[text()='" + siteName + "']")); siteLink.click(); Thread.sleep(3000); //Delete Folder LOGGER.info("Delete the Folder : " + folderName); test.log(LogStatus.INFO, "Delete the Folder : " + folderName); test.log(LogStatus.INFO, "Navigate To DocumentLibrary"); test.log(LogStatus.INFO, "Select Folder"); test.log(LogStatus.INFO, "Click \"Selected Items\""); test.log(LogStatus.INFO, "Click \"Delete\" Button"); test.log(LogStatus.INFO, "Click \"Delete Confirmation\" Button"); test.log(LogStatus.INFO, "Login as Admin to delete Folder in TrashCan"); test.log(LogStatus.INFO, "Click \"My Profile\""); test.log(LogStatus.INFO, "Place FolderName"); test.log(LogStatus.INFO, "Click \"Search\" Button"); test.log(LogStatus.INFO, "Check the patucular FolderName"); test.log(LogStatus.INFO, "Click \"Selected Item\" Button"); test.log(LogStatus.INFO, "Click \"Delete\" Button"); test.log(LogStatus.INFO, "Click \"OK\" Button"); test.log(LogStatus.INFO, "Click \"OK confirmation\" Button"); RemoveObjects delete = new RemoveObjects(driver); delete.deleteFolder(folderName, className, screenShotName); Thread.sleep(3000); WebDriver augmentedDriver2 = new Augmenter().augment(driver); File screenshot2 = ((TakesScreenshot) augmentedDriver2).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(screenshot2, new File( TestCaseProperties.REPORT_TEST_PATH_CHROME + className + "/" + screenShotName + "73" + ".jpg")); test.log(LogStatus.INFO, "Snapshot below: " + test.addScreenCapture("./" + className + "/" + screenShotName + "73" + ".jpg")); System.out.println("Screenshot Taken Successfully!!!!"); loginPage.logout(); //--- Folder Validation LOGGER.info("Accessing the Login Page Again"); test.log(LogStatus.INFO, "Accessing the Login Page Again"); //Login as the Admin LOGGER.info("Login As Admin"); test.log(LogStatus.INFO, "Login As Admin"); LoginPage loginPage1 = new LoginPage(driver); loginPage1.loginAsAdmin(className, screenShotName); NavigateToPage navigateTo = new NavigateToPage(driver); LOGGER.info("CHECK WHETHER FOLDER\" " + folderName + " \"IS DELETED OR NOT"); test.log(LogStatus.INFO, "CHECK WHETHER FOLDER\" " + folderName + " \"IS DELETED OR NOT"); navigateTo.goToHome(); LOGGER.error("Click \"My Profile\" Again"); test.log(LogStatus.INFO, "Click \"My Profile\" Again"); navigateTo.goToUserTrashCan(className, screenShotName + "deletconfirm123"); LOGGER.info("Place folderUrl"); test.log(LogStatus.INFO, "Place folderUrl"); TextField textField = new TextField(driver, By.id("template_x002e_user-trashcan_x002e_user-trashcan_x0023_default-search-text")); textField.clearText(); textField.enterText(folderName); LOGGER.info("Click \"Search\" Button"); test.log(LogStatus.INFO, "Click \"Search\" Button"); Button searchButton = new Button(driver, By.xpath("//button[text()='Search']")); searchButton.click(); Thread.sleep(2000); WebDriver augmentedDriver3 = new Augmenter().augment(driver); File screenshot3 = ((TakesScreenshot) augmentedDriver3).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(screenshot3, new File( TestCaseProperties.REPORT_TEST_PATH_CHROME + className + "/" + screenShotName + "73" + ".jpg")); test.log(LogStatus.INFO, "Snapshot below: " + test.addScreenCapture("./" + className + "/" + screenShotName + "73" + ".jpg")); System.out.println("Screenshot Taken Successfully!!!!"); LOGGER.info("Check the patucular folderUrl"); test.log(LogStatus.INFO, "Check the patucular folderUrl"); if (Element.isElementPresent(driver, By.xpath("//tbody[@class='yui-dt-message']//tr//td//div"))) { LOGGER.info(folderName + " Folder IS DELETED SUCCESSFULLY"); test.log(LogStatus.PASS, folderName + " Folder IS DELETED SUCCESSFULLY"); WebDriver augmentedDriver4 = new Augmenter().augment(driver); File screenshot4 = ((TakesScreenshot) augmentedDriver4).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(screenshot4, new File( TestCaseProperties.REPORT_TEST_PATH_CHROME + className + "/" + screenShotName + "74" + ".jpg")); test.log(LogStatus.INFO, "Snapshot below: " + test.addScreenCapture("./" + className + "/" + screenShotName + "74" + ".jpg")); System.out.println("Screenshot Taken Successfully!!!!"); } else { Element.waitUntilElementPresent(driver, By.xpath("//div//div//table//tbody//tr[contains(.,'" + folderName + "')]//td//div")); java.util.List<WebElement> myList = driver.findElements( By.xpath("//div//div//table//tbody//tr[contains(.,'" + folderName + "')]//td//div")); for (int i = 0; i < myList.size(); i++) { if (myList.get(i).getText().equals(folderName)) { Thread.sleep(2000); LOGGER.info(folderName + "Folder IS NOT DELETED"); test.log(LogStatus.FAIL, folderName + " Folder IS NOT DELETED"); WebDriver augmentedDriver4 = new Augmenter().augment(driver); File screenshot4 = ((TakesScreenshot) augmentedDriver4).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(screenshot4, new File(TestCaseProperties.REPORT_TEST_PATH_CHROME + className + "/" + screenShotName + "75" + ".jpg")); test.log(LogStatus.INFO, "Snapshot below: " + test.addScreenCapture("./" + className + "/" + screenShotName + "75" + ".jpg")); System.out.println("Screenshot Taken Successfully!!!!"); } else { LOGGER.info(folderName + " Folder IS DELETED SUCCESSFULLY"); test.log(LogStatus.PASS, folderName + "Folder IS DELETED SUCCESSFULLY"); WebDriver augmentedDriver4 = new Augmenter().augment(driver); File screenshot4 = ((TakesScreenshot) augmentedDriver4).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(screenshot4, new File(TestCaseProperties.REPORT_TEST_PATH_CHROME + className + "/" + screenShotName + "76" + ".jpg")); test.log(LogStatus.INFO, "Snapshot below: " + test.addScreenCapture("./" + className + "/" + screenShotName + "76" + ".jpg")); System.out.println("Screenshot Taken Successfully!!!!"); } } } loginPage1.logout(); LOGGER.info("Test case d_deleteFolder executed"); test.log(LogStatus.INFO, "Test case d_deleteFolder executed"); extent.endTest(test); extent.flush(); } /** * * @Test DeleteSite * @return * * @throws Exception InterruptedException, IOException */ @Test public void e_deleteSite() throws InterruptedException, IOException { LOGGER.info(TestCaseProperties.TEXT_TEST_EXECUTING, "Delete site called \" " + siteName + " \" "); //Extent Report Start Configuration(testCaseName,Definition of testCase) ExtentTest test = extent.startTest("e_deleteSite", "Delete site called \" " + siteName + " \" "); //Set the DriverType(BrowserName,Platform) driver = TestCaseProperties.driverType("Chrome", "WINDOWS"); // Set the upper left corner of the screen starting point driver.manage().window().setPosition(new Point(0, 0)); // define screen size java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); // define desired size Dimension maxWindowSize = new Dimension((int) screenSize.getWidth(), (int) screenSize.getHeight()); // Maximize the browser window according to your system's current // resolution(set desired size) driver.manage().window().setSize(maxWindowSize); //Get LoginScreen_URl from TestcaseProperties Values driver.get(TestCaseProperties.LOGIN_SCREEN_URL); LOGGER.info("Test case e_deleteSite started executing"); test.log(LogStatus.INFO, "Test case e_deleteSite started executing"); LOGGER.info("Accessing the Login Page"); test.log(LogStatus.INFO, "Accessing the Login Page"); LOGGER.info("Login as admin"); test.log(LogStatus.INFO, "Login as admin"); LoginPage loginPage = new LoginPage(driver); loginPage.loginAsAdmin(className, screenShotName); LOGGER.info("Check the site,if site exist Delet the user"); test.log(LogStatus.INFO, "Check the site,if site exist Delete the user"); test.log(LogStatus.INFO, "Search the site"); test.log(LogStatus.INFO, "Click \"Delete\" Button,next to site\"" + siteName + "\""); test.log(LogStatus.INFO, "Click \"Delete\" Button,for delete confirmation"); test.log(LogStatus.INFO, "Login as Admin to delete Site in TrashCan"); test.log(LogStatus.INFO, "Click \"My Profile\""); test.log(LogStatus.INFO, "Place siteUrl"); test.log(LogStatus.INFO, "Click \"Search\" Button"); test.log(LogStatus.INFO, "Check the patucular siteUrl"); test.log(LogStatus.INFO, "Click \"Selected Item\" Button"); test.log(LogStatus.INFO, "Click \"Delete\" Button"); test.log(LogStatus.INFO, "Click \"OK\" Button"); test.log(LogStatus.INFO, "Click \"OK confirmation\" Button"); RemoveObjects deleteSite = new RemoveObjects(driver); deleteSite.deleteSite(siteName, siteId, className, screenShotName); LOGGER.info("CHECK WHETHER SITE\" " + siteName + " \"IS DELETED OR NOT"); test.log(LogStatus.INFO, "CHECK WHETHER SITE\" " + siteName + " \"IS DELETED OR NOT"); NavigateToPage navigateTo = new NavigateToPage(driver); navigateTo.goToHome(); LOGGER.error("Click \"My Profile\" Again"); test.log(LogStatus.INFO, "Click \"My Profile\" Again"); test.log(LogStatus.INFO, "Accessing trashcan Page"); navigateTo.goToUserTrashCan(className, screenShotName + "deletconfirm1"); LOGGER.info("Place siteUrl"); test.log(LogStatus.INFO, "Place siteUrl"); TextField textField = new TextField(driver, By.id("template_x002e_user-trashcan_x002e_user-trashcan_x0023_default-search-text")); textField.clearText(); textField.enterText(siteId); LOGGER.info("Click \"Search\" Button"); test.log(LogStatus.INFO, "Click \"Search\" Button"); Button searchButton = new Button(driver, By.xpath("//button[text()='Search']")); searchButton.click(); Thread.sleep(2000); WebDriver augmentedDriver1 = new Augmenter().augment(driver); File screenshot1 = ((TakesScreenshot) augmentedDriver1).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(screenshot1, new File( TestCaseProperties.REPORT_TEST_PATH_CHROME + className + "/" + screenShotName + "30" + ".jpg")); test.log(LogStatus.INFO, "Snapshot below: " + test.addScreenCapture("./" + className + "/" + screenShotName + "30" + ".jpg")); System.out.println("Screenshot Taken Successfully!!!!"); //Element.takescreenshot(driver, className, screenShotName+"deleteConfirmation"); //CheckBox checkbox=new CheckBox(driver, By.xpath("//div[@class='name'][text()='"+item+"']/ancestor::td[1]/preceding-sibling::td[2]//input")); //checkbox.click(); LOGGER.info("Check the patucular siteUrl"); test.log(LogStatus.INFO, "Check the patucular siteUrl"); if (Element.isElementPresent(driver, By.xpath("//tbody[@class='yui-dt-message']//tr//td//div"))) { LOGGER.info(siteName + " SITE IS DELETED SUCCESSFULLY"); test.log(LogStatus.PASS, siteName + " SITE IS DELETED SUCCESSFULLY"); WebDriver augmentedDriver2 = new Augmenter().augment(driver); File screenshot2 = ((TakesScreenshot) augmentedDriver2).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(screenshot2, new File( TestCaseProperties.REPORT_TEST_PATH_CHROME + className + "/" + screenShotName + "31" + ".jpg")); test.log(LogStatus.INFO, "Snapshot below: " + test.addScreenCapture("./" + className + "/" + screenShotName + "31" + ".jpg")); System.out.println("Screenshot Taken Successfully!!!!"); } else { Element.waitUntilElementPresent(driver, By.xpath("//div//div//table//tbody//tr[contains(.,'" + siteId + "')]//td//div")); java.util.List<WebElement> myList = driver .findElements(By.xpath("//div//div//table//tbody//tr[contains(.,'" + siteId + "')]//td//div")); for (int i = 0; i < myList.size(); i++) { if (myList.get(i).getText().equals(siteId)) { Thread.sleep(2000); LOGGER.info(siteName + "SITE IS NOT DELETED"); test.log(LogStatus.FAIL, siteName + " SITE IS NOT DELETED"); WebDriver augmentedDriver2 = new Augmenter().augment(driver); File screenshot2 = ((TakesScreenshot) augmentedDriver2).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(screenshot2, new File(TestCaseProperties.REPORT_TEST_PATH_CHROME + className + "/" + screenShotName + "32" + ".jpg")); test.log(LogStatus.INFO, "Snapshot below: " + test.addScreenCapture("./" + className + "/" + screenShotName + "32" + ".jpg")); System.out.println("Screenshot Taken Successfully!!!!"); } else { LOGGER.info(siteName + " SITE IS DELETED SUCCESSFULLY"); test.log(LogStatus.PASS, siteName + "SITE IS DELETED SUCCESSFULLY"); WebDriver augmentedDriver2 = new Augmenter().augment(driver); File screenshot2 = ((TakesScreenshot) augmentedDriver2).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(screenshot2, new File(TestCaseProperties.REPORT_TEST_PATH_CHROME + className + "/" + screenShotName + "33" + ".jpg")); test.log(LogStatus.INFO, "Snapshot below: " + test.addScreenCapture("./" + className + "/" + screenShotName + "33" + ".jpg")); System.out.println("Screenshot Taken Successfully!!!!"); } } } loginPage.logout(); LOGGER.info("Test case e_deleteSite executed"); test.log(LogStatus.INFO, "Test case e_deleteSite executed"); extent.endTest(test); extent.flush(); } }