Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🐛 Bug]: Error allow custom commands scoped to element #8417

Closed
3 tasks done
yopasa94 opened this issue Jun 9, 2022 · 7 comments
Closed
3 tasks done

[🐛 Bug]: Error allow custom commands scoped to element #8417

yopasa94 opened this issue Jun 9, 2022 · 7 comments

Comments

@yopasa94
Copy link

yopasa94 commented Jun 9, 2022

Have you read the Contributing Guidelines on issues?

WebdriverIO Version

latest

Node.js Version

latest

Mode

Standalone Mode

Which capabilities are you using?

capabilities: [
    {
      maxInstances: 1,
      browserName: 'chrome',
      'goog:chromeOptions': {
        args: ['--start-maximized'],
      },
      acceptInsecureCerts: true,
    },
  ]

What happened?

Custom commands should use a '$' symbol at the end to be processed unfortunately it produce a new issue when we call wrapCommand from shim.js class

Related PR
#8134

image

SetValueSafe$ does not exist in the (this) (WebDriver:Element) context. Event though I can see the list of wdio default commands (i.e click, $, $$, setValue....so on)
image

What is your expected behavior?

I should be able to call custom commands from elements

How to reproduce the bug.

wdio.chain.command.type.d.ts

import 'webdriverio';
declare module 'webdriverio' {
  interface ChainablePromiseElement<T> {
    setValueSafe$: (value: string) => Promise<void>;
  }
}

wdio.command.type.d.ts

declare global {
  namespace WebdriverIO {
    interface Element {
      setValueSafe$: (value: string) => Promise<void>;
    }
  }
}

MyCustomCommand.ts

export async function setValueSafe(this: WebdriverIO.Element, value: string, expectedValue = value): Promise<void> {
  await this.waitForDisplayed();
  await this.setValue(value);
}

wdio-conf.ts

  before() {
    browser.addCommand('setValueSafe$', setValueSafe, true);
  }

Relevant log output

TypeError: Cannot read properties of undefined (reading 'apply')
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Code of Conduct

  • I agree to follow this project's Code of Conduct

Is there an existing issue for this?

  • I have searched the existing issues
@yopasa94 yopasa94 added Bug 🐛 Needs Triaging ⏳ No one has looked into the issue yet labels Jun 9, 2022
@jayrepo
Copy link
Contributor

jayrepo commented Jun 15, 2022

Does it occur if you remove trailing $ from your command?

@yopasa94
Copy link
Author

No, it does not occur but I'd need to use multiple await to call the new custom command i.e

I would like to call the new custom comman in this way ->
await mypage.nameInput.setValueSafe$('querty');

If I remove the '$, it forces me to use multiple await
await (await mypage.nameInput).setValueSafe('querty');

@jayrepo
Copy link
Contributor

jayrepo commented Jun 16, 2022

Tried with minimal code below, both commands are working fine

async function setValueSafe(value) {
  await this.waitForDisplayed();
  await this.setValue(value);
}

describe('My Login application', () => {
  beforeAll(() => {
    browser.addCommand('setValueSafe$', setValueSafe, true);
    browser.addCommand('setValueSafe', setValueSafe, true);
  });
  it('should login with valid credentials', async () => {
    await browser.url(`https://the-internet.herokuapp.com/login`);

    await $('#username').setValueSafe$('tomsmith');
    await $('#password').setValueSafe('SuperSecretPassword!');
    await $('button[type="submit"]').click();

    await expect($('#flash')).toBeExisting();
    await expect($('#flash')).toHaveTextContaining('You logged into a secure area!');
  });
});

there might be issue with mypage.nameinput, can you please provide an example?

@yopasa94
Copy link
Author

Could you share your package.json file ? I'd like to use the same version dependencies

@jayrepo
Copy link
Contributor

jayrepo commented Jun 17, 2022

{
    "devDependencies": {
        "@wdio/cli": "^7.20.2",
        "@wdio/jasmine-framework": "^7.20.0",
        "@wdio/local-runner": "^7.20.2",
        "@wdio/spec-reporter": "^7.20.0",
        "chromedriver": "^102.0.0",
        "wdio-chromedriver-service": "^7.3.2"
    }
}

@christian-bromann
Copy link
Member

@yopasa94 please provide a reproducible example to help us identify this issue for you, otherwise we can only close it.

@christian-bromann christian-bromann added Reproducible Example Missing and removed Needs Triaging ⏳ No one has looked into the issue yet labels Jun 20, 2022
@christian-bromann
Copy link
Member

Closing due to inactivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants