Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command to take screenshot during test execution #632

Closed
jgwilson42 opened this issue Apr 24, 2017 · 9 comments
Closed

Command to take screenshot during test execution #632

jgwilson42 opened this issue Apr 24, 2017 · 9 comments
Assignees
Milestone

Comments

@jgwilson42
Copy link
Contributor

This is a feature request.

Expected behavior

I would like to be able to take a screenshot at a specific point in the test execution. In the same way that I can use Gauge.writemessage() I would like a command like Gauge.screenshot() .

Currently I am using the following to write the screenshot to the disk, it would be much better to include the screenshot in the gauge report.

Gauge version

Gauge version: 0.8.3

Plugins
-------
html-report (3.1.0)
java (0.6.2)
@sswaroopgupta
Copy link
Contributor

sswaroopgupta commented Apr 27, 2017

@jgwilson42 The following is a workaround/hack. Let me know what you think.
How about using Gauge.writemessage to print the path of the screenshot captured. So while browsing the report, the screenshot can be opened manually using the path specified.

@jgwilson42
Copy link
Contributor Author

Interesting approach. Assuming this works with relative paths this would be fine. The reason for needing relative paths is that the tests are run from travis and then the report is zip'd up and moved to google storage.

@nomade
Copy link

nomade commented Oct 10, 2017

So, I was needing take screenshot for each step, then, I use Selenium to take picture and use Gauge.writeMessage to add image in report. It's working for me.

@AfterStep
public void screenshot() {
	try {
		Thread.sleep(10);
		takesScreenshot(String.valueOf(System.currentTimeMillis()));
	}catch (Exception e) {
		e.printStackTrace();
	}
}
public void takesScreenshot(String pictureName) {
    	try {
    		String fileName = "images/"+MessageMd5.md5(pictureName)+".png";
    		File file = new File("reports/html-report/"+fileName);
    		if(file.exists()) {
    			file.delete();
    		}
    		File scrFile = ((TakesScreenshot)browser).getScreenshotAs(OutputType.FILE);
		FileUtils.copyFile(scrFile, file);
		Gauge.writeMessage("<img src='../"+fileName+"' width='800' height='480'");
		} catch (IOException e) {
			e.printStackTrace();
		}
}

Another approach, I created a step to take screenshot between scenarios.

@Step("Take a screenshot with the name <pictureName>.")
public void takesScreenshot(String pictureName) {
    	try {
    		String fileName = "images/"+MessageMd5.md5(pictureName)+".png";
    		File file = new File("reports/html-report/"+fileName);
    		if(file.exists()) {
    			file.delete();
    		}
    		File scrFile = ((TakesScreenshot)browser).getScreenshotAs(OutputType.FILE);
		FileUtils.copyFile(scrFile, file);
		Gauge.writeMessage("<img src='../"+fileName+"' width='800' height='480'");
		} catch (IOException e) {
			e.printStackTrace();
		}
}

Congratulations Gauge team, it's a fantastic application, I imagine incredible possibility of using this tool like: Automation Test, Performance Test, Load Test, Functional Specification...

@zabil zabil added this to the 1.1 milestone May 29, 2018
@sriv
Copy link
Member

sriv commented Jun 7, 2018

I am going to start work on this.

Notes:

  • Gauge shall expose a screenshot api via language runners. For ex. gauge-ruby shall have Gauge.capture_screenshot .
  • Mechanism to capture the screenshot: The behaviour would be the same as capturing the screenshot for failures:
    • By default gauge will capture the active desktop (using the screenshot plugin)
    • CustomScreenshotGrabber will be used when configured.
    • screenshot_enabled property will be honoured. Disabling screenshots will result in no screenshots (failure or otherwise)
  • Reports: The screenshot will be shown similar to the failure screenshots. These shall be inlined as a base64 image, and hence will not be available as a separate file.

Thoughts/Feedback welcome.

@ajoecker
Copy link
Contributor

ajoecker commented Jun 7, 2018

reason for not have them as separate files ?

@sriv
Copy link
Member

sriv commented Jun 7, 2018

Mostly historic. It used to be a single page application, but had performance issues when loading huge suite results. We did not externalize the screenshots when we used the Golang templating.

So, given the current implementation, it is simpler to include the screenshots as inline base64 images. I would like to know if the preference is to have files.

@ajoecker
Copy link
Contributor

ajoecker commented Jun 7, 2018

personally yes. when filing e.g. a bug ticket i do not need to somehow link the whole report with all its files, but can simply add this one screenshot that shows the failure to the ticket

sriv added a commit to getgauge/gauge-proto that referenced this issue Jun 25, 2018
sriv added a commit to getgauge/gauge-csharp that referenced this issue Jun 25, 2018
sriv added a commit that referenced this issue Jun 26, 2018
@ghost ghost assigned sriv Jun 26, 2018
sriv added a commit to getgauge/html-report that referenced this issue Jun 28, 2018
@sriv
Copy link
Member

sriv commented Jul 3, 2018

Language runner support:

sriv added a commit to getgauge/gauge-csharp that referenced this issue Jul 9, 2018
sriv added a commit to getgauge/gauge-csharp that referenced this issue Jul 10, 2018
sriv added a commit that referenced this issue Jul 10, 2018
sriv added a commit that referenced this issue Jul 10, 2018
sriv added a commit that referenced this issue Jul 10, 2018
allow screenshots to be taken via test code, #632

tests for screenshot mapping, #632

fixed vendoring, travis and appveyor build scripts

remove godep, use go 1.10

use proto.Equal to check proto message equality

reduce build log, use --verbose to print details

run appveyor tests in parallel
@sriv
Copy link
Member

sriv commented Jul 19, 2018

Should be available in nightly >= 18/07/2018

olejkavn pushed a commit to olejkavn/gauge that referenced this issue Jul 19, 2018
allow screenshots to be taken via test code, getgauge#632

tests for screenshot mapping, getgauge#632

fixed vendoring, travis and appveyor build scripts

remove godep, use go 1.10

use proto.Equal to check proto message equality

reduce build log, use --verbose to print details

run appveyor tests in parallel
Apoorva-GA added a commit to getgauge/gauge-proto that referenced this issue Jul 20, 2018
Added Screenshot for scenarios and specs, getgauge/gauge#632
shubhamsc added a commit to getgauge/gauge-proto that referenced this issue Jul 20, 2018
shubhamsc added a commit to getgauge/html-report that referenced this issue Jul 21, 2018
shubhamsc added a commit to getgauge/html-report that referenced this issue Jul 21, 2018
nehashri pushed a commit to getgauge/html-report that referenced this issue Jul 25, 2018
nehashri pushed a commit to getgauge/html-report that referenced this issue Jul 25, 2018
sriv added a commit to getgauge/gauge-ruby that referenced this issue Jul 30, 2018
added support for capturing screenshot in Step, getgauge/gauge#632
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

6 participants