I have a problem similar to link, I think in that link guys are using typescript files. I have defined selectors in the js files, I tried to do it this way:
class Page {
constructor(sampleText){
this.optionsButton = Selector('#options').withText(sampleText);
}
}
export default new Page();
but when I try to call selector from test file
test('sampleTest', async t=> {
await t.click(Page.optionsButton('sometext');
)}
I got an error:
ERROR Cannot prepare tests due to the following error: The "text" argument (undefined) is not of expected type (string or a regular expression).
How to solve this issue ?
optionsButton is a property and its value is defined using the constructor so the parameter can only be passed at the moment you create the object like this:
new Page('sometext');
It would be better if you write a method in the Page class that returns the selector based on a parameter:
class Page {
optionsButton(opt) {
return Selector('#options').withText(opt);
}
}
export default new Page();