1

I have the code that takes a screenshot after every step, however it is only taking the screenshot of the current view point. I would like it to take the screenshot of the entire page.

I have looked into things like aShot but I don't know how to add it to my project.

Current code:

    [AfterStep]
    public void AfterStep()
    {
        Screenshot ss = ((ITakesScreenshot)webDriver).GetScreenshot();
        string stepTitle = ScenarioContext.Current.StepContext.StepInfo.Text;
        string fileTitle = DateTime.Now.ToString("yyyyMMdd_HHmmss")+ "_" + stepTitle;
        string drive = (path + DateTime.Now.ToString("yyyyMMdd_HHmm") + "_" + testTitle);

        string screenshotfilename = drive + "\\" + fileTitle + ".Png";
        ss.SaveAsFile(screenshotfilename, ScreenshotImageFormat.Png);
    }

Edit:

My problem is not to do with the action of taking a screenshot exactly. The issue I am facing is my page extends the height of the browser and therefor when I take a screenshot, it is a screenshot of the view-able page and not the entire page.

Ross
  • 2,463
  • 5
  • 35
  • 91

3 Answers3

0

Have you tried the following at the start of your test?

webDriver.Manage().Window.Maximize();

e.g. you could include it here:

[Binding]
public class Setup
{
public static IWebDriver Driver = new ChromeDriver();

[BeforeTestRun]
public static void SetUpBrowser()
{
Driver.Manage().Window.Maximize();
}

note: it may have a slightly different syntax to 'BeforeTestRun' in Gherkin

Danny
  • 287
  • 2
  • 15
  • My browser opens maximized already. my issue is that the page height is greater than my browser height and therefore the screenshot is of the view-able page, not the entire page. – Ross Nov 28 '17 at 13:12
0

If your browser is on top and you see it on your screen, try using C#'s screenshot feature (that will take a screenshot of the whole screen). Like clicking PrtScn button that will save the whole screen.

Implementations within the webdriver itself (like the code you showed), IMO should take a screenshot only of the webdriver, since you are asking webdriver to take a screenshot of what it handles (the browser window). If you want a full screen, just use some of the implementations used in the link below.

Capture a Screen Shot using C#

Edit: If you want to take a screenshot of the whole page even though it is not visible (and you have to scroll down to see it), it seems it is not possible as shown here:

how to get screenshot of full web page using selenium in java?

0

You may want to try this feature of selenium:

set_window_size(int(width), int(height))

I just set window size to 4800*2560 and captured whole page at once which I had to scroll down twice on a 27-inch screen.