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!