I'm using codeceptjs with puppeteer.
Now the problem I'm having I'm either not aware it can be done within puppeteer, or I'm not sure how to do this with the native puppeteer.
I'm wanting to target an element and get all the information for that element then match on a string and the pop out some certain data. I have some code that works in native standalone puppeteer however I'm not sure how to use this within Codeceptjs.
Because Puppeteer has a helper file within codecptjs I don't just want to const require puppeteer again I'd rather just direct the query at the helper.
let match ='';
const targetEls = await page.$$('#element');
for(let target of targetEls)
{
const cell_content = await page.evaluate(el => el.innerHTML, target);
let county = (cell_content.match(/string_to_match/g) || []).length;
if(county === 2)
{
match = cell_content.match(/http:\/\/(\w*)\.(\w*)\/(\w*)\/(\d*)/gi).pop(); // searches for url within element info and pop it out.
break;
}
}
The issue I'm having is that the await page.evaluate(el.innerHTML, target)
doesn't work with codeceptjs as I haven't instantiated puppeteer within my steps code. However, it is within the puppeteer helper.js
Not sure, what do you want. Describe, please, where does code from question is placed.
page
is not described globally, you can access to it by using Puppeteer helper's page
object.
Looks like you want to make method in your custom helper, where access to puppeteer helper is used to get its browser
value, like described on Puppeteer helpers doc:
const currentPage = this.helpers['Puppeteer'].page;
await currentPage.$$('#element'); // Get the url of the current page
So your helper will include method, you described in question and you can call it from test.