Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 15 additions & 18 deletions lib/helper/WebDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -912,14 +912,9 @@ class WebDriver extends Helper {
async grabTextFrom(locator) {
const res = await this._locate(locator, true);
assertElementExists(res, locator);
let val;
if (res.length > 1) {
val = await forEachAsync(res, async el => this.browser.getElementText(getElementId(el)));
} else {
val = await this.browser.getElementText(getElementId(res[0]));
}
this.debugSection('Grab', val);
return val;
const val = await forEachAsync(res, el => this.browser.getElementText(getElementId(el)));
this.debugSection('Grab', String(val));
return val.length > 1 ? val : val[0];
}

/**
Expand All @@ -929,12 +924,9 @@ class WebDriver extends Helper {
async grabHTMLFrom(locator) {
const elems = await this._locate(locator, true);
assertElementExists(elems, locator);
const values = await Promise.all(elems.map(elem => elem.getHTML(false)));
this.debugSection('Grab', values);
if (Array.isArray(values) && values.length === 1) {
return values[0];
}
return values;
const val = await forEachAsync(elems, elem => elem.getHTML(false));
this.debugSection('Grab', String(val));
return val.length > 1 ? val : val[0];
}

/**
Expand All @@ -944,8 +936,9 @@ class WebDriver extends Helper {
async grabValueFrom(locator) {
const res = await this._locate(locator, true);
assertElementExists(res, locator);

return forEachAsync(res, async el => el.getValue());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

method returned array, now it returns array or string.

Others helpers have both variants.
@DavertMik , We should review helpers signature

Copy link
Contributor

@DavertMik DavertMik Dec 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think we need to do that for 3.0 release.
Maybe a better way would be to revert merged pull request and introduce a new policy for 3.0

const val = await forEachAsync(res, el => el.getValue());
this.debugSection('Grab', String(val));
return val.length > 1 ? val : val[0];
}

/**
Expand All @@ -954,7 +947,9 @@ class WebDriver extends Helper {
async grabCssPropertyFrom(locator, cssProperty) {
const res = await this._locate(locator, true);
assertElementExists(res, locator);
return forEachAsync(res, async el => this.browser.getElementCSSValue(getElementId(el), cssProperty));
const val = await forEachAsync(res, async el => this.browser.getElementCSSValue(getElementId(el), cssProperty));
this.debugSection('Grab', String(val));
return val.length > 1 ? val : val[0];
}

/**
Expand All @@ -964,7 +959,9 @@ class WebDriver extends Helper {
async grabAttributeFrom(locator, attr) {
const res = await this._locate(locator, true);
assertElementExists(res, locator);
return forEachAsync(res, async el => el.getAttribute(attr));
const val = await forEachAsync(res, async el => el.getAttribute(attr));
this.debugSection('Grab', String(val));
return val.length > 1 ? val : val[0];
}

/**
Expand Down