admin管理员组文章数量:1323370
What I'm trying to do is print/use the value of the Polyline attribute.
<Polyline points="x,y x,y x,y x,y">
I've tried to get them with these methods:
This is an util function
export const getPointAttribute = async () => {
const polyline = s.polyline;
const polylineData = ClientFunction(() => polyline().attributes, {
dependencies: { polyline }
});
return polylineData
}
This is inside the test script
test('', async (t) => {
console.log(u.getPointAttribute())
}
or
test('', async (t) => {
console.log(s.polyline.getAttribute('points'));
}
And I include my selectors external
import * as s from '../utilities/selectors';
But all I get is a promise as output in the console log
Promise { }
or
ReExecutablePromise { _then: [], _fn: [Function], _taskPromise: null }
Any help is appreciated!
What I'm trying to do is print/use the value of the Polyline attribute.
<Polyline points="x,y x,y x,y x,y">
I've tried to get them with these methods:
This is an util function
export const getPointAttribute = async () => {
const polyline = s.polyline;
const polylineData = ClientFunction(() => polyline().attributes, {
dependencies: { polyline }
});
return polylineData
}
This is inside the test script
test('', async (t) => {
console.log(u.getPointAttribute())
}
or
test('', async (t) => {
console.log(s.polyline.getAttribute('points'));
}
And I include my selectors external
import * as s from '../utilities/selectors';
But all I get is a promise as output in the console log
Promise { }
or
ReExecutablePromise { _then: [], _fn: [Function], _taskPromise: null }
Any help is appreciated!
Share Improve this question edited Jan 24, 2019 at 15:13 Alex Skorkin 4,2743 gold badges26 silver badges48 bronze badges asked Jan 24, 2019 at 12:52 D.RooijD.Rooij 2532 silver badges13 bronze badges3 Answers
Reset to default 5You should await the call inside the console.log:
test('', async (t) => {
console.log(await s.polyline.getAttribute('points'));
}
or
test('', async (t) => {
console.log(await s.polyline.getAttribute('points'));
}
Your getPointAttribute
function returns the polylineData
object that is an instance if the ClientFunction type (which is, in turn, based on Promises). That's why when you log u.getPointAttribute()
, you get these messages. All you need to do is to use the await
keyword before calling the ClientFunction. Please see the following code:
const polylineData = ClientFunction(() => polyline().attributes, {
dependencies: { polyline }
});
await polylineData();
Refer to the following article to get more information https://devexpress.github.io/testcafe/documentation/test-api/obtaining-data-from-the-client/
I would also like to mention that you do not need to use async
in your getPointAttribute
function.
I've managed to get it working with a utility function for the ones who are interested.
export function getPoints(object: Selector) : Promise<string> {
return object.getAttribute('points');
}
This makes it easier and cleaner to work with the data.
import * as u from '../utilities/functions';
import * as s from '../utilities/selectors';
console.log(await u.getPoints( s.polyline ));
Thanks for the help guys!
本文标签: javascriptHow do i useprint the value inside a generic attribute in TestCafeStack Overflow
版权声明:本文标题:javascript - How do i useprint the value inside a generic attribute in TestCafe - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742125409a2421916.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论