-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Comments
FYI. If I remove async, and change it to function, I could attach from step definition Then('to test the attachment', function () { |
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? |
I was just testing out attachments in AfterAll Hook. However, my real issue is attaching string or screenshot from step definitions. |
You can use async, but you can't use arrow functions. See the FAQ |
Closing due to lack of response and appears to be resolved. Please reopen if needed |
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. |
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)
The text was updated successfully, but these errors were encountered: