1

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"));
  }
}
2
  • 2
    We'd love to help. Care to show us your code? Mar 1, 2017 at 12:42
  • You could be outputting the original screenshot to different filenames, or the navigation could actually be failing . . .
    – ernie
    Mar 1, 2017 at 18:05

2 Answers 2

1

What may be happening here is that the navigation itself is failing, e.g.

  • Visit Home. Take screenshot
  • Try to visit page 1 but there is an issue with the link or the form and you are still on the home page, so the screenshot now taken is still the same homepage.
  • Repeat

Could be a missing link, bad link, bad URL, bad parameters, related to js, etc.

1
  • Code has been added, seems to be a coding error instead :) Mar 6, 2017 at 8:17
1

Before every screenshot you need to call getScreenshotAs() again, add this line before each time you want to save a screenshot:

scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);

The scrFile does not continuously update its value with the current screen, only when you evoke getScreenshot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.