Skip to content

Unify grab* methods accross helpers #2093

@DavertMik

Description

@DavertMik

Each grab* method returns either array or a string or whatever... and this is a problem. For CodeceptJS 3.0 we need to unify API so the result of those methods will be predictable.

We need to go through helpers:

  • WebDriver
  • Puppeteer
  • Appium
  • TestCafe
  • Nightmare
  • Protractor

and go through following grab* methods and implement a new method which ALWAYS returns an array:

  • grabAttributeFrom rename to grabAttributeFromAll => returns array
  • grabCssPropertyFrom rename to grabCssPropertyFromAll => returns array
  • grabHTMLFrom rename to grabHTMLFromAll => returns array
  • grabTextFrom rename to grabTextFromAll => returns array
  • grabValueFrom rename to grabValueFromAll => returns array

While all current methods should always return value for the first element:

  • grabAttributeFrom returns value of the FIRST element
  • grabCssPropertyFrom returns value of the FIRST element
  • grabHTMLFrom returns value of the FIRST element
  • grabTextFrom returns value of the FIRST element
  • grabValueFrom returns value of the FIRST element

For each of new / old methods write corresponding tests in:

  • tests/helper/webapi.js
  • tests/helper/HELPERNAME.js

Workflow

Development

  • Open a helper
  • Find a corresponding grab* method
  • Rename it to grab*All
  • Make sure it returns an array
  • Create a new method grab*
  • Call grab*All from it, and return a single value

Testing

  • find corresponding test for the method in tests/helpers/*
  • change test for grab* to match single value only
  • add a new test for grab*All

Documentation

  • update docs in docs/webapi/grab* to say "returns a single value (string)"
  • copy documentation to docs/webapi/grab*All to say "returns an array"
  • add {{> grab*All }} into grab*All method docblock

Alternative implementation

Just an idea, to save time we can just add { all: true} parameter to the list of arguments for each grab* function. So it can be:

grabTextFrom('.user'); // returns first text
grabTextFrom('.user', { all: true }); // returns array

This implementation is simpler as we will need less tests and less methods documented

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions