Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Attachments from step definitions #1109

Closed
vikraman2212 opened this issue Jun 26, 2018 · 6 comments
Closed

Attachments from step definitions #1109

vikraman2212 opened this issue Jun 26, 2018 · 6 comments

Comments

@vikraman2212
Copy link

I'm not able to use this.attach in AfterAll methods and in Step definitions.

import { setWorldConstructor } from "cucumber";

export function World ({attach, parameters}) {
this.attach = attach;
this.parameters = parameters;

};
setWorldConstructor(World);

Under Hooks.ts

After(async function(scenario) {
if (scenario.result.status === Status.PASSED) {
// screenShot is a base-64 encoded PNG
const screenShot = await browser.takeScreenshot();
this.attach(screenShot, "image/png");
this.attach("attach is working perfectly fine");
}
});

AfterAll({timeout: 100 * 1000}, async () => {
this.attach("test");
await browser.quit();
});

Under Step Definitions:

import { browser, protractor, ExpectedConditions, $, by } from "protractor";
import { expect } from "chai";

import { GenerticActions } from "../genericfunctions/genericActions";
import { Transactions } from "../pageObjects/transactions";
import { Given, When, Then} from "cucumber";

var GenericActions = new GenerticActions();
var TransactionsPage = new Transactions();

Given('Transactions page is launched', { timeout: 60 * 1000 }, async () => {
// Write code here that turns the phrase above into concrete actions
await GenericActions.LaunchBrowser();

browser.actions().mouseMove(TransactionsPage.name).perform();

});

When('the title {string} is visible', async (string) => {

this.attach("attach from step definition");
await GenericActions.ValidateTitle(string);

});

I'm getting error while running the above mentioned code

.F--..Unhandled rejection VError: an AfterAll hook errored, process exiting: typeScript\support\hooks.js:34: this.attach is not a function
at C:\Vikram\FSOe\automation\citi-qa\node_modules\cucumber\src\runtime\index.js:36:15
at Generator.next ()
at Generator.tryCatcher (C:\Vikram\FSOe\automation\citi-qa\node_modules\bluebird\js\release\util.js:16:23)
at PromiseSpawn._promiseFulfilled (C:\Vikram\FSOe\automation\citi-qa\node_modules\bluebird\js\release\generators.js:97:49)
at Promise._settlePromise (C:\Vikram\FSOe\automation\citi-qa\node_modules\bluebird\js\release\promise.js:574:26)
at Promise._settlePromise0 (C:\Vikram\FSOe\automation\citi-qa\node_modules\bluebird\js\release\promise.js:614:10)
at Promise._settlePromises (C:\Vikram\FSOe\automation\citi-qa\node_modules\bluebird\js\release\promise.js:693:18)
at Async._drainQueue (C:\Vikram\FSOe\automation\citi-qa\node_modules\bluebird\js\release\async.js:133:16)
at Async._drainQueues (C:\Vikram\FSOe\automation\citi-qa\node_modules\bluebird\js\release\async.js:143:10)

@vikraman2212
Copy link
Author

FYI. If I remove async, and change it to function, I could attach from step definition

Then('to test the attachment', function () {
// Write code here that turns the phrase above into concrete actions
this.attach("something to test the attachment");
});

@charlierudolph
Copy link
Member

AfterAll doesn't have access to a world instance and thus cannot add attachments as the attach method is added to world instances.

What is your use case for attaching something in an after all hook?

@vikraman2212
Copy link
Author

I was just testing out attachments in AfterAll Hook. However, my real issue is attaching string or screenshot from step definitions.
If I use async in Given, When, or Then, I'm not able to attach anything using this.attach.

@charlierudolph
Copy link
Member

charlierudolph commented Jun 28, 2018

You can use async, but you can't use arrow functions. See the FAQ

@charlierudolph
Copy link
Member

Closing due to lack of response and appears to be resolved. Please reopen if needed

@lock
Copy link

lock bot commented Sep 7, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Sep 7, 2019
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants