1

I was trying to take the screenshot of a particular output screen for all the tests.The URL of the page differs for each test depending on the environment (QA,DEV) and also the reference number created. For example "https://xyz-QA-abc.com/ABCDEF/123456"

Here the QA can be changed and 123456 is different for each test.I am doing my work in cucumber using JAVA8.I am not using selenium webdriver.I tried with the code below in HOOKS.But it is not working.It is showing error in browser,attach,buffer,base64png .Could someone help me with a better code

if(scenario.isFailed()){
    return browser.takeScreenshot()
   .then((base64png)=>{
  scenario.attach(new Buffer(base64png,'base64'),'image/png');
});
RRR
  • 75
  • 2
  • 11
  • If you are not using using selenium driver then what is the browser automation tool being used? What are the errors shown? Compilation? – André Barbosa Nov 02 '17 at 15:37

1 Answers1

0

Try this:

byte[] screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
scenario.embed(screenshot, "image/png");
ncvetkovic
  • 31
  • 6
  • Could you please tell what should I do to add TakesScreenshot,driver and outputType.It is showing error there.I am so sorry for asking silly questions.I am a beginner in automation – RRR Nov 03 '17 at 11:46
  • This question has been answered already: [Take a screenshot with Cucumber](https://stackoverflow.com/questions/16160200/take-a-screenshot-with-cucumber) – ncvetkovic Nov 03 '17 at 12:56
  • I think it is not answering what I asked.I will make it clear.I would like to know do we need to add any packages for this.My understanding is TakesScreenshot is an interface.So Do I need to add any package ? It is showing 'Cannot resolve symbol' error for TakesScreenshot,driver and OutputType – RRR Nov 03 '17 at 13:00