Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

204
Views
Passing string arguments to TestCafe Selector in page model

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 ?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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();
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!