Skip to content

Commit

Permalink
feat: return all meta on getMeta call without arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
j0tunn committed Apr 10, 2018
1 parent 3026165 commit 79264e2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ The test will be processed in all browsers and **silently** skipped in `ie9`.
### Sharable meta info
Implemented via two commands:
* setMeta(key, value)
* getMeta(key)
* getMeta([key])

These methods allow you to store some information between webdriver calls and it can then be used in custom commands, for instance. This meta information will be shown in the [allure report](https://github.com/gemini-testing/hermione-allure-reporter).

Expand All @@ -301,7 +301,9 @@ it('test1', function() {
.getMeta('foo')
.then((val) => console.log(val)) // prints 'bar'
.getMeta('url')
.then((url) => console.log(url)); // prints '/foo/bar?baz=qux'
.then((url) => console.log(url)) // prints '/foo/bar?baz=qux'
.getMeta()
.then((meta) => console.log(meta)) // prints `{foo: 'bar', url: '/foo/bar?baz=qux'}`
});
```

Expand Down Expand Up @@ -466,7 +468,7 @@ Option name | Description
`screenshotOnRejectTimeout`| Timeout for taking screenshot on test fail. Default value is `httpTimeout`.
`testsPerSession` | Maximum amount of tests (`it`s) to run in each web driver session.
`retry` | How many times a test should be rerun. Default value is `0`.
`shouldRetry` | Function that determines whether to make a retry. By default returns `true `if retry attempts are available otherwise returns `false`.
`shouldRetry` | Function that determines whether to make a retry. By default returns `true `if retry attempts are available otherwise returns `false`.
`calibrate` | Allows to correctly capture the image. Default value is `false`.
`screenshotPath` | Directory to save screenshots by Webdriverio. Default value is `null`.
`meta` | Additional data that can be obtained via .getMeta() method
Expand Down Expand Up @@ -512,7 +514,7 @@ Argument of this function is object with fields:
* `retriesLeft {Number}` — number of available retries
* `ctx` — in case of test `TEST_FAIL` it would be bound data, in case of `ERROR` it would be link to `Runnable`
* `[error]` — error type (available only in case of ERROR)


### calibrate
Does this browser need to perform the calibration procedure. This procedure allows to correctly capture the image in case the particular WebDriver implementation captures browser UI along with web page. Default value is `false`.
Expand Down
2 changes: 1 addition & 1 deletion lib/browser/existing-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = class ExistingBrowser extends Browser {

_addMetaAccessCommands(session) {
session.addCommand('setMeta', (key, value) => this._meta[key] = value);
session.addCommand('getMeta', (key) => this._meta[key]);
session.addCommand('getMeta', (key) => key ? this._meta[key] : this._meta);
}

_decorateUrlMethod(session) {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions test/lib/browser/existing-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ describe('NewBrowser', () => {

assert.deepEqual(browser.meta, {k1: 'v1'});
});

describe('getMeta', () => {
it('should get all meta if no key provided', async () => {
mkBrowser_();

await session.setMeta('foo', 'bar');
await session.setMeta('baz', 'qux');

const meta = await session.getMeta();

assert.deepEqual(meta, {foo: 'bar', baz: 'qux'});
});
});
});

describe('url decorator', () => {
Expand Down

0 comments on commit 79264e2

Please sign in to comment.