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 badges
Add a ment  | 

3 Answers 3

Reset to default 5

You 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 asyncin 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