gauge icon indicating copy to clipboard operation
gauge copied to clipboard

Gauge is not taking screen shots when tests are run in Linux - Ubuntu container in a headless mode #2167 tried this, the issue still exists.

Open harimadusumilli opened this issue 3 years ago • 4 comments

Thank you for your advise. We did try to change the path using the "" to "/". Although we have tried this, the issue still exists.

var fullPath = Path.Combine(DriverScript.GetRelativePath() + @"/reports/html-report/images",filename);

Originally posted by @harimadusumilli in https://github.com/getgauge/gauge/issues/2167#issuecomment-974084030

harimadusumilli avatar Nov 19 '21 13:11 harimadusumilli

Adding the Support Issue Contents of 2167 as it seems to have been accidentally closed by the Gauge Team. Hello Sriv,

We have tried based on the suggestions you have provided above, it appears that the code is not being called. When we execute we get the following error in the console log of Jenkins. The same code works in Dotnet Core 3.x and not in Dotnet 5.x Not sure if the Gauge.CSharp.Lib has anything to do with it, that is causing this issue.

Error log in job console: panic: empty display string goroutine 1 [running]: main.main() /Users/vagrant/go-agent-17.4.0/pipelines/Screenshot/src/github.com/getgauge/gauge_screenshot/main.go:44 +0x19c [0;32m ✔[0mpanic: empty display string goroutine 1 [running]: main.main() /Users/vagrant/go-agent-17.4.0/pipelines/Screenshot/src/github.com/getgauge/gauge_screenshot/main.go:44 +0x19c [0;32m ✔[0mpanic: empty display string goroutine 1 [running]: main.main() /Users/vagrant/go-agent-17.4.0/pipelines/Screenshot/src/github.com/getgauge/gauge_screenshot/main.go:44 +0x19c

Failed to read screenhsot open /home/jenkins/agent/workspace/bn-qa-testing-center/Donet5Container/.gauge/screenshots/screenshot-1cd324a7-8da3-44c1-aadc-ee02d0d86dd1.png: no such file or directory Failed to read screenhsot open /home/jenkins/agent/workspace/bn-qa-testing-center/Donet5Container/.gauge/screenshots/screenshot-b472850b-b54a-433b-a18a-82da47eb2437.png: no such file or directory Failed to read screenhsot open /home/jenkins/agent/workspace/bn-qa-testing-center/Donet5Container/.gauge/screenshots/screenshot-99d08c95-d519-4729-8af4-f0bb66533094.png: no such file or directory Successfully generated html-report to => /home/jenkins/agent/workspace/bn-qa-testing-center/Donet5Container/reports/html-report/index.html

Gauge Screenshot code:

using System; using System.IO; using OpenQA.Selenium; using Gauge.CSharp.Lib; namespace Gauge.CSharp.Lib { class CustomScreenGrabber : ICustomScreenshotWriter { public string TakeScreenShot() { string screenshotFolder; Console.WriteLine("Screenshot Captured Starting"); screenshotFolder = (String)Path.Combine(Environment.GetEnvironmentVariable("gauge_screenshots_dir")).Replace("","/"); string filename = String.Format("screenshot-{0}.png", Guid.NewGuid().ToString()); var fullPath = Path.Combine(screenshotFolder,filename); byte [] screenshot;

   if(DriverScript.driverflg.Equals("Win")){
        screenshot = ((ITakesScreenshot)DriverScript.GetWiniumDriver()).GetScreenshot().AsByteArray;
    }else{
        screenshot = ((ITakesScreenshot)DriverScript.GetSeleniumDriver()).GetScreenshot().AsByteArray;
    }
    File.WriteAllBytes(fullPath,screenshot);
    Console.WriteLine("Screenshot Captured Successfully");
    return fullPath;
}

} }

Note:

https://github.com/getgauge/gauge_screenshot/blob/master/main.go

harimadusumilli avatar Dec 09 '21 13:12 harimadusumilli

Hello Gauge Support,

I am not sure if anyone has had a chance to look at this issue. I have tried the recommendations made and we still seem to be having issues with DOTNET(core) 5.x . The screen shots work fine with Dotnet-Core 3.x. Any tips and suggestions are appreciated.

Thanks, Hari

harimadusumilli avatar Jan 02 '22 14:01 harimadusumilli

Can you try marking the CustomScreenGrabber class public? Having a custom screenshot writer should prevent gauge_screenshot from being invoked

sriv avatar Jan 04 '22 01:01 sriv

We have tried working with DOTNET 5 and noticed that the screen shot does not work when have this code in a DLL. Code Snippet below: using System; using System.IO; using OpenQA.Selenium;

namespace Gauge.CSharp.Lib { public class CustomScreenGrabber : ICustomScreenshotWriter { public string TakeScreenShot() { Console.WriteLine("Screenshot Captured Starting"); string filename = String.Format("screenshot-{0}.png", Guid.NewGuid().ToString()); var sfullPath = Path.Combine(DriverScript.GetRelativePath() + @"/.gauge/screenshots",filename); byte [] screenshot; if(DriverScript.driverflg.Equals("Win")){ screenshot = ((ITakesScreenshot)DriverScript.GetWiniumDriver()).GetScreenshot().AsByteArray; }else{ screenshot = ((ITakesScreenshot)DriverScript.GetSeleniumDriver()).GetScreenshot().AsByteArray; } sfullPath=sfullPath.Replace("\","/"); File.WriteAllBytes(sfullPath,screenshot); Console.WriteLine("Screenshot Captured Successfully" + filename); return filename; } } }

When the same piece of code is inside a .CS (Csharp) file and used, it works, meaning it calls our custom screen shot code. We wanted to package the screen shot as a a dll so that we don't have to include this code in a CS file. We are noticing that when we have the above code in a DLL it does not call our custom screenshot code and it calls the code that Gauge by default provides.

The above piece of code when packaged as a DLL with DOTNET2.0 works with our custom screen shot code

harimadusumilli avatar Mar 01 '22 13:03 harimadusumilli