Skip to content

Update Locator.build typing to have locator parameter be optional #4542

Closed
@silvanusbuyesti

Description

@silvanusbuyesti

What are you trying to achieve?

When using AI to generate Page Objects, it generates a number of them that start with simply locate() with no parameter passed.

According to the code, this is completely valid:
Locator.build = (locator) => { if (!locator) return new Locator({ xpath: '//*' }); return new Locator(locator, 'css'); };

Typescript is upset there is nothing passed as the type is defined as:
static build(locator: CodeceptJS.LocatorOrString): Locator;

Since the actual function doesn't care about having a 'locator' actually passed, this should be set to optional.
static build(locator?: CodeceptJS.LocatorOrString): Locator;

Details

  • CodeceptJS version: 3.6.7
  • NodeJS Version:22.2.0
  • Operating System: Mac

Workaround

Add a locator parameter to the locate call.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions