1

Hi CodeceptJS Community,

  • Is there a way to use custom defined functions (under steps_file.js) as I. customFunction() in page object files.

  • Is there a way to use native codeceptjs functions (like I.click()) in my custom helper files

I couldn't find any help in the documentation and in other sources. Is there any way to achieve this?

  • And is there any way to use xpath locators in puppeteer helper?

    this.helpers['Puppeteer'].page.click(xpath);

tewoos
  • 45
  • 2
  • 10

3 Answers3

0

I had the same problem to use custom steps in pageObjects. To avoid it, i passed the actor (I) as parameter to my pageObject function.

page object:

const I = actor();

       module.exports = {

           doSomething(I){
                 I.login();
           }
};

Test scenario:

Scenario('Test something' (I,pageObject)=>{
     pageObject.doSomething(I)
})

In this case, pageObjects will has access to all custom steps from I :)

Matheus Souza
  • 55
  • 1
  • 6
0

Thank you for your sharing Matheus. I have used a different solution. Instead of writing "I" object in every page object method (which was also one option for me), I have created a custom helper file and written all methods using puppeteer helper like below;

async method() {
    await this.helpers['Puppeteer'].click(xpath);
}

I can call this method both in tests and page objects

I.method();
tewoos
  • 45
  • 2
  • 10
0

I was facing the same issue and when I looked into the typescripts definitions I noticed that actor() which is required in every page object etc. has custom steps arguments.

So this worked for me to extend the const I = actor(); witht the custom steps form steps_file.js;

const customSteps = require('./steps_file');
const I = actor(customSteps());

After that, I can use all methods in page objects like in tests scenarios which are accessing the methods from steps_file.js

Mugetsu
  • 1,739
  • 2
  • 20
  • 41