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

Images not showing up for nested spec directories #251

Closed
cyberjaime45 opened this issue Feb 20, 2020 · 10 comments
Closed

Images not showing up for nested spec directories #251

cyberjaime45 opened this issue Feb 20, 2020 · 10 comments
Assignees
Labels

Comments

@cyberjaime45
Copy link

Expected behavior

Images created by the new CustomScreenshotWriter should show up for for nested specs directories

Actual behavior

The images links are broken if:
specs specDirectory1 specDirectory2 My-Spec.spec
In the html-plugin the screenshot image links address is expected to be: <root_project>reports/staging/html-report/specs/specFolder1/specFolder1/images/screenshot-c7a2f422-bedc-4215-9d4d-94d004210b0a.png

Steps to reproduce

Create a project with nested spec directories

Gauge version

Gauge version: 1.0.7
Commit Hash: ed7b4fd6

Plugins
-------
flash (0.0.2)
html-report (4.0.9)
java (0.7.4)
json-report (0.3.3)
screenshot (0.0.1)
@sriv sriv added the bug label Feb 20, 2020
@sriv sriv self-assigned this Feb 20, 2020
@freedombycrypto
Copy link

Waiting for this release. I am also having folder structure as

specs
    - teamName
           - regression
                  - ui
                       - file.spec
                  -api
                       - file.spec.

would be nice if it accepts for any folder structure under specs.

@cyberjaime45
Copy link
Author

@Vishnu1067 I tested this branch (251_nested_dir_images). The bug has been fixed. I downloaded the source code and compiled myself. Let me know if you need the zip file for your machine. I hope they release soon.

@freedombycrypto
Copy link

freedombycrypto commented Feb 26, 2020

I have checkout this branch (251_nested_dir_images) and compiled go run build/make.go && go run build/make.go --install

and now gauge -v

Gauge version: 1.0.7

Plugins
-------
html-report (4.0.10)
java (0.7.4)
screenshot (0.0.1)
spectacle (0.1.3)
xml-report (0.2.1)

When i use ICustomScreenshotGrabber, screenshots are showing in the report (deprecated ICustomScreenshotGrabber)

public class CustomScreenGrabber implements ICustomScreenshotGrabber {

@Override
    public byte[] takeScreenshot() {
       return ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
   }

But if i use CustomScreenshotWriter, screenshot not placed in images and it is crashed.

public class CustomScreenGrabber implements CustomScreenshotWriter {

 @Override
    public String takeScreenshot() {
        return ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE).getName();
  }

Correct me if i am doing anything wrong here.

Also not sure i must put env gauge_screenshots_dir as per this PR
getgauge/gauge-java#333

@freedombycrypto
Copy link

@sriv can you please consider to fix this issue or am i missing something? Please advise.

I have checkout this branch (251_nested_dir_images) and compiled go run build/make.go && go run build/make.go --install

and now gauge -v

Gauge version: 1.0.7

Plugins
-------
html-report (4.0.10)
java (0.7.4)
screenshot (0.0.1)
spectacle (0.1.3)
xml-report (0.2.1)

When i use ICustomScreenshotGrabber, screenshots are showing in the report (deprecated ICustomScreenshotGrabber)

public class CustomScreenGrabber implements ICustomScreenshotGrabber {

@Override
    public byte[] takeScreenshot() {
       return ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
   }

But if i use CustomScreenshotWriter, screenshot not placed in images and it is crashed.

public class CustomScreenGrabber implements CustomScreenshotWriter {

 @Override
    public String takeScreenshot() {
        return ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE).getName();
  }

Correct me if i am doing anything wrong here.

Also not sure i must put env gauge_screenshots_dir as per this PR
getgauge/gauge-java#333

@sriv
Copy link
Member

sriv commented Feb 27, 2020

@Vishnu1067 - sure. will check this out as well.

@sriv
Copy link
Member

sriv commented Feb 27, 2020

@Vishnu1067 - your custom screengrabber imlpementation is incorrect. You need to write the file and then return the path. The location of screenshot should be read from gauge_screenshots_dir. Something like this:

    // Return a screenshot file name
    @Override
    public String takeScreenshot() {
        TakesScreenshot driver = (TakesScreenshot) DriverFactory.getDriver();
        String screenshotFileName = String.format("screenshot-%s.png", UUID.randomUUID().toString());
        File screenshotFile = new File(Paths.get(System.getenv("gauge_screenshots_dir"), screenshotFileName).toString());
        File tmpFile = driver.getScreenshotAs(OutputType.FILE);
        try {
            FileUtils.copyFile(tmpFile, screenshotFile);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return screenshotFileName;
    }

I tried this and am able to see the screenshots in all pages (even the nested ones).

PS - the docs mention this: https://docs.gauge.org/writing-specifications.html?os=windows&language=java&ide=vscode#taking-custom-screenshots

@freedombycrypto
Copy link

Ok thank you @sriv. I will try it out

@freedombycrypto
Copy link

@sriv It works, Thanks.

@freedombycrypto
Copy link

@sriv When will be expected to release this fix?

@sriv
Copy link
Member

sriv commented Mar 3, 2020

The fix is being tested, please watch out for the PR #253 to be merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants