Skip to content

Commit 3f49241

Browse files
author
John Doherty
committed
added helpers.waitUntilAttributeEquals and fixed helpers.getAttributeValue
1 parent d84d665 commit 3f49241

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

Diff for: page-objects/mammoth-workwear.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ module.exports = {
2323
expect(pageTitle).to.contain(expectedTitle);
2424
});
2525
}
26-
};
26+
};

Diff for: runtime/helpers.js

+33-8
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = {
1010
*/
1111
loadPage: function(url, waitInSeconds) {
1212

13-
// use either passed in timeout or global 10 seconds default
13+
// use either passed in timeout or global default
1414
var timeout = (waitInSeconds) ? (waitInSeconds * 1000) : DEFAULT_TIMEOUT;
1515

1616
// load the url and wait for it to complete
@@ -23,20 +23,17 @@ module.exports = {
2323

2424
/**
2525
* returns the value of an attribute on an element
26-
* @param {string} selector - css selector used to find the element
26+
* @param {string} htmlCssSelector - HTML css selector used to find the element
2727
* @param {string} attributeName - attribute name to retrieve
2828
* @returns {string} the value of the attribute or empty string if not found
2929
* @example
3030
* helpers.getAttributeValue('body', 'class');
3131
*/
32-
getAttributeValue: function (selector, attributeName) {
32+
getAttributeValue: function (htmlCssSelector, attributeName) {
3333

3434
// get the element from the page
35-
return driver.findElement(by.css(selector)).then(function(attributeValue) {
36-
return attributeValue;
37-
})
38-
.catch(function() {
39-
return '';
35+
return driver.findElement(by.css(htmlCssSelector)).then(function(el) {
36+
return el.getAttribute(attributeName);
4037
});
4138
},
4239

@@ -127,6 +124,34 @@ module.exports = {
127124

128125
// grab matching elements
129126
return driver.findElements(by.js(clickElementInDom, cssSelector, textToMatch));
127+
},
128+
129+
/**
130+
* Waits until a HTML attribute equals a particular value
131+
* @param {string} elementSelector - HTML element CSS selector
132+
* @param {string} attributeName - name of the attribute to inspect
133+
* @param {string} attributeValue - value to wait for attribute to equal
134+
* @param {integer} waitInSeconds - number of milliseconds to wait for page to load
135+
* @returns {Promise} resolves if attribute eventually equals, otherwise rejects
136+
* @example
137+
* helpers.waitUntilAttributeEquals('html', 'data-busy', 'false', 5);
138+
*/
139+
waitUntilAttributeEquals: function(elementSelector, attributeName, attributeValue, waitInSeconds) {
140+
141+
// use either passed in timeout or global default
142+
var timeout = (waitInSeconds) ? (waitInSeconds * 1000) : DEFAULT_TIMEOUT;
143+
144+
// repeatedly execute the test until it's true or we timeout
145+
return driver.wait(function() {
146+
147+
// get the html attribute value using another helper method
148+
return helpers.getAttributeValue(elementSelector, attributeName).then(function(value) {
149+
150+
// inspect the value
151+
return value === attributeValue;
152+
});
153+
154+
}, timeout);
130155
}
131156

132157
};

0 commit comments

Comments
 (0)