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

Support for screenshots gone? #25

Closed
rgeraldporter opened this issue Sep 20, 2018 · 28 comments
Closed

Support for screenshots gone? #25

rgeraldporter opened this issue Sep 20, 2018 · 28 comments
Assignees

Comments

@rgeraldporter
Copy link

I was wondering if the support for screenshots that nightwatch-cucumber is gone now? I can't find any references in this repo and configs that worked in n-c do not work now.

@mucsi96
Copy link
Owner

mucsi96 commented Sep 24, 2018

Thank for your contribution. I don't think that's gone just need more manual effort. You want to create screenshots on failure?

@rgeraldporter
Copy link
Author

@mucsi96 I had this sort-of-working until I realized the problems with waitForElement checks.

This is what I was doing, in setup.js

// Passing a callback
After(function(testCase, callback) {
    if (testCase.result.status === Status.FAILED) {
        const world = this;
        const filepath = `./screenshots/${faker.random.uuid()}.png`;
        client.saveScreenshot(filepath, screenshot => {
            try {
                world.attach(screenshot.value, 'image/png', callback);
            } catch(e) {
                callback();
            }
          }
        );
    } else {
        callback();
    }
});

Passing the screenshots object into test_settings.default wasn't doing anything.

@mucsi96
Copy link
Owner

mucsi96 commented Sep 25, 2018

I see. Can you do some deeper investigation on this? I am not at my computer for 2 weeks

@flashbackzoo
Copy link
Contributor

flashbackzoo commented Dec 3, 2018

When creating a client in createSession shouldn't the reporter constructor be passed settings (the third argument)?

export async function createSession(options: IOptions): Promise<Api> {
  createRunner(options);
  const settings = runner.test_settings;
  client = createClient(settings, new reporter([], 0, {}, {}));
  await client.startSession();
  log('Session created');
  return client.api;
}

Currently it is being passed an empty Object, which is then passed to the Screenshot constructor when the Reporter is initialised here:

https://github.com/nightwatchjs/nightwatch/blob/c3e87ff8e607006a3acf1afa3468c2a7d7103973/lib/core/reporter.js#L11

Note that when no Reporter is supplied, Nightwatch will pass settings to the default SimplifiedReporter it creates, here:

See here https://github.com/nightwatchjs/nightwatch/blob/master/lib/index.js#L414

I haven't had time to test this yet, so may not be this issue...

UPDATE

I've done some testing and this doesn't seem to be the issue. In addition to createSession not passing settings to the Reporter constructor, Reporter looks like it's passing an additional (incorrect) argument to Screenshots see https://github.com/nightwatchjs/nightwatch/blob/master/lib/testsuite/reporter.js#L21

The Screenshots class expects only one argument, which should be settings, see https://github.com/nightwatchjs/nightwatch/blob/master/lib/testsuite/screenshots.js#L7

I made these "fixes" locally, ran my tests again, but still no screenshots. My failing test is being treated as passed, and is being handled by the success handler here https://github.com/nightwatchjs/nightwatch/blob/master/lib/http/response.js#L58

Note that screenshotContent is not passed to the handler in the success case, and in my case screenshotContent was undefined anyway.

Wondering if this is related to #26

Sorry for the noise here - just thought I'd share my findings incase it points someone else in the right direction.

@mucsi96 mucsi96 added this to To do in nightwatch-api Dec 4, 2018
@mucsi96 mucsi96 self-assigned this Dec 15, 2018
@mucsi96 mucsi96 moved this from To do to In progress in nightwatch-api Dec 15, 2018
@mucsi96
Copy link
Owner

mucsi96 commented Dec 16, 2018

I have created a PR for this. After review we can release it. After that I am waiting for your feedback 👍

nightwatch-api automation moved this from In progress to Done Dec 17, 2018
@mucsi96
Copy link
Owner

mucsi96 commented Dec 17, 2018

Feature released in 2.1.0. This is how you can enable it https://nightwatch-api.netlify.com/#screenshots-on-failure

@gnaneswarreddy
Copy link

I followed the same example in cucumber-example and one of my step definition for title got failed, still After function has been success and no screenshot is getting saved to the folder. Could anyone help me what is the actual issue i am using cucumber-js, html reporter latest versions and nightwatch api latest version.

Thanks,
Eswar

@mucsi96
Copy link
Owner

mucsi96 commented Mar 15, 2019

Have you enabled the screenshot creation on failure? Search for screenshot in the docs. Looks like its missing from the cucumber html repoter docs. Will update the docs

@gnaneswarreddy
Copy link

yes i enabled

screenshots:{
enabled:true,
path:'to my local drive'
on_failure:true
on_error:true
}

@mucsi96
Copy link
Owner

mucsi96 commented Mar 15, 2019

Then something is wrong with screenshot creation. What path are you using? Maybe there is something about it. Can you try both relative and absolute path. Currently it works fine on my machine and on CI Linux

@gnaneswarreddy
Copy link

I used both relative and absolute path still not working and below are the versions i am using
nightwatch-api - 2.1.1, cucumber-html-reporter: 4.0.5 and cucumber: 5.1.0 OS: Windows7. Am i missing anything?

@mucsi96
Copy link
Owner

mucsi96 commented Mar 15, 2019

The last think I car recommend is to clone the repo and try to run the examples on your machine. Check if screenshot is created in cucumber example if you make some step failing

@spnraju
Copy link
Collaborator

spnraju commented Mar 15, 2019

Even I have tried with cucumber-example by altering line number 17 as below and found screenshots under screenshots folder.

await client.assert.visible('input[name="q3423"]');

@mucsi96
Copy link
Owner

mucsi96 commented Mar 15, 2019

@gnaneswarreddy any updates?

@gnaneswarreddy
Copy link

I did a small mistake in nightwatch-conf.js and i fixed it now screenshots are loading fine. Thankyou @mucsi96 and @spnraju

@mucsi96
Copy link
Owner

mucsi96 commented Mar 15, 2019

Great! Happy to help! Will add screenshot enabling to html reporting section

@gnaneswarreddy
Copy link

Hi,
Not sure if its the right forum to post but i am looking to perform a scroll down to a particular element using nightwatch api and perfecto. Is there any code available or please let me know if anyone has done it.

@spnraju
Copy link
Collaborator

spnraju commented Apr 4, 2019

@gnaneswarreddy You are right. This is not the right forum to ask. But just to help you out, check the below URL.

http://nightwatchjs.org/api/moveToElement.html
http://nightwatchjs.org/api/moveTo.html

@gnaneswarreddy
Copy link

Hi,
one small question about screenshots i removed on_failure:true, on_error:true and i was hoping that passed screenshots would be saved to the folder. Am i missing anything? Will the passed screenshots cannot be saved.

@gnaneswarreddy
Copy link

Hi,
Is the screenshots generated only on failure?

Thanks,
Gnaneswar

@mucsi96
Copy link
Owner

mucsi96 commented Apr 10, 2019

Hi! Unfortunately this is implemented currently to skip the the successful cases. See

if (client && client.api.screenshotsPath) {

But it's quite easy to change. Would appreciate if you can contribute and send a pull request for this. Also please create a separate issue for this as this thread is getting too long :)

@gnaneswarreddy
Copy link

Hi @mucsi96,

Actually i have a laptop which is related to the customer and cannot do the pull request and upload it. I can just use the npm package. Is @spnraju will be able to help as in my personal laptop it will take time to setup with everything?

Thanks.

@mucsi96
Copy link
Owner

mucsi96 commented Apr 16, 2019

Based on Nightwatch docs it also doesn't support auto screenshot creation on success. See

Selenium generates screenshots when command errors occur. With on_failure set to true, also generates screenshots for failing or erroring tests. These are saved on the disk.
Since v0.7.5 you can disable screenshots for command errors by setting "on_error" to false.
Example:

"screenshots" : {
  "enabled" : true,
  "on_failure" : true,
  "on_error" : false,
  "path" : ""
}

But you can manually create screenshot any time.

@gnaneswarreddy
Copy link

Yes i tried the same way for failure and it was successfully getting saved to disk. But i have to use the screenshots used in pass scenario in cucumber-html-reporter. As you have mentioned if (client && client.api.screenshotsPath) { Can we have the option so that we can also save the screenshots and it automatically be pulled up in reporter framework also?

@mucsi96
Copy link
Owner

mucsi96 commented Apr 16, 2019

When do you want to do the scrrenshots? After every step or after every scenario as last step?

@gnaneswarreddy
Copy link

after every step if possible

@mucsi96
Copy link
Owner

mucsi96 commented Apr 17, 2019

It's easy to make screenshot after every scenario using cucumber hooks. Unfortunatly the step hook was removed from cucumber. So its harder. Also I dont think we can do much in this package

@mucsi96
Copy link
Owner

mucsi96 commented Apr 17, 2019

This is the issue you can follow cucumber/cucumber-js#997

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

No branches or pull requests

5 participants