I am navigating across an application on different areas like dashboard and google maps and taking screenshots along the way for every new page loaded. The screenshots are captured but only the screenshot taken on the 1st instance when the application is loaded is taken multiple times just with different names, as per the code. So all the 5 screenshots taken for the application are of the same landing page of the application. I have tried putting implicit wait of 60 sec before taking the screenshot / tried putting the implicit wait after the screenshot method is called / currently the code has thread.sleep after every click even, but no difference. It's like the wait is not working at all the screenshot syntax is executed before even the new pages can come up.
Please help.
Here is my code for reference :
@Test
public void ProdValidation() throws IOException, InterruptedException {
// Telling the system where to find the chrome driver
System.setProperty("webdriver.chrome.driver","C:/Users/avneet.sikka/Documents/chromedriver.exe");
// Create a new instance of the Chrome driver
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
// Logging in to Atlanta Application
driver.get("https://test.atlantadwm.mwhaccenture.com/WaterAnalytics/");
driver.findElement(By.id("login")).sendKeys("avneet.sikka");
driver.findElement(By.id("password")).sendKeys("as87*63l");
driver.findElement(By.className("arrow")).click();
//driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
Thread.sleep(3000);
Assert.assertEquals(driver.getCurrentUrl().endsWith("/<WaterAnalyticsFrontController>/"),false);
Reporter.log( "Atlanta home Page is displayed", true );
File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("Test Result\\AtlantaHomepage.png"));
//Navigate to Consent Decree SSES Reports Dashboard
driver.findElement(By.className("geoSub")).click();
Thread.sleep(3000);
WebElement element8 = driver.findElement(By.cssSelector("div [class$='calendar']")); // Locate icon, where we mouse hover
Actions builder=new Actions(driver); // Use action class to mouse hover on icon
builder.moveToElement(element8).perform(); //mouse hover on the icon
String toolTipText8 = element8.getAttribute("title"); // get the tool tip text and assert
Assert.assertEquals(toolTipText8 , "Dashboard");
driver.findElement(By.cssSelector("div [class$='projectDash']")).isDisplayed();
Reporter.log( "Consent Decree SSES Reports Dashboard is present in WasteWater module under the Dashboard tab", true );
driver.findElement(By.cssSelector("div [class$='circledash']")).click();
Thread.sleep(3000);
driver.findElement(By.cssSelector("div [class$='projectDash']")).click();
Thread.sleep(3000);
String text1 = "CITY OF ATLANTA";
driver.getPageSource().contains(text1);
Assert.assertEquals(text1, "CITY OF ATLANTA");
Reporter.log( "Project Dashboard is displayed and has the heading : CITY OF ATLANTA DEPT. OF WATERSHED MANAGEMENT - CONSENT DECREE PROJECTS DASHBOARD", true );
FileUtils.copyFile(scrFile, new File("Test Result\\ProjectDashboard.png"));
//Navigate to Spills Dashboard
driver.findElement(By.id("homeNav")).click();
Thread.sleep(3000);
driver.findElement(By.className("geoSub")).click();
Thread.sleep(3000);
driver.findElement(By.cssSelector("div [class$='circledash']")).click();
Thread.sleep(3000);
driver.findElement(By.cssSelector("div [class$='spills']")).isDisplayed();
Reporter.log( "Spills Overflow Reports Dashboard is present in WasteWater module under the Dashboard tab", true );
FileUtils.copyFile(scrFile, new File("Test Result\\WasteWaterModule_Dashboards.png"));
driver.findElement(By.cssSelector("div [class$='spills']")).click();
Thread.sleep(3000);
String text2 = "SPILLS MONITORING DASHBOARD";
driver.getPageSource().contains(text2);
Assert.assertEquals(text2, "SPILLS MONITORING DASHBOARD");
Reporter.log( "Spills Dashboard page is displayed and has the heading : SPILLS MONITORING DASHBOARD", true );
FileUtils.copyFile(scrFile, new File("Test Result\\SpillsDashboard.png"));
//Navigate to Wastewater Geospatial View
driver.findElement(By.id("homeNav")).click();
Thread.sleep(3000);
driver.findElement(By.className("geoSub")).click();
Thread.sleep(3000);
driver.findElement(By.cssSelector("div [class$='geoDash']")).click();
Thread.sleep(3000);
Reporter.log( "WasteWater Geospatial View is displayed", true );
driver.manage().timeouts().implicitlyWait(120, TimeUnit.SECONDS);
//Check ShapeFile - Monitored manholeCouncil district and take screenshot
List<WebElement> CHECKBOXlist = driver.findElements(By.xpath("(//input[@type='checkbox'])[position()=1]"));
WebDriverWait wait = new WebDriverWait(driver,30);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("(//input[@type='checkbox'])[position()=1]")));
for(WebElement checkbox : CHECKBOXlist) {
checkbox.click();
}
Thread.sleep(3000);
Reporter.log("Monitored manhole shapefile is present and loaded in the GeoSpatial View", true);
FileUtils.copyFile(scrFile, new File("Test Result\\MonitoredManhole.png"));
}
}