Skip to content

Commit 4a769f1

Browse files
Richard PetersenDavertMik
authored andcommitted
Streamlined return values from grab* (#2054)
1 parent fcb0c8b commit 4a769f1

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

lib/helper/WebDriver.js

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -912,14 +912,9 @@ class WebDriver extends Helper {
912912
async grabTextFrom(locator) {
913913
const res = await this._locate(locator, true);
914914
assertElementExists(res, locator);
915-
let val;
916-
if (res.length > 1) {
917-
val = await forEachAsync(res, async el => this.browser.getElementText(getElementId(el)));
918-
} else {
919-
val = await this.browser.getElementText(getElementId(res[0]));
920-
}
921-
this.debugSection('Grab', val);
922-
return val;
915+
const val = await forEachAsync(res, el => this.browser.getElementText(getElementId(el)));
916+
this.debugSection('Grab', String(val));
917+
return val.length > 1 ? val : val[0];
923918
}
924919

925920
/**
@@ -929,12 +924,9 @@ class WebDriver extends Helper {
929924
async grabHTMLFrom(locator) {
930925
const elems = await this._locate(locator, true);
931926
assertElementExists(elems, locator);
932-
const values = await Promise.all(elems.map(elem => elem.getHTML(false)));
933-
this.debugSection('Grab', values);
934-
if (Array.isArray(values) && values.length === 1) {
935-
return values[0];
936-
}
937-
return values;
927+
const val = await forEachAsync(elems, elem => elem.getHTML(false));
928+
this.debugSection('Grab', String(val));
929+
return val.length > 1 ? val : val[0];
938930
}
939931

940932
/**
@@ -944,8 +936,9 @@ class WebDriver extends Helper {
944936
async grabValueFrom(locator) {
945937
const res = await this._locate(locator, true);
946938
assertElementExists(res, locator);
947-
948-
return forEachAsync(res, async el => el.getValue());
939+
const val = await forEachAsync(res, el => el.getValue());
940+
this.debugSection('Grab', String(val));
941+
return val.length > 1 ? val : val[0];
949942
}
950943

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

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

970967
/**

0 commit comments

Comments
 (0)