Skip to content

The same "I" instance being used in step runtime context cant be injected in custom helper #4520

Description

@attilagyoriid

What are you trying to achieve?

to inject the same "I" instance as being used in step runtime context in custom helper

What do you get instead?

undefined or different "I" instance

Provide test source code if related
I tried it to achieve the I injection in many ways

1.
class MyHelper extends Helper {

constructor(prop) {
    super();

    const {I} = inject(); → "I" is undefined

}
....
2.
class MyHelper  extends Helper { 

myMethod = message => {
    const {I} = inject(); → "I" it is not the same instance being used in the context of step execution
};
.....
3.
class MyHelper  extends Helper

{

async _before() {

    const {I} = inject(); → "I" it is not the same instance being used in the context of step execution
};

Details

  • CodeceptJS version: 3.6.7
  • NodeJS Version: v20.11.0
  • Operating System: macOS 15.0.01
  • puppeteer || webdriverio || testcafe version (if related)
  • Configuration file:
codecept.conf.js:
...
module.exports = {
  name: 'project',
  tests: '../src/tests/**/*_test.js',
  output: '../output',
  bootstrap: null,
  helpers: {  
    MyHelper: {
      require: '../src/lib/helpers/MyHelper.js',
    }
  },
......

The question:
Is there a way to get a hold of the same "I" instance being used during step exec and inject it into custom helper classes?

Thanks for your help and answer

Best Regards

Attila

Activity

  1. kobenguyent commented on Oct 21, 2024

    @kobenguyent
    Collaborator

    hey @attilagyoriid per my best knowledge, the I actor is not designed to be injected in custom helper.
    https://codecept.io/helpers/#extending-codeceptjs-with-custom-helpers

    perhaps @DavertMik could explain it better than myself.

  2. attilagyoriid commented on Oct 22, 2024

    @attilagyoriid
    Author

    Dear @kobenguyent thanks for the pretty fast reply

    So If I understand correctly, custom helper classes are designed to implement those activities can not be achieved using I actor?

    Other question being important:
    In case of Page Object Model, can it be achieved to inject the same actor I instance being used during step context?

    Thanks for your answer

    Best Regards

    Attila

  3. kobenguyent commented on Oct 22, 2024

    @kobenguyent
    Collaborator

    As far as my experience, with PO, the I object is possible, please check a sample report here https://github.com/kobenguyent/amazon-ui-tests/blob/master/pages/ResultPage.js

    Or official guidelines https://codecept.io/pageobjects/#stepobjects

    Hope that helps

  4. locked and limited conversation to collaborators on Nov 11, 2024
  5. converted this issue into a discussion #4559 on Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions