cucumber attach screenshot to stepresult - cucumber

I'm trying to generate report with cucumber-html-reporter. On it's GitHub page I saw a fancy bootstrap report, where a screenshot is attached to the failed step itself.
https://www.npmjs.com/package/cucumber-html-reporter
I'm working with cucumber-js 2.3.1 and cannot attach a screenshot to the StepResult.
I can attach a screenshot only in the After hook, where the World is available.
After(function (scenario) {
if (scenario.isFailed()) {
const world = this;
return browser.takeScreenshot().then(function (screenShot) {
world.attach(screenShot, 'image/png');
});
}
});
This is working fine, but unfortunately the screenshot is attached to the "After" step, not to the failed one.
I have tried this:
registerHandler('StepResult', function (StepResult) {
if (StepResult.isFailed()) {
return browser.takeScreenshot().then(function (screenShot) {
var decodedImage = new Buffer(screenShot, 'base64');
StepResult.attachments.push({
data: decodedImage.toString('base64'),
mimeType: 'image/png'
});
});
}
});
It works, the attachment is added, but not rendered into the report, since the cucumber json_formatter.handleStepResult is executed BEFORE the 'StepResult' hook is invoked.
Can someone show me a solution?
Thanks!

The reporter would show the Screenshot link in the failed STEP if you capture screenshot in the STEP itself. If you capture at the AFTER hook, it will show in the hook.
On the example shown in the Github page, it attaches the screenshot to the Step, and so it shows to the "then" step. Please take a look at here for more info.

Related

No permission to execute Netsuite suitelet script as administrator role

I created a UE script that adds a button and loads in a CS script. The CS script in turn calls a SL script when the button is clicked.
I deployed the suitelet script to be executed as the administrator role with every role also being part of the audience.
My CS script:
https.post.promise({
url: "https://"+domain+".app.netsuite.com/app/site/hosting/scriptlet.nl?script=687&deploy=1",
body: params
})
.then(function (response){
log.debug({title: 'Response',details: response});
console.log('response', response);
})
The result I get is HTML telling me I have to login to access the page. When I actually take the URL and paste it myself in the browser however, it does work. Does anyone know why this happens?
I don't know much about https.post.promise method but even I once faced this exact error.
My suggestion here would be to use url.resolveScript method in your ClinetScript that would apparently call your Suitelet Script.
window.onbeforeunload = null;
var suiteletURL = url.resolveScript({
scriptId: 'SUITELET SCRIPT ID HERE',
deploymentId: 'SUITELET DEPLOYMENT ID HERE',
params: {
//If any
}
});
window.open(suiteletURL, '_self', false);
Let me know in case of any issue in the comments below.
It seems the problem was that Netsuite generated an external URL which required authentication always. The following code solved my issue:
var suitletURL = url.resolveScript({
scriptId: 'scriptid',
deploymentId: 'deploymentid',
returnExternalUrl: false
});

Mock network requests in Cypress

I've been tearing my hair out over this for ages now - and I hope someone can help me :)
I've been trying to stub a network request in Cypress for ages now.
commands.js
Cypress.Commands.add('login', (
email = 'email',
password = 'pass'
) => {
cy.server();
cy.visit('url');
cy.get('input[name="username"').type(email);
cy.get('form').submit();
cy.get('input[name="password"').type(password);
cy.get('form').submit();
});
mock.js
describe('mock', function() {
it('user can login', function() {
cy.login();
cy.get('main[role="main"]');
cy.route('GET',
'**/getIncentives*',
{info: {}, results: {}}
).as('oppty');
cy.wait('#oppty');
});
});
Chrome dev tools request
Cypress request failed
Any help here would be really appreciated - I've been going crazy!
Thanks so much,
Ollie
Currently, Cypress cy.route can only stub network requests that use XHRs
Native HTML form elements don't use XMLHTTPRequest, hence you cannot use cy.route to stub it.
Most people don't run into this issue because using native HTML forms is not as common nowadays
Edit:
You are also waiting on the route, but haven't actually done anything in your test. Your test should look something like this:
cy.route('GET',
'**/getIncentives*',
{info: {}, results: {}}
).as('oppty');
// cypress code that would cause a network request.
cy.wait('#oppty');
Also, make sure the request is of type:XHR:
Cypress will only find the network request after it's been aliased. The code in your question indicated you're not doing an action that would cause a network request:
cy.route('GET',
'**/getIncentives*',
{info: {}, results: {}}
).as('oppty');
// cypress expected something to cause a network request here
cy.wait('#oppty');
You should either move the call to route earlier in the test, or move the code that causes the request after the call to route.
Also note that cy.route() may not work with server side rendering (apparently).
I've had this problem when using NextJs, and solved it by first calling some other page, then navigate on the client to the page I actually want to test.
Like so:
describe('test cy.route', function() {
it( 'test 1', () => {
cy.server();
cy.route({
method: 'GET',
url: /.*\/api\/someApiCall/,
response: { 'someApiResponse': 'ok' },
status: 200
} ).as('myRouteAlias');
// go to start page: first page is server side rendered. cy.route doesn't work.
cy.visit('/');
// go to page to be tested: client side, cy.route works then.
cy.get( `a[href="/pageToBeTested"` ).should('exist').click();
// wait for page loaded
cy.url().should('include', 'pageToBeTested' );
// do something that requests '/api/someApiCall'.
invokeFunctionThatDoesTheRequest();
// wait for the request
cy.wait('#myRouteAlias');
});
});

How to get Scenario name from cucumber js?

In case of error I want to be able to log the scenario name. I'm using cucumber.js and node.
Feature file
Scenario: As me I can go to google
Given that I have a computer
When I go to google
Then I see wondrous stuff
I have tried the code below, but the name comes back as an empty string.
When(/^I go to google$/, (scenario) => {
// do something
var scenarioName = scenario.name;
});
By stepping through the code I can see that it's a function.
It has :
[[FunctionLocation]] = Object
[[Scopes]] = Scopes(6)
length = 2
name= ""
It seems like you can't do this in a Given or When, it has to be done in the Before or After hook:
Before((scenario) => {
const scenarioName = scenario.name;
console.log(`${scenarioName}`);
});
I could get the scenario name using this code:
Before((scenario: any) => {
console.log(`Starting scenario ${scenario.sourceLocation.uri}:${scenario.sourceLocation.line} (${scenario.pickle.name})`);
});
As you can see, there's more in there than just the scenario name. The entire test, with all the steps, tags, etc is in the object. I'm using CucumberJS 5.0.3.
I found the scenario name using below code
console.log(`The scenario is ${JSON.stringify(scenario.pickle.name)}.`);

CucumberJS: Take screenshot after each step

Has anybody figured out how to take screenshot for every step of a scenario in cucumberjs, and attach it to the json report?
Apparently this can be done via a custom reporter, using Cucumber event handlers.
browser.takeScreenshot().then((png: any) => {
var decodedImage = new Buffer(png, 'base64');
currentStep.embeddings.push({
data: decodedImage.toString('base64'),
mime_type: 'image/png'
});
});

Nightwatch.js click choose file

Everyone!
about two days trying to find solution to choose the image file for upload using nightwatch.js
Code looks like this:
module.exports = {
'File Upload': function (client) {
client
.url('http://myurl.com')
.click('#selector')
.end();
}
};
we clicked on drag and drop so something like this .setValue('input#fileUpload', require('path').resolve(__dirname + '/testfile.jpg')) can't be exists. And
.keys(client.Keys.DOWN_ARROW)
.keys(client.Keys.ENTER)
not works for this finder window:
I need something like sendKeys() in Selenium to choose the file from finder. Nightwatch.js .keys() works only for internet browser (Firefox for me) window. I need for popup finder to choose the file.
Thx.
Are you heard about online image sharing ,igmur/photobucket, upload the image then save the URL in your 'globals', for example we will have a file images.js in "globals_path":
module.exports ={
image1: 'www.imgur.com/iamge1',
image2: 'www.imgur.com/iamge2',
}
And in your test :
module.exports = {
'File Upload': function (client) {
const images = client.images;
client
.url('http://myurl.com')
.click('#choose-button')
.setValue('#txt-path',iamges.image1)
.click('#submit-button');
.end();
}
};

Resources