codeceptjs / codeceptjs/CodeceptJS

Gherkin (BDD) step hook and name

Đang mở
#1,301 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
JavaScript
Star
4.2k
Fork
757
Merge trung bình
2 ngày 9 giờ
Pull request đã merge (30 ngày)
16

Mô tả

#### What are you trying to achieve?
I need the step name from the BDD file in before step hook.
#### What do you get instead?
I am using step.metaStep to get the name of the step. However, the parameterized step names are not being retrieved.
> Provide console output if related. Use `--verbose` mode for more details.

```bash
Admins-MacBook-Pro:Codeceptv1 admin$ npm run test

> codecept_poc@1.0.0 test /Users/admin/Desktop/My_Data/QuantumJS/Codeceptv1
> codeceptjs run-multiple wiki --grep "@kulin"

Use JS config file
undefined
Use JS config file
undefined
>>> PerfectoWebDriverIO() begin loading configuration.
>>> PerfectoWebDriverIO() loading configuration completed.
Tests are running!
[1.wiki:Firefox] CodeceptJS v1.4.4
[1.wiki:Firefox] Using test root "/Users/admin/Desktop/My_Data/QuantumJS/Codeceptv1"

[1.wiki:Firefox] Perfecto Wiki - search @wiki @wiki1 @wiki2 @kulin --
>>> _startBrowser() begin creating reportingClient.
>>> _startBrowser() creation of reportingClient completed.
[14:51:25] COMMAND POST "/nexperience/perfectomobile/wd/hub/session"
[14:51:25] DATA {"desiredCapabilities":{"javascriptEnabled":true,"locationContextEnabled":true,"handlesAlerts":true,"rotatable":true,"browserName":"Firefox","user":"kulins@perfectomobile.com","securityToken":"eyJhbGciOiJSUzI1NiJ9.eyJqdGkiOiIzOWY3MWRjOS1jNTIwLTQ4NmEtYTJmZS1jZDBmYWMyMWY4ZjYiLCJleHAiOjAsIm5iZiI6MCwiaWF0IjoxNTI0MjEwODA0LCJpc3MiOiJodHRwczovL2F1dGgucGVyZmVjdG9tb2JpbGUuY29tL2F1dGgvcmVhbG1zL3BzLXB ... (840 more bytes)","platformName":"Windows","platformVersion":"10","browserVersion":"62","_":"4 more keys: [\"resolution\",\"location\",\"loggingPrefs\",\"requestOrigins\"]"}}
[14:51:44] INFO SET SESSION ID 89018528-a9a2-44b0-ae4a-7c854b6135fd
[14:51:44] RESULT {"reportPdfUrl":"https://ps.reporting.perfectomobile.com/export/api/v1/test-executions/pdf?externalId[0]=kulins@perfectomobile.com_RemoteWebDriver_18-11-01_09_21_26_851&_timestamp[0]=1541064086231","l ... (1471 more bytes)
[14:51:44] COMMAND POST "/nexperience/perfectomobile/wd/hub/session/89018528-a9a2-44b0-ae4a-7c854b6135fd/timeouts"
[14:51:44] DATA {"type":"script","ms":1000}
>>> Test Start method called
[14:51:44] COMMAND POST "/nexperience/perfectomobile/wd/hub/session/89018528-a9a2-44b0-ae4a-7c854b6135fd/execute"
[14:51:44] DATA {"script":"mobile:test:start","args":[{"name":"Go to wiki","jobName":"PerfectoWebDriverIO Test Job","jobNumber":38,"jobBranch":"Not Branched Yet","projectName":"Perfecto-CodeceptJS Example Tests","projectVersion":"v0.1a","tags":["codeceptjs","webdriverio","nodejs","example tag"],"customFields":[]}]}
[14:51:44] RESULT "N/A"
>>> Before step method calledGiven I resize to a 1024x768 screen size
[14:51:45] COMMAND POST "/nexperience/perfectomobile/wd/hub/session/89018528-a9a2-44b0-ae4a-7c854b6135fd/execute"
[14:51:45] DATA {"script":"mobile:step:start","args":[{"name":"Given I resize to a 1024x768 screen size "}]}
[14:51:46] COMMAND POST "/nexperience/perfectomobile/wd/hub/session/89018528-a9a2-44b0-ae4a-7c854b6135fd/window/current/size"
[14:51:46] DATA {"width":1024,"height":768}
>>> Before step method calledAnd I go to the wiki home page
[14:51:47] COMMAND POST "/nexperience/perfectomobile/wd/hub/session/89018528-a9a2-44b0-ae4a-7c854b6135fd/execute"
[14:51:47] DATA {"script":"mobile:step:start","args":[{"name":"And I go to the wiki home page "}]}
[14:51:48] COMMAND POST "/nexperience/perfectomobile/wd/hub/session/89018528-a9a2-44b0-ae4a-7c854b6135fd/url"
[14:51:48] DATA {"url":"http://www.wikipedia.com/"}
>>> **Before step method calledLogin: searchWiki**
[14:51:49] COMMAND POST "/nexperience/perfectomobile/wd/hub/session/89018528-a9a2-44b0-ae4a-7c854b6135fd/elements"
[14:51:49] DATA {"using":"id","value":"searchInput"}
[14:51:49] RESULT [{"ELEMENT":"91eb144f-1673-43e6-9b3b-242627ff8df6"}]
[14:51:49] COMMAND POST "/nexperience/perfectomobile/wd/hub/session/89018528-a9a2-44b0-ae4a-7c854b6135fd/element/91eb144f-1673-43e6-9b3b-242627ff8df6/clear"
[14:51:49] DATA {}
[14:51:50] COMMAND POST "/nexperience/perfectomobile/wd/hub/session/89018528-a9a2-44b0-ae4a-7c854b6135fd/element/91eb144f-1673-43e6-9b3b-242627ff8df6/value"
[14:51:50] DATA {"value":["P","e","r","f","e","c","t","o"],"text":"Perfecto"}
>>> **Before step method calledLogin: clickSearchBtn**
[14:51:50] COMMAND POST "/nexperience/perfectomobile/wd/hub/session/89018528-a9a2-44b0-ae4a-7c854b6135fd/elements"
[14:51:50] DATA {"using":"css selector","value":".svg-search-icon"}
[14:51:50] RESULT [{"ELEMENT":"762a95a3-5a44-48a6-81b6-cc6794b1eefa"}]
[14:51:50] COMMAND POST "/nexperience/perfectomobile/wd/hub/session/89018528-a9a2-44b0-ae4a-7c854b6135fd/element/762a95a3-5a44-48a6-81b6-cc6794b1eefa/click"
[14:51:50] DATA {}
>>> Before step method calledGiven I resize to a 200x400 screen size
[14:51:51] COMMAND POST "/nexperience/perfectomobile/wd/hub/session/89018528-a9a2-44b0-ae4a-7c854b6135fd/execute"
[14:51:51] DATA {"script":"mobile:step:start","args":[{"name":"Given I resize to a 200x400 screen size "}]}
[14:51:52] COMMAND POST "/nexperience/perfectomobile/wd/hub/session/89018528-a9a2-44b0-ae4a-7c854b6135fd/window/current/size"
[14:51:52] DATA {"width":200,"height":400}
>>> Before step method calledAnd I wait for 1 seconds
[14:51:52] COMMAND POST "/nexperience/perfectomobile/wd/hub/session/89018528-a9a2-44b0-ae4a-7c854b6135fd/execute"
[14:51:52] DATA {"script":"mobile:step:start","args":[{"name":"And I wait for 1 seconds "}]}
[1.wiki:Firefox] ✔ Go to wiki in 9538ms
[14:51:55] COMMAND POST "/nexperience/perfectomobile/wd/hub/session/89018528-a9a2-44b0-ae4a-7c854b6135fd/execute"
[14:51:55] DATA {"script":"mobile:test:end","args":[{"success":true}]}
>>> perfectoClient.testStop completed for Go to wiki.
this.browser: { state: 'fulfilled',
value:
{ sessionId: '89018528-a9a2-44b0-ae4a-7c854b6135fd',
state: null,
hCode: 1234613025,
value:
{ reportPdfUrl: 'https://ps.reporting.perfectomobile.com/export/api/v1/test-executions/pdf?externalId[0]=kulins@perfectomobile.com_RemoteWebDriver_18-11-01_09_21_26_851&_timestamp[0]=1541064086231',
loggingPrefs: [Object],
resolution: '1280x1024',
deviceName: '1_355EE5E6-5D16-4140-8880-AC93D43E71A2',
requestOrigins: [Object],
password: '',
deviceSessionId: 'kulins@perfectomobile.com_RemoteWebDriver_18-11-01_09_21_26_851',
platformVersion: '10',
browserVersion: '62',
host: 'ps.perfectomobile.com',
singleTestReportUrl: 'https://ps.reporting.perfectomobile.com/library?externalId[0]=kulins@perfectomobile.com_RemoteWebDriver_18-11-01_09_21_26_851&_timestamp[0]=1541064086231',
browserName: 'Firefox',
takesScreenshot: true,
javascriptEnabled: true,
platformName: 'Windows',
rotatable: true,
testGridReportUrl: 'https://ps.reporting.perfectomobile.com/library?externalId[0]=kulins@perfectomobile.com_RemoteWebDriver_18-11-01_09_21_26_851&_timestamp[0]=1541064086231',
entityType: 'remote_web_driver',
handlesAlerts: true,
serverConnector: '',
securityToken: '',
executionId: 'kulins@perfectomobile.com_RemoteWebDriver_18-11-01_09_21_26_851',
'webdriver.remote.sessionid': '89018528-a9a2-44b0-ae4a-7c854b6135fd',
locationContextEnabled: true,
scriptName: 'RemoteWebDriver',
location: 'US East',
reportKey: 'kulins@perfectomobile.com_RemoteWebDriver_18-11-01_09_21_26_851',
windTunnelReportUrl: 'https://ps.reporting.perfectomobile.com/library?externalId[0]=kulins@perfectomobile.com_RemoteWebDriver_18-11-01_09_21_26_851&_timestamp[0]=1541064086231',
user: '',
cssSelectorsEnabled: true },
class: 'org.openqa.selenium.remote.Response',
status: 0 } }

[1.wiki:Firefox] OK | 1 passed // 29s
[14:51:55] COMMAND DELETE "/nexperience/perfectomobile/wd/hub/session/89018528-a9a2-44b0-ae4a-7c854b6135fd"
[14:51:55] DATA {}
Admins-MacBook-Pro:Codeceptv1 admin$

```

> Provide test source code if related

```js
_beforeStep(step) {
console.debug('>>> Before step method called' + step.metaStep);
var stepName = step.metaStep.toString();
if ((stepName.includes("Given") || stepName.includes("When") || stepName.includes("Then") || stepName.includes("And")) && !stepName.includes(": ")) {
const client = this.perfectoClient;
let promise = new Promise(function (resolve, reject) {
client.stepStart(stepName).then(() => {
setTimeout(() => resolve(1), 1000);
});

});
return promise;
}

return this.browser;

}
```
Scenario: Go to wiki
Given I resize to a 1024x768 screen size
And I go to the wiki home page
And I search "Perfecto" in wiki
And I click the search button
Given I resize to a 200x400 screen size

And I wait for 1 seconds

### Details

* CodeceptJS version: 1.4.4
* NodeJS Version: 5.7.1
* Operating System: Mac
* Protractor || WebDriverIO || Nightmare version (if related) WebdriverIO

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.