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.