1

I try to write an own Selector that will read an XML and get an XPath from it. But my idea does not work any suggestion?

I use

//xpath.js
import { Selector } from 'testcafe';
import fs from "fs";
import downloadsFolder from "downloads-folder";
import {DOMParser} from 'xmldom'

const elementByXPath = Selector(xpath => {

    const items = [];
    var xml = fs.readFileSync(downloadsFolder()+'export.xml', 'utf8').toString();
    var doc = new DOMParser().parseFromString(xml);

    //for debug reson
    console.log(xml);

    /*
    Logik for XPath here
     */
    items.push('0');

    return items;
});

export default function (xpath) {
    return Selector(elementByXPath(xpath));
}

and the fixture is

//testfixture.js
import { Selector } from 'testcafe';
import XPathSelector from './xpath';

fixture `SM Run 1`

test('Per Anhalter durch die Galaxies', async t => {

        await t
            .navigateTo("http://www.ifoerster.com")

        await t
            .expect(elementByXPath('test')).eql(1)


        console.log("Fertig")

    });

In my understanding, this has to work.

Alex Skorkin
  • 4,264
  • 3
  • 25
  • 47
ingo
  • 776
  • 1
  • 10
  • 25
  • 1
    Could you please clarify what error message you got? Note that the function argument of the Selector must return a DOM node, an array of DOM nodes, NodeList, HTMLCollection, etc. as it is described in the [Initialize Selectors](https://devexpress.github.io/testcafe/documentation/test-api/selecting-page-elements/selectors/creating-selectors.html#initialize-selectors) article. – Dmitry Ostashev Oct 18 '19 at 13:19

0 Answers0